Agent.run() or Agent.arun(). Here’s how they work:
- The agent builds the context to send to the model (system message, user message, chat history, user memories, session state and other relevant inputs).
- The agent sends this context to the model.
- The model processes the input and responds with either a message or a tool call.
- If the model makes a tool call, the agent executes it and returns the results to the model.
- The model processes the updated context, repeating this loop until it produces a final message without any tool calls.
- The agent returns this final response to the caller.
Basic Execution
TheAgent.run() function runs the agent and returns the output — either as a RunOutput object or as a stream of RunOutputEvent objects (when stream=True). For 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:
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
To enable streaming, setstream=True when calling run(). This will return an iterator of RunOutputEvent objects instead of a single response.
Streaming all events
By default, when you stream a response, only theRunContent events will be streamed.
You can also stream all run events by setting stream_events=True.
This will provide real-time updates about the agent’s internal processes, like tool calling or reasoning:
. For example:
Handling Events
You can process events as they arrive by iterating over the response stream:RunEvents make it possible to build exceptional agent experiences.
Event Types
The following events are yielded by theAgent.run() and Agent.arun() functions depending on the agent’s configuration:
Core Events
Control Flow Events
Tool Events
Reasoning Events
Memory Events
Session Summary Events
Pre-Hook Events
Post-Hook Events
Parser Model events
Output Model events
Custom Events
If you are using your own custom tools, you can yield custom events along with the rest of the Agno events. Create a custom event class by extending theCustomEvent class. For example:
Specify Run 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