Agent.run()
function runs the agent and generates a response, either as a RunOutput
object or a stream of RunOutputEvent
objects.
Running Agents
Basic Execution
Here’s how to run your agent. The response is captured in theresponse
.
You can also run the agent asynchronously using the
Agent.arun()
method.
See the Async Agent example.Run Input
Theinput
parameter is the input to send to the agent. It can be a string, a list, a dictionary, a message, a pydantic model or a list of messages.
For example:
The
pprint_run_response
utility is a helper function that prints the response on your terminal.Run Output
TheAgent.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.
Streaming Responses
To enable streaming, setstream=True
when calling run()
. This will return an iterator of RunOutputEvent
objects instead of a single response.
You can also run the agent asynchronously using the
Agent.arun()
method.
See the Async Agent Streaming example.Streaming Intermediate Steps
For even more detailed streaming, you can enable intermediate steps by settingstream_intermediate_steps=True
. This will provide real-time updates about the agent’s internal processes.
Handling Events
You can process events as they arrive by iterating over the response stream:Storing Events
You can store all the events that happened during a run on theRunOutput
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:
Event Types
The following events are yielded by theAgent.run()
and Agent.arun()
functions depending on the agent’s configuration:
Core Events
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 |
Control Flow Events
Event Type | Description |
---|---|
RunPaused | Indicates the run has been paused |
RunContinued | Signals that a paused run has been continued |
Tool Events
Event Type | Description |
---|---|
ToolCallStarted | Indicates the start of a tool call |
ToolCallCompleted | Signals completion of a tool call, including tool call results |
Reasoning Events
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 |
Memory Events
Event Type | Description |
---|---|
MemoryUpdateStarted | Indicates that the agent is updating its memory |
MemoryUpdateCompleted | Signals completion of a memory update |
Parser Model events
Event Type | Description |
---|---|
ParserModelResponseStarted | Indicates the start of the parser model response |
ParserModelResponseCompleted | Signals completion of the parser model response |
Output Model events
Event Type | Description |
---|---|
OutputModelResponseStarted | Indicates the start of the output model response |
OutputModelResponseCompleted | Signals completion of the output model response |
Custom Events
If you are using your own custom tools, it will often be useful to be able to yield custom events. Your custom events will be yielded together with the rest of the expected Agno events. We recommend creating your custom event class extending the built-inCustomEvent
class:
Options When Running an Agent
Specify the User and Session
You can specify which user and session to use when running the agent by passing theuser_id
and session_id
parameters. This ensures the current run is associated with the correct user and session.
For example:
Passing Images / Audio / Video / Files
You can pass images, audio, video, or files to the agent by passing theimages
, audio
, video
, or files
parameters.
For example:
Pausing and Continuing a Run
An agent run can be paused when a human-in-the-loop flow is initiated. You can then continue the execution of the agent by calling theAgent.continue_run()
method.
See more details in the Human-in-the-Loop documentation.
Cancelling a Run
A run can be cancelled by calling theAgent.cancel_run()
method.
See more details in the Cancelling a Run documentation.
Developer Resources
- View the Agent reference
- View the RunOutput schema
- View Agent Cookbook