Learn how to run an agent and get the response.
Agent.run()
function runs the agent and generates a response, either as a RunOutput
object or a stream of RunOutputEvent
objects.
agent.print_response()
which is a helper utility to
print the response in the terminal. It uses agent.run()
under the hood.response
.
Agent.arun()
method.
See the Async Agent example.Agent.print_response()
method.
Agent.print_response()
method is a helper method that uses the Agent.run()
method under the hood.
This is only for convenience during development and not recommended for production use.See the Agent class reference for more details.Agent.run()
or Agent.print_response()
as the input
parameter.
input_schema
on the agent to validate the input. See more details in the Input and Output documentation.output_schema
on the agent to specify typed output.
Agent.run()
function returns a RunOutput
object when not streaming. Here are some of the core attributes:
run_id
: The id of the run.agent_id
: The id of the agent.agent_name
: The name of the agent.session_id
: The id of the session.user_id
: The id of the user.content
: The response content.content_type
: The type of content. In the case of structured output, this will be the class name of the pydantic model.reasoning_content
: The reasoning content.messages
: The list of messages sent to the model.metrics
: The metrics of the run. For more details see Metrics.model
: The model used for the run.stream=True
when calling run()
. This will return an iterator of RunOutputEvent
objects instead of a single response.
Agent.arun()
method.
See the Async Agent Streaming example.stream_intermediate_steps=True
. This will provide real-time updates about the agent’s internal processes.
RunOutput
object.
RunContentEvent
event is not stored (because it would be very verbose). You can modify which events are skipped by setting the events_to_skip
parameter.
For example:
Agent.run()
and Agent.arun()
functions depending on the agent’s configuration:
Event Type | Description |
---|---|
RunStarted | Indicates the start of a run |
RunContent | Contains the model’s response text as individual chunks |
RunIntermediateContent | Contains the model’s intermediate response text as individual chunks. This is used when output_model is set. |
RunCompleted | Signals successful completion of the run |
RunError | Indicates an error occurred during the run |
RunCancelled | Signals that the run was cancelled |
Event Type | Description |
---|---|
RunPaused | Indicates the run has been paused |
RunContinued | Signals that a paused run has been continued |
Event Type | Description |
---|---|
ToolCallStarted | Indicates the start of a tool call |
ToolCallCompleted | Signals completion of a tool call, including tool call results |
Event Type | Description |
---|---|
ReasoningStarted | Indicates the start of the agent’s reasoning process |
ReasoningStep | Contains a single step in the reasoning process |
ReasoningCompleted | Signals completion of the reasoning process |
Event Type | Description |
---|---|
MemoryUpdateStarted | Indicates that the agent is updating its memory |
MemoryUpdateCompleted | Signals completion of a memory update |
Event Type | Description |
---|---|
ParserModelResponseStarted | Indicates the start of the parser model response |
ParserModelResponseCompleted | Signals completion of the parser model response |
Event Type | Description |
---|---|
OutputModelResponseStarted | Indicates the start of the output model response |
OutputModelResponseCompleted | Signals completion of the output model response |
CustomEvent
class: