Skip to content

Commit e69a174

Browse files
committed
introduction
1 parent 75ca1e9 commit e69a174

File tree

6 files changed

+131
-210
lines changed

6 files changed

+131
-210
lines changed

agents/knowledge.mdx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22
title: Knowledge
33
---
44

5-
**Agents use knowledge to supplement their training data with domain expertise**.
5+
**Knowledge** is domain-specific information that the Agent can **search** at runtime to make better decisions (dynamic few-shot learning) or provide accurate responses (agentic RAG). Knowledge is stored in a vector db and this **searching on demand** pattern is known as Agentic RAG.
66

7-
Knowledge is stored in a vector database and provides agents with business context at query time, helping them respond in a context-aware manner. The general syntax is:
7+
<Accordion title="Dynamic Few-Shot Learning: Text2Sql Agent" icon="database">
8+
Example: If we're building a Text2Sql Agent, we'll need to give the table schemas, column names, data types, example queries, common "gotchas" to help it generate the best-possible SQL query.
9+
10+
We're obviously not going to put this all in the system prompt, instead we store this information in a vector database and let the Agent query it at runtime.
11+
12+
Using this information, the Agent can then generate the best-possible SQL query. This is called dynamic few-shot learning.
13+
</Accordion>
14+
15+
**Agno Agents use Agentic RAG** by default, meaning if you add `knowledge` to an Agent, it will search this knowledge base, at runtime, for the specific information it needs to achieve its task.
16+
17+
The simplest example of how to add knowledge to an Agent is:
818

919
```python
1020
from agno.agent import Agent, AgentKnowledge
@@ -20,15 +30,23 @@ knowledge_base.load_text("The sky is blue")
2030
agent = Agent(knowledge=knowledge_base, search_knowledge=True)
2131
```
2232

23-
You can give your agent access to your knowledge base in the following ways:
33+
We can give our agent access to the knowledge base in the following ways:
2434

25-
- You can set `search_knowledge=True` to provide a `search_knowledge_base()` tool to your agent. This is automatically added if you provide a knowledgebase.
26-
- You can set `add_references=True` to automatically add references from the knowledge base. Optionally pass your own `retriever` callable with the following signature:
27-
```
35+
- We can set `search_knowledge=True` to add a `search_knowledge_base()` tool to the Agent. `search_knowledge` is `True` **by default** if you add `knowledge` to an Agent.
36+
- We can set `add_references=True` to automatically add references from the knowledge base to the Agent's prompt. This is the traditional 2023 RAG approach.
37+
38+
<Tip>
39+
40+
If you need complete control over the knowledge base search, you can pass your own `retriever` function with the following signature:
41+
42+
```python
2843
def retriever(agent: Agent, query: str, num_documents: Optional[int], **kwargs) -> Optional[list[dict]]:
2944
...
3045
```
31-
- You can set `update_knowledge=True` to provide a `add_to_knowledge()` tool to your agent allowing it to update the knowledgebase.
46+
47+
This function is called during `search_knowledge_base()` and is used by the Agent to retrieve references from the knowledge base.
48+
49+
</Tip>
3250

3351
## Vector Databases
3452

agents/memory.mdx

Lines changed: 48 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
title: Memory
33
---
44

5-
If you're building intelligent agents, you need to give them memory which is the ability to **remember**, **reason** and **personalize** responses to users. Memory comes in 3 shapes:
5+
If you're building intelligent agents, you need to give them memory **which is their ability to learn about the user they are interacting with**. Memory comes in 3 shapes:
66

7-
1. **Chat History:** This is the current conversation between users and the agent, stored as sessions in chronological order. This is the most basic form of memory and **called "Storage" in Agno**.
8-
2. **User Memories:** Insights and facts about users extracted from conversations, helping agents personalize their responses to users. Think of this as adding a "ChatGPT like memory" to your agent. **This is called "Memory" in Agno**.
9-
3. **Session Summaries:** Condensed representations of conversations, useful when chat histories grow too long. **This is called "Summary" in Agno**.
7+
1. **Session Storage:** Session storage saves sessions in a database and enables Agents to have multi-turn conversations. Session storage also holds the session state, which is persistent across runs because it is saved to the database after each run. Session storage is a form of short-term memory **called "Storage" in Agno**.
8+
9+
2. **User Memories:** The Agent can also store insights and facts about the user it learns over time. This helps the agents personalize its response to the user it is interacting with. Think of this as adding "ChatGPT like memory" to your agent. **This is called "Memory" in Agno**.
10+
11+
3. **Session Summaries:** The Agent can store a condensed representations of the session, useful when chat histories gets too long. **This is called "Summary" in Agno**.
1012

1113
Memory helps Agents:
12-
- Manage conversation state (chat history)
13-
- Personalize responses to users (user memories)
14-
- Maintain long-session context (session summaries)
14+
- Manage session history and state (session storage).
15+
- Personalize responses to users (user memories).
16+
- Maintain long-session context (session summaries).
1517

16-
Memory is critical for personal assistants, it allows Agents to "Remember" and "Personalize" their responses to users.
18+
## Default Memory
1719

18-
## Built-in Memory
20+
Every Agent comes with built-in memory that keeps track of the session while the Agent is running.
1921

20-
Every Agent comes with built-in memory that can be used to access the historical **runs** per session.
22+
You can access the messages in this session using `agent.get_messages_for_session()`.
2123

2224
You can give your agent access to chat history in the following ways:
2325

@@ -29,11 +31,11 @@ You can give your agent access to chat history in the following ways:
2931
<Step title="Built-in memory example">
3032
```python agent_memory.py
3133
from agno.agent import Agent
32-
from agno.models.google.gemini import Gemini
34+
from agno.models.openai import OpenAIChat
3335
from rich.pretty import pprint
3436

3537
agent = Agent(
36-
model=Gemini(id="gemini-2.0-flash-exp"),
38+
model=OpenAIChat(id="gpt-4o"),
3739
# Set add_history_to_messages=true to add the previous chat history to the messages sent to the Model.
3840
add_history_to_messages=True,
3941
# Number of historical responses to add to the messages.
@@ -44,12 +46,12 @@ You can give your agent access to chat history in the following ways:
4446
# -*- Create a run
4547
agent.print_response("Share a 2 sentence horror story", stream=True)
4648
# -*- Print the messages in the memory
47-
pprint([m.model_dump(include={"role", "content"}) for m in agent.memory.messages])
49+
pprint([m.model_dump(include={"role", "content"}) for m in agent.get_messages_for_session()])
4850

4951
# -*- Ask a follow up question that continues the conversation
5052
agent.print_response("What was my first message?", stream=True)
5153
# -*- Print the messages in the memory
52-
pprint([m.model_dump(include={"role", "content"}) for m in agent.memory.messages])
54+
pprint([m.model_dump(include={"role", "content"}) for m in agent.get_messages_for_session()])
5355
```
5456
</Step>
5557
<Step title="Run the example">
@@ -72,14 +74,19 @@ You can give your agent access to chat history in the following ways:
7274
</Step>
7375
</Steps>
7476

75-
## Persistent Memory
77+
## Session Storage
78+
79+
The built-in memory only lasts while the session is active.
7680

77-
The built-in memory only lasts while the session is active. To persist chat history across sessions, we can store agent sessions in a database using `AgentStorage`.
81+
To persist history and state across runs, we can provide `AgentStorage` which saves an Agent's session to a database or file. Storage has typically been an under-discussed part of agentic infrastructure, but we see it as one of the most critical pieces of the stack.
7882

79-
Storage is a necessary component when building user facing AI products as any production application will require users to be able to "continue" their conversation with the Agent.
83+
While storage is absolutely necessary when building user facing AI products as any production application will need to be able to retrieve sessions, continue sessions, and save state between runs. There is so much more:
84+
- Storage saves our Agent's session data for inspection and evaluations.
85+
- Storage helps us extract few-shot examples from session data, which can be used to improve the Agent.
86+
- Storage enables us to build internal monitoring tools and dashboards.
8087

8188
<Steps>
82-
<Step title="Persistent memory example">
89+
<Step title="Storage example">
8390
Let's test this out, create a file `persistent_memory.py` with the following code:
8491

8592
```python persistent_memory.py
@@ -156,11 +163,11 @@ You can view the agent sessions in the sqlite database and continue any conversa
156163

157164
Read more in the [storage](/agents/storage) section.
158165

159-
## Creating User Memories
166+
## User Memories
160167

161-
Along with storing chat history and run messages, `Memory` can be used by the agent to create user memories based on the conversation history.
168+
Along with storing session history and state, Agents can also create user memories based on the conversation history.
162169

163-
To enable user memory creation, create an `Agent` with `Memory` and a memory database, and set `enable_user_memories=True`.
170+
To enable user memories, give your Agent a `Memory` object and set `enable_agentic_memory=True`.
164171

165172
<Note>
166173
Enabling user memory will also add all existing user memories to the agent's system prompt.
@@ -173,38 +180,41 @@ Enabling user memory will also add all existing user memories to the agent's sys
173180
from agno.memory.v2.db.sqlite import SqliteMemoryDb
174181
from agno.memory.v2.memory import Memory
175182
from agno.models.google.gemini import Gemini
176-
from agno.storage.sqlite import SqliteStorage
177-
178-
session_id = "session_1"
179-
jon_hamm_id = "[email protected]"
180183

181184
memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")
182185
memory = Memory(db=memory_db)
183186

187+
john_doe_id = "[email protected]"
188+
184189
agent = Agent(
185190
model=Gemini(id="gemini-2.0-flash-exp"),
186191
memory=memory,
187-
storage=SqliteStorage(
188-
table_name="agent_sessions", db_file="tmp/persistent_memory.db"
189-
),
190-
enable_user_memories=True,
192+
enable_agentic_memory=True,
191193
)
192194

195+
# The agent can add new memories to the user's memory
193196
agent.print_response(
194-
"My name is Jon Hamm and I like to hike in the mountains on weekends.",
197+
"My name is John Doe and I like to hike in the mountains on weekends.",
195198
stream=True,
196-
user_id=jon_hamm_id,
197-
session_id=session_id,
199+
user_id=john_doe_id,
198200
)
199201

202+
agent.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)
203+
204+
# The agent can also remove all memories from the user's memory
200205
agent.print_response(
201-
"What are my hobbies?", stream=True, user_id=jon_hamm_id, session_id=session_id
206+
"Remove all existing memories of me. Completely clear the DB.",
207+
stream=True,
208+
user_id=john_doe_id,
202209
)
203210

