Chat response in the Android SDK

Read the ChatResponse returned by the Android OctoClient: the answer text in Kotlin, the sources the agent used, the conversation id and credit usage.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

Every call to chat returns a ChatResponse. It carries the agent's answer, the sources behind it and the id you need to continue the conversation. Use this page when you render an answer in your own UI.

Send a message

val response: ChatResponse = octo.chat(
    text = "Where is my order?",
    conversationId = null,
)

Leave conversationId as null to start a new conversation. Pass the id from an earlier response to add to an existing one.

The ChatResponse type

data class ChatResponse(
    val conversationId: String,
    val message: Message,
    val usage: Usage,
)
Field Type Description
conversationId String The conversation the answer belongs to, for example conv_8f2a. Store it to continue the thread.
message Message The assistant message: id, role, content and sources.
usage Usage Resource use of this request. usage.credits is the number of credits it consumed.

The same fields appear in the JSON of the chat endpoint, so you can compare SDK output with raw API output while debugging.

Show the answer and its sources

val answer = response.message.content
val titles = response.message.sources.map { it.title }

textView.text = answer
sourcesView.text = titles.joinToString(separator = "\n")

Each Source has an id such as src_42 and a title. The list is empty when the agent answered from a procedure or from the conversation itself and did not need a source. Show sources as small labels under the answer so customers can see where it came from.

Continue the conversation

val first = octo.chat(text = "I want to return a jacket")
val second = octo.chat(
    text = "It arrived last week",
    conversationId = first.conversationId,
)

Both calls land in one conversation, so the agent keeps the context of the first message.

Note: A response can arrive while the conversation is already handed off to your team. Check the conversation status with Conversations if your UI should tell the customer that a person will reply.

Something unclear or missing? Tell us and we will fix the page.