Skip to main content

Overview

The chat() method sends a message and returns the final text response. It’s a convenience wrapper around stream() that returns only the last AI text from messages-tuple events.

Method Signature

Parameters

str
required
User message text to send to the agent.
str | None
default:"None"
Thread ID for conversation context. Auto-generated if None.
Without a checkpointer at initialization, thread_id is only used for file isolation (uploads/artifacts), not conversation history.
str
default:"client default"
Override the model for this specific call.
bool
default:"client default"
Override thinking mode for this call.
bool
default:"client default"
Override plan mode for this call.
bool
default:"client default"
Override subagent delegation for this call.
int
default:"100"
Maximum number of agent steps per turn.

Return Value

str
The last AI message text, or empty string if no response was generated.

Examples

Basic Usage

With Thread ID

Override Model

Multi-Turn Conversation

Behavior Notes

If the agent emits multiple text segments in one turn, intermediate segments are discarded. Use stream() directly to capture all events.

Example: Multiple AI Messages

If the agent produces:
  1. “Let me think about this…”
  2. “I’ll use a tool to help.”
  3. “The final answer is 42.”
The chat() method will return only: “The final answer is 42.” To see all intermediate messages, use stream() instead:

Error Handling

Common errors:
  • Configuration errors (missing API keys, invalid model names)
  • Network errors (when using cloud models)
  • Tool execution errors (file not found, permission denied)

Testing

From the test suite:

See Also