204-
memories = memory.get_user_memories(user_id=jon_hamm_id)
205-
print("Jon Hamm's memories:")
206-
for i, m in enumerate(memories):
207-
print(f"{i}: {m.memory}")
211+
agent.print_response(
212+
"My name is John Doe and I like to paint.", stream=True, user_id=john_doe_id
213+
)
214+
215+
# The agent can remove specific memories from the user's memory
216+
agent.print_response("Remove any memory of my name.", stream=True, user_id=john_doe_id)
217+
208218
```
209219
</Step>
210220

@@ -231,7 +241,7 @@ Enabling user memory will also add all existing user memories to the agent's sys
231241
User memories are stored in the `Memory` object and persisted in the `SqliteMemoryDb` to be used across multiple users and multiple sessions.
232242

233243

234-
## Creating Session Summaries
244+
## Session Summaries
235245

236246
To enable session summaries, set `enable_session_summaries=True` on the `Agent`.
237247

@@ -297,79 +307,6 @@ To enable session summaries, set `enable_session_summaries=True` on the `Agent`.
297307
</Steps>
298308

299309

300-
## Agentic Memory Management
301-
302-
You can also enable an agent to manage the user memories for you. Enable agentic memory management by setting `enable_agentic_memory=True` on the `Agent`.
303-
304-
<Note>
305-
Enabling agentic memory will also add all existing user memories to the agent's system prompt.
306-
</Note>
307-
308-
<Steps>
309-
<Step title="Agentic memory management example">
310-
```python agentic_memory_management.py
311-
from agno.agent import Agent
312-
from agno.memory.v2.db.sqlite import SqliteMemoryDb
313-
from agno.memory.v2.memory import Memory
314-
from agno.models.google.gemini import Gemini
315-
316-
memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")
317-
memory = Memory(db=memory_db)
318-
319-
john_doe_id = "[email protected]"
320-
321-
agent = Agent(
322-
model=Gemini(id="gemini-2.0-flash-exp"),
323-
memory=memory,
324-
enable_agentic_memory=True,
325-
)
326-
327-
# The agent can add new memories to the user's memory
328-
agent.print_response(
329-
"My name is John Doe and I like to hike in the mountains on weekends.",
330-
stream=True,
331-
user_id=john_doe_id,
332-
)
333-
334-
agent.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)
335-
336-
# The agent can also remove all memories from the user's memory
337-
agent.print_response(
338-
"Remove all existing memories of me. Completely clear the DB.",
339-
stream=True,
340-
user_id=john_doe_id,
341-
)
342-
343-
agent.print_response(
344-
"My name is John Doe and I like to paint.", stream=True, user_id=john_doe_id
345-
)
346-
347-
# The agent can remove specific memories from the user's memory
348-
agent.print_response("Remove any memory of my name.", stream=True, user_id=john_doe_id)
349-
350-
```
351-
</Step>
352-
<Step title="Run the example">
353-
Install libraries
354-
355-
```shell
356-
pip install google-genai agno
357-
```
358-
359-
Export your key
360-
```shell
361-
export GOOGLE_API_KEY=xxx
362-
```
363-
364-
Run the example
365-
366-
```shell
367-
python agentic_memory_management.py
368-
```
369-
</Step>
370-
</Steps>
371-
372-
373310
## Attributes
374311

375312
| Parameter | Type | Default | Description |

agents/run.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
title: Agent.run()
33
---
44

5-
Use the `Agent.run()` function to run the agent and return the response as a `RunResponse` object or a stream of `RunResponse` objects.
5+
The `Agent.run()` function runs the agent and generates a response, either as a `RunResponse` object or a stream of `RunResponse` objects.
66

7-
<Tip>
8-
Many of our examples use `agent.print_response()` but that is just a helper utility to print the response in the terminal. In practice, you should always use `agent.run()`.
9-
</Tip>
7+
Many of our examples use `agent.print_response()` which is a helper utility to print the response in the terminal. It uses `agent.run()` under the hood.
8+
9+
Here's how to run your agent. The response is captured in the `response` and `response_stream` variables.
1010

1111
```python
1212
from typing import Iterator

