Use the Agent.run() function to run the agent and return the response as a RunResponse object or a stream of RunResponse objects.

from typing import Iterator
from agno.agent import Agent, RunResponse
from agno.models.openai import OpenAIChat
from agno.utils.pprint import pprint_run_response

agent = Agent(model=OpenAIChat(id="gpt-4o-mini"))

# Run agent and return the response as a variable
response: RunResponse = agent.run("Tell me a 5 second short story about a robot")
# Run agent and return the response as a stream
response_stream: Iterator[RunResponse] = agent.run("Tell me a 5 second short story about a lion", stream=True)

# Print the response in markdown format
pprint_run_response(response, markdown=True)
# Print the response stream in markdown format
pprint_run_response(response_stream, markdown=True)

Set stream=True to return a stream of RunResponse objects.

RunResponse

The Agent.run() function returns either a RunResponse object or an Iterator[RunResponse] when stream=True. It has the following attributes:

RunResponse Attributes

AttributeTypeDefaultDescription
contentAnyNoneContent of the response.
content_typestr"str"Specifies the data type of the content.
contextList[MessageContext]NoneThe context added to the response for RAG.
eventstrRunEvent.run_response.valueEvent type of the response.
event_dataDict[str, Any]NoneData associated with the event.
messagesList[Message]NoneA list of messages included in the response.
metricsDict[str, Any]NoneUsage metrics of the run.
modelstrNoneThe model used in the run.
run_idstrNoneRun Id.
agent_idstrNoneAgent Id for the run.
session_idstrNoneSession Id for the run.
toolsList[Dict[str, Any]]NoneList of tools provided to the model.
imagesList[Image]NoneList of images the model produced.
videosList[Video]NoneList of videos the model produced.
audioList[Audio]NoneList of audio snippets the model produced.
response_audioModelResponseAudioNoneThe model’s raw response in audio.
created_atint-Unix timestamp of the response creation.