Your first Agents
What are Agents?
Agents are AI programs that operate autonomously.
The core of an Agent is the model, tools and instructions:
- Model: is the brain of an Agent, helping it reason, act, and respond to the user.
- Tools: are the body of an Agent, enabling it to interact with the real world.
- Instructions: guide the Agent’s behavior. Better the model, better it is at following instructions.
Agents also have memory, knowledge, storage and the ability to reason:
- Reasoning: enables Agents to “think” before responding and “analyze” the results of their actions (i.e. tool calls), this improves the Agents’ ability to solve problems that require sequential tool calls.
- Knowledge: is domain-specific information that the Agent can search on demand to make better decisions and provide accurate responses. Knowledge is stored in a vector database and this search on demand pattern is known as Agentic RAG.
- Storage: is used by Agents to save session history and state in a database. Model APIs are stateless and storage enables us to continue conversations from where they left off. This makes Agents stateful, enabling multi-turn conversations.
- Memory: gives Agents the ability to store and recall information from previous interactions, allowing them to learn user preferences and personalize their responses.
Basic Agent
The simplest Agent only contains a model and calls the model API to generate a response.
Agno provides a unified interface to 23+ model providers, so you can test different providers and switch models as needed.
To run the agent, install dependencies and export your ANTHROPIC_API_KEY
.
Setup your virtual environment
Install dependencies
Export your Anthropic key
Run the agent
Agent with tools
Lets give the Agent a tool to fetch the latest stock price using the yfinance
library.
Install dependencies and run the Agent
Install new dependencies
Run the agent
Now the Agent will be able to give you the latest stock price.
Agent with instructions
The Agent will give you the latest stock price, but it will also yap along with it. To control the Agent’s output, we can and should add instructions.
Run the Agent
This will give you a much more concise response.
Set debug_mode=True
or export AGNO_DEBUG=true
to see the system prompt, user messages and tool calls.
Agent with reasoning
Agents can also “think” & “analyze” to solve problems that require more than one step. The ReasoningTools
is one of the best “hacks” to improve the Agents’s response quality.
Run the Agent
Agent with knowledge
While models have a large amount of training data, we almost always need to give them domain-specific information to help them achieve their task. This knowledge isn’t just used for RAG, an emerging use case is to dynamically provide few-shot examples to the model.
Agno Agents use Agentic RAG by default, which means they will search their knowledge base, at runtime, for the specific information they need to achieve their task.
Here’s how the following example works:
- The
UrlKnowledge
will download the Agno documentation and load it into a LanceDB vector database, using OpenAI for embeddings - At runtime, the Agent will search the knowledge base for the most relevant information and use the
ReasoningTools
to reason about the user’s question.
Install dependencies, export your OPENAI_API_KEY
and run the Agent
Install new dependencies
Run the agent
Agent with storage
Storage
drivers will help you save Agent sessions and state in a database. Model APIs are stateless and storage enables us to continue conversations from where they left off, by storing chat history and state in a database.
In this example, we’ll use the SqliteStorage
driver to save the Agent’s session history and state in a database.
We’ll also set the session_id
to a fixed value to demo persistence. Run this example multiple times to see the conversation continue from where it left off.
Install dependencies and run the Agent
Install new dependencies
Run the agent
Agent with memory
Memory
drivers enable Agents to store and recall information about users from previous interactions, allowing them to learn user preferences and personalize their responses.
In this example, we’ll use the v2 Memory driver to store user memories in a Sqlite database.
Because memories are tied to a user, we’ll set the user_id
to a fixed value to build a persona for the user.
Run the Agent
Multi Agent Teams
Agents work best when they have a singular purpose, a narrow scope and a small number of tools. When the number of tools grows beyond what the language model can handle or the tools belong to different categories, use a team of agents to spread the load.
Agno provides an industry leading multi-agent Architecture that allows you to build Reasoning Agent Teams. You can run the team in 3 modes: route
, coordinate
and collaborate
.
In this example, we’ll build a team of 2 agents to analyze the semiconductor market performance, reasoning step by step.
Install dependencies and run the Agent team
Install dependencies
Run the agent
Debugging
Want to see the system prompt, user messages and tool calls?
Agno includes a built-in debugger that will print debug logs in the terminal. Set debug_mode=True
on any agent or set AGNO_DEBUG=true
in your environment.
Run the agent to view debug logs in the terminal: