
Example: Research Agent
Let’s create a research agent that can search the web, read the top links and write a report for us. We “prompt” the agent usingdescription and instructions.
The description and instructions are converted to the system prompt and the input (e.g.
Simulation theory) is passed as the user prompt.Use debug_mode=True to view the raw logs behind the scenes.Capturing the Agent’s response in a variable
WhileAgent.print_response() is useful for quick experiments, we typically want to capture the agent’s response in a variable to either pass to the frontend, another agent or use in our application. The Agent.run() function returns the response as a RunResponse object.
stream=False, set stream=True to return a stream of RunResponse objects.
RunResponse
TheAgent.run() function returns either a RunResponse object or an Iterator[RunResponse] when stream=True.
RunResponse Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
content | Any | None | Content of the response. |
content_type | str | "str" | Specifies the data type of the content. |
context | List[MessageContext] | None | The context added to the response for RAG. |
event | str | RunEvent.run_response.value | Event type of the response. |
event_data | Dict[str, Any] | None | Data associated with the event. |
messages | List[Message] | None | A list of messages included in the response. |
metrics | Dict[str, Any] | None | Usage metrics of the run. |
model | Model | OpenAIChat | OpenAI model is used to run by default. |
run_id | str | None | Run Id. |
agent_id | str | None | Agent Id for the run. |
session_id | str | None | Session Id for the run. |
tools | List[Dict[str, Any]] | None | List of tools provided to the model. |
created_at | int | - | Unix timestamp of the response creation. |