agent.run() to process messages and get responses. Supports streaming, structured outputs, and runtime knowledge base integration.
Quick Start
Function Signature
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
message | str | Yes | - | User message to process |
session_id | str | No | Auto-generated | Session ID for conversation continuity |
stream | bool | No | False | Enable streaming responses |
user_id | str | No | Auto-generated | User identifier |
knowledge_bases | List | No | None | Knowledge bases for RAG at runtime |
Return Value
The return type depends on configuration:| Configuration | Return Type |
|---|---|
| Default | AgentResponse |
response_model set | Pydantic model instance |
stream=True | Iterator[AgentStream] |
Basic Usage
Simple Run
With Session ID
Maintain conversation context across multiple runs:With User ID
Streaming Responses
Get real-time responses as they’re generated:AgentStream Properties
| Property | Type | Description |
|---|---|---|
content | str | Accumulated content so far |
delta | str | New content in this chunk |
done | bool | True if this is the final chunk |
session_id | str | Session identifier |
chunk_index | int | Index of this chunk |
metadata | dict | Additional metadata |
structured_data | BaseModel | Parsed structured data (final chunk only) |
artifact_files | List[Artifact] | Generated files (final chunk only) |
Streaming with Progress
Structured Outputs
Get type-safe responses using Pydantic models:Nested Models
Streaming with Structured Output
Runtime Knowledge Bases
Pass knowledge bases at runtime for RAG:Multiple Knowledge Bases
Custom KB Configuration
Usewith_config() to customize retrieval settings:
AgentResponse Object
The response object contains:| Property | Type | Description |
|---|---|---|
response | str | The agent’s text response |
session_id | str | Session identifier |
message_id | str | Unique message ID |
metadata | dict | Additional metadata |
tool_calls | List[dict] | Tools called during execution |
raw_response | dict | Raw API response |
artifact_files | List[Artifact] | Generated files |