You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: agents/knowledge.mdx
+25-7Lines changed: 25 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,19 @@
2
2
title: Knowledge
3
3
---
4
4
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.
6
6
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:
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:
8
18
9
19
```python
10
20
from agno.agent import Agent, AgentKnowledge
@@ -20,15 +30,23 @@ knowledge_base.load_text("The sky is blue")
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:
24
34
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:
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:
6
6
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**.
Memory is critical for personal assistants, it allows Agents to "Remember" and "Personalize" their responses to users.
18
+
## Default Memory
17
19
18
-
## Built-in Memory
20
+
Every Agent comes with built-in memory that keeps track of the session while the Agent is running.
19
21
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()`.
21
23
22
24
You can give your agent access to chat history in the following ways:
23
25
@@ -29,11 +31,11 @@ You can give your agent access to chat history in the following ways:
29
31
<Steptitle="Built-in memory example">
30
32
```python agent_memory.py
31
33
from agno.agent import Agent
32
-
from agno.models.google.geminiimportGemini
34
+
from agno.models.openaiimportOpenAIChat
33
35
from rich.pretty import pprint
34
36
35
37
agent = Agent(
36
-
model=Gemini(id="gemini-2.0-flash-exp"),
38
+
model=OpenAIChat(id="gpt-4o"),
37
39
# Set add_history_to_messages=true to add the previous chat history to the messages sent to the Model.
38
40
add_history_to_messages=True,
39
41
# 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:
44
46
# -*- Create a run
45
47
agent.print_response("Share a 2 sentence horror story", stream=True)
46
48
# -*- 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()])
48
50
49
51
# -*- Ask a follow up question that continues the conversation
50
52
agent.print_response("What was my first message?", stream=True)
51
53
# -*- 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()])
53
55
```
54
56
</Step>
55
57
<Steptitle="Run the example">
@@ -72,14 +74,19 @@ You can give your agent access to chat history in the following ways:
72
74
</Step>
73
75
</Steps>
74
76
75
-
## Persistent Memory
77
+
## Session Storage
78
+
79
+
The built-in memory only lasts while the session is active.
76
80
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.
78
82
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.
80
87
81
88
<Steps>
82
-
<Steptitle="Persistent memory example">
89
+
<Steptitle="Storage example">
83
90
Let's test this out, create a file `persistent_memory.py` with the following code:
84
91
85
92
```python persistent_memory.py
@@ -156,11 +163,11 @@ You can view the agent sessions in the sqlite database and continue any conversa
156
163
157
164
Read more in the [storage](/agents/storage) section.
158
165
159
-
## Creating User Memories
166
+
## User Memories
160
167
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.
162
169
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`.
164
171
165
172
<Note>
166
173
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
173
180
from agno.memory.v2.db.sqlite import SqliteMemoryDb
"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
+
208
218
```
209
219
</Step>
210
220
@@ -231,7 +241,7 @@ Enabling user memory will also add all existing user memories to the agent's sys
231
241
User memories are stored in the `Memory` object and persisted in the `SqliteMemoryDb` to be used across multiple users and multiple sessions.
232
242
233
243
234
-
## Creating Session Summaries
244
+
## Session Summaries
235
245
236
246
To enable session summaries, set `enable_session_summaries=True` on the `Agent`.
237
247
@@ -297,79 +307,6 @@ To enable session summaries, set `enable_session_summaries=True` on the `Agent`.
297
307
</Steps>
298
308
299
309
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
-
<Steptitle="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
Copy file name to clipboardExpand all lines: agents/run.mdx
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,11 @@
2
2
title: Agent.run()
3
3
---
4
4
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.
6
6
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.
Copy file name to clipboardExpand all lines: agents/sessions.mdx
+14-12Lines changed: 14 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,17 @@ title: Sessions
4
4
5
5
When we call `Agent.run()`, it creates a stateless, singular Agent run.
6
6
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.
8
10
9
11
Let's outline some key concepts:
10
12
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.
14
16
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.
agent.print_response("Tell me a 5 second short story about a robot")
27
29
```
28
30
29
-
## Each User gets a Unique Set of Sessions
31
+
## Multi-user, multi-session Agents
30
32
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.
32
34
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.
34
36
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.
36
38
37
-
<Tip>
39
+
<Note>
38
40
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.
0 commit comments