ConversationObserver
An AgentObserver that is also told what the calls send and get back: the request a model is sent, its answer, the input of a tool and its result. Use it to record the conversation in a trace, as OtlpObserver and OpenTelemetryObserver of telar-otel do with recordContent = true:
val log = object : ConversationObserver {
override fun onModelCallResponse(call: ObservedModelCall, response: ChatResponse) {
println("${call.caller}: ${response.message.text}")
}
}The conversation can hold personal data, such as what the users of an app wrote, so only an observer that implements this interface gets it. The rules of AgentObserver hold, and:
The request is the one the model is sent: the part of the conversation that
shortenkeeps, the prompt that ask adds to ask again, and the prompt that a ChatDecisionModel builds.In the order of the call: onModelCallRequest right after onModelCallStarted, and onModelCallResponse right before onModelCallCompleted. A call that fails has its request but no response. A tool call is the same with onToolCallInput and onToolCallResult.
A streamed answer arrives whole in onModelCallResponse, when the stream has ended.
Functions
The model of call answered, with the tokens its provider reported, or null when it reported none.
The model of call is sent request. Called right after onModelCallStarted.
The model of call answered with response. Called right before onModelCallCompleted.
call asks its model. A try of a node with a retry asks again, as a new call.
call ended without a result: it was cancelled, the tool paused the run with interrupt, or it threw an error that ends the run, such as an OutOfMemoryError.
The model's toolCall is what the tool of call runs on. An input that is not JSON is in ToolCall.invalidInput. Called right after onToolCallStarted.
The tool of call returned result for the model. Called right before onToolCallCompleted.
call runs its tool.