agents/sessions.mdx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ title: Sessions
44

55
When we call `Agent.run()`, it creates a stateless, singular Agent run.
66

7-
But what if we want to continue this run i.e. have a multi-turn conversation? That's where `sessions` come in. A session is a multi-turn conversation between a user and an Agent. Using a `session_id`, we can maintain conversation history and state across multiple runs.
7+
But what if we want to continue this run i.e. have a multi-turn conversation? That's where `sessions` come in. A session is collection of consecutive runs.
8+
9+
In practice, a session is a multi-turn conversation between a user and an Agent. Using a `session_id`, we can pass the conversation history and state across multiple runs.
810

911
Let's outline some key concepts:
1012

11-
- **Session:** A session is a multi-turn conversation between a user and an Agent. Sessions are identified by a `session_id` and each turn is called a **run**.
12-
- **Run:** Every interaction (i.e. chat or turn) with an Agent is called a **run**. Runs are identified by a `run_id`. `Agent.run()` creates a new `run_id` when called.
13-
- **Messages:** are the individual messages sent to and received from the model. They are the underlying data structure that the Agent and model communicate using. Each run contains a list of messages and each session contains a list of runs.
13+
- **Session:** A session is collection of consecutive runs like a multi-turn conversation between a user and an Agent. Sessions are identified by a `session_id` and each turn is a **run**.
14+
- **Run:** Every interaction (i.e. chat or turn) with an Agent is called a **run**. Runs are identified by a `run_id` and `Agent.run()` creates a new `run_id` when called.
15+
- **Messages:** are the individual messages sent between the model and the Agent. Messages are the communication protocol between the Agent and model.
1416

15-
Let's start with an example where a single run is created with an Agent. A `run_id` is automatically generated, as well as a `session_id` (because we didn't provide one to continue the conversation). This run is not yet associated with a specific user.
17+
Let's start with an example where a single run is created with an Agent. A `run_id` is automatically generated, as well as a `session_id` (because we didn't provide one to continue the conversation). This run is not yet associated with a user.
1618

1719
```python
1820
from typing import Iterator
@@ -26,19 +28,19 @@ agent = Agent(model=OpenAIChat(id="gpt-4o-mini"))
2628
agent.print_response("Tell me a 5 second short story about a robot")
2729
```
2830

29-
## Each User gets a Unique Set of Sessions
31+
## Multi-user, multi-session Agents
3032

31-
Each user that is interacting with an Agent maintains a unique set of sessions. Set a `user_id` to connect a user to their sessions.
33+
Each user that is interacting with an Agent gets a unique set of sessions and you can have multiple users interacting with the same Agent at the same time.
3234

33-
In the examples below, we set a `session_id` to demo how you can continue multi-turn conversations with multiple users at the same time. In production, the `session_id` is automatically generated.
35+
Set a `user_id` to connect a user to their sessions with the Agent.
3436

35-
Note: Multi-user, multi-session currently only works with `Memory.v2`.
37+
In the example below, we set a `session_id` to demo how to have multi-turn conversations with multiple users at the same time. In production, the `session_id` is auto generated.
3638

37-
<Tip>
39+
<Note>
3840

39-
`Memory.v2` will become the default memory implementation in the next release.
41+
Note: Multi-user, multi-session currently only works with `Memory.v2`, which will become the default memory implementation in the next release.
4042

41-
</Tip>
43+
</Note>
4244

4345
```python
4446
from agno.agent import Agent

0 commit comments

Comments
 (0)