AgentState

@Serializable
data class AgentState(val messages: List<ChatMessage> = emptyList(), val tokens: TokenUsage = TokenUsage())

The state of a toolAgent: the conversation so far, oldest message first, and what it cost.

It is @Serializable, so a checkpointer that uses kotlinx.serialization can save it.

Constructors

Link copied to clipboard
constructor(messages: List<ChatMessage> = emptyList(), tokens: TokenUsage = TokenUsage())
constructor(question: String)

Starts a conversation with question as the user's first message.

Properties

Link copied to clipboard

The text of the model's final answer, or null while the conversation does not end with one: before the first run, when the run paused with tool calls waiting, or when the agent used its token budget before it had an answer.

Link copied to clipboard

true when the model reached its output limit before it finished its last message, so answer is cut off.

Link copied to clipboard
Link copied to clipboard

the tokens of every answer of the model in this conversation, as far as the provider reported them. A conversation that continues with withUserMessage keeps counting. Use copy(tokens = TokenUsage()) to start the count again, for example for a budget per question.

Functions

Link copied to clipboard

Returns this state with text added as the user's next message, to continue the conversation.