chatWithProgress

Returns the model's next message for request, like ChatModel.chat, and lets a streamed run watch the model write it. Use it in a node in place of ChatModel.chat:

val answer = node("answer", work = { email -> model.chatWithProgress(ChatRequest(email.messages)).message }) { email, reply ->
email.copy(messages = email.messages + reply)
}

graph.stream(email).collect { event -> event.textDelta?.let(::print) }

In a node of a run that is collected with stream or streamResume, the model is asked with ChatModel.stream and each ChatEvent.TextDelta is passed to reportProgress, so it arrives in the run's flow as a GraphEvent.NodeProgress; textDelta reads it there. Anywhere else nobody would see the pieces, and the model is asked with ChatModel.chat.

Throws

when the call fails or the model declines to answer.


suspend fun ChatModel.chatWithProgress(prompt: String, system: String? = null): String

Sends prompt as a single user message and returns the text of the answer, like chat with a prompt, and lets a streamed run watch the model write it. See the overload with a ChatRequest.

node("summarize", work = { model.chatWithProgress("Summarize: ${it.notes}") }) { state, summary ->
state.copy(summary = summary)
}