Overview
Thechat() 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.
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:- “Let me think about this…”
- “I’ll use a tool to help.”
- “The final answer is 42.”
chat() method will return only: “The final answer is 42.”
To see all intermediate messages, use stream() instead:
Error Handling
- 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
- Streaming - For real-time event streaming
- Configuration - For file uploads and model selection
- Overview - For initialization options