Android SDK
Conversations & History
Start, continue, list and page through conversations with the QwryAI Android SDK
Starting and continuing conversations
- Send a message
The first message starts a new conversation when you don't pass a
conversationId.val response = client.send("Hello!") - Keep the conversation ID
The response carries the conversation's ID:
val conversationId = response.conversationId - Continue the conversation
Pass the ID to later calls:
val followUp = client.send( text = "Tell me more", conversationId = conversationId )
newConversation
class QwryClient, Package: com.qwryai.sdk
fun newConversation()Forgets the current conversation, so the next send starts a new one.
client.newConversation()
client.send("Brand new conversation!")listConversations
suspend fun listConversations(
cursor: String? = null,
limit: Int = 20
): Page<Conversation>Lists the user's conversations (this install's while anonymous), most recently active first.
cursor String?
The cursor from the previous page. Leave it out for the first page.
limit Int
Conversations per page, from 1 to 100. Defaults to 20.
val page = client.listConversations(limit = 20)
page.items.forEach { conversation ->
println("${conversation.title ?: "New conversation"}: ${conversation.status}")
}
println("Total: ${page.total}")
println("Has more: ${page.hasMore}")Conversation
data class Conversation, Package: com.qwryai.sdk
data class Conversation(
val id: String,
val title: String?,
val createdAt: Long,
val updatedAt: Long,
val userId: String?,
val status: Status
)id String required
The conversation's ID.
title String?
A short summary QwryAI writes for the conversation, or null until there is one.
createdAt Long required
When the conversation started, in seconds since 1970.
updatedAt Long required
When it was last active, in seconds since 1970.
userId String?
The identified user it belongs to, or null for an anonymous (device) conversation.
status Conversation.Status required
ONGOING, ENDED or TAKEN_OVER.
listMessages
suspend fun listMessages(
conversationId: String,
cursor: String? = null,
limit: Int = 20
): Page<Message>Loads a page of a conversation's messages.
conversationId String required
The conversation to read.
cursor String?
The cursor from the previous page, to reach further back. Leave it out for the newest messages.
limit Int
Messages per page, from 1 to 100. Defaults to 20.
val page = client.listMessages(conversationId, limit = 50)
page.items.forEach { message ->
val who = if (message.role == Message.Role.USER) "You" else "Agent"
println("$who: ${message.text}")
}Message
data class Message, Package: com.qwryai.sdk
data class Message(
val id: String,
val role: Role,
val parts: List<MessagePart>,
val createdAt: Long? = null,
val feedback: Feedback? = null,
val score: Double? = null
)id String required
The message's ID.
role Message.Role required
USER or ASSISTANT. Replies from a person on your team also come back as ASSISTANT.
parts List<MessagePart> required
The message's content: text, tool calls and tool results.
createdAt Long?
When it was sent, in seconds since 1970.
feedback Message.Feedback?
POSITIVE, NEGATIVE or null.
score Double?
The agent's confidence in this answer, when it reported one.
text String
All of the message's text parts joined together.
Pagination
data class Page<T>, Package: com.qwryai.sdk
Both list calls return a Page<T>.
data class Page<T>(
val items: List<T>,
val cursor: String?,
val hasMore: Boolean,
val total: Int
)items List<T> required
The items on this page.
cursor String?
Pass it back to get the next page. null when there are no more.
hasMore Boolean required
Whether another page exists.
total Int required
How many items there are across all pages.
Paging through all results
var page = client.listConversations(limit = 20)
while (true) {
page.items.forEach { conversation ->
println(conversation.title)
}
val next = page.cursor
if (!page.hasMore || next == null) break
page = client.listConversations(cursor = next, limit = 20)
}Ready-made state holders
For screens, ConversationListState and ConversationState keep the pages for you as StateFlows:
val list = ConversationListState(client)
list.load() // the most recently active conversations
list.loadMore() // the next page, added to the end of list.conversations
val chat = ConversationState(client, conversationId)
chat.load() // the latest page of messages
chat.loadEarlier() // the page before the oldest message shown, added to the top of chat.messagesConversationListState exposes conversations, hasMore and error. ConversationState exposes messages, isSending, hasEarlier and error, and its send and retry stream the answer into messages.