Skip to content

Commit 0c6f76e

Browse files
committed
introduction
1 parent e69a174 commit 0c6f76e

File tree

11 files changed

+259
-90
lines changed

11 files changed

+259
-90
lines changed

agents/memory.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Memory
44

55
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. **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**.
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 persisted 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**.
88

99
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**.
1010

agents/storage.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Storage
66

77
Agents come with built-in memory but it only lasts while the session is active.
88

9-
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.
9+
To persist session 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.
1010

1111
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:
1212
- Storage saves our Agent's session data for inspection and evaluations.

introduction/agents.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Set `debug_mode=True` or `export AGNO_DEBUG=true` to see the system prompt, user
167167

168168
## Agent with reasoning
169169

170-
Agents can also **"think" & "reason"** to solve problems that require more than one step. The `ReasoningTools` is one of the best "hacks" to improve the Agents's response quality.
170+
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.
171171

172172
```python agent_with_reasoning.py
173173
from agno.agent import Agent

knowledge/introduction.mdx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
title: Introduction
33
---
44

5-
A **knowledge base** is a database of information that an agent can search to improve its responses. This information is stored in a vector database and provides agents with business context, helping them respond in a context-aware manner. The general syntax is:
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+
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:
618

719
```python
820
from agno.agent import Agent, AgentKnowledge
@@ -18,6 +30,24 @@ knowledge_base.load_text("The sky is blue")
1830
agent = Agent(knowledge=knowledge_base, search_knowledge=True)
1931
```
2032

33+
We can give our agent access to the knowledge base in the following ways:
34+
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
43+
def retriever(agent: Agent, query: str, num_documents: Optional[int], **kwargs) -> Optional[list[dict]]:
44+
...
45+
```
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>
50+
2151
## Vector Databases
2252

2353
While any type of storage can act as a knowledge base, vector databases offer the best solution for retrieving relevant results from dense information quickly. Here's how vector databases are used with Agents:

memory/introduction.mdx

Lines changed: 127 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,130 @@ title: Introduction
44

55
# Memory for Agents
66

7-
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:
7+
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:
88

9-
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**.
10-
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**.
11-
3. **Session Summaries:** Condensed representations of conversations, useful when chat histories grow too long. **This is called "Summary" in Agno**.
9+
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 persisted 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**.
10+
11+
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**.
12+
13+
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**.
1214

1315
Memory helps Agents:
14-
- Manage conversation state (chat history)
15-
- Personalize responses to users (user memories)
16-
- Maintain long-session context (session summaries)
16+
- Manage session history and state (session storage).
17+
- Personalize responses to users (user memories).
18+
- Maintain long-session context (session summaries).
19+
20+
## Managing User Memory
21+
22+
When we speak about Memory, the commonly agreed upon understanding of Memory is the ability to store insights and facts about the user the Agent is interacting with. In short, build a persona of the user, learn about their preferences and use that to personalize the Agent's response.
23+
24+
### Agentic Memory
25+
26+
Agno Agents natively support Agentic Memory Management and recommend it as the best way to give Agents memory.
27+
28+
With Agentic Memory, The Agent itself creates, updates and deletes memories from user conversations.
29+
30+
Set `enable_agentic_memory=True` to enable Agentic Memory.
31+
32+
```python agentic_memory.py
33+
from agno.agent.agent import Agent
34+
from agno.memory.v2.db.sqlite import SqliteMemoryDb
35+
from agno.memory.v2.memory import Memory
36+
from agno.models.openai import OpenAIChat
37+
from rich.pretty import pprint
38+
39+
memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")
40+
# No need to set the model, it gets set to the model of the agent
41+
memory = Memory(db=memory_db, delete_memories=True, clear_memories=True)
42+
43+
# Reset the memory for this example
44+
memory.clear()
45+
46+
# User ID for the memory
47+
john_doe_id = "[email protected]"
48+
agent = Agent(
49+
model=OpenAIChat(id="gpt-4o-mini"),
50+
memory=memory,
51+
enable_agentic_memory=True,
52+
)
53+
54+
# Send a message to the agent that would require the memory to be used
55+
agent.print_response(
56+
"My name is John Doe and I like to hike in the mountains on weekends.",
57+
stream=True,
58+
user_id=john_doe_id,
59+
)
60+
61+
# Send a message to the agent that checks the memory is working
62+
agent.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)
63+
64+
# Print the memories for the user
65+
memories = memory.get_user_memories(user_id=john_doe_id)
66+
print("Memories about John Doe:")
67+
pprint(memories)
68+
69+
# Send a message to the agent that removes all memories for the user
70+
agent.print_response(
71+
"Remove all existing memories of me.",
72+
stream=True,
73+
user_id=john_doe_id,
74+
)
75+
memories = memory.get_user_memories(user_id=john_doe_id)
76+
print("Memories about John Doe:")
77+
pprint(memories)
78+
```
79+
80+
### Create Memories after each run
1781

18-
Memory is critical for personal assistants, it allows Agents to "Remember" and "Personalize" their responses to users. Learn more about agent memory [here](/agents/memory) and about managing sessions [here](/agents/sessions).
82+
Set `enable_user_memories=True` to trigger the `MemoryManager` after each run. We recommend using Agentic Memory but this option is there is you need it.
83+
84+
```python create_memories_after_each_run.py
85+
from agno.agent.agent import Agent
86+
from agno.memory.v2.db.sqlite import SqliteMemoryDb
87+
from agno.memory.v2.memory import Memory
88+
from agno.models.openai import OpenAIChat
89+
from rich.pretty import pprint
90+
91+
memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")
92+
# No need to set the model, it gets set to the model of the agent
93+
memory = Memory(db=memory_db, delete_memories=True, clear_memories=True)
94+
95+
# Reset the memory for this example
96+
memory.clear()
97+
98+
# User ID for the memory
99+
john_doe_id = "[email protected]"
100+
agent = Agent(
101+
model=OpenAIChat(id="gpt-4o-mini"),
102+
memory=memory,
103+
enable_user_memories=True,
104+
)
105+
106+
# Send a message to the agent that would require the memory to be used
107+
agent.print_response(
108+
"My name is John Doe and I like to hike in the mountains on weekends.",
109+
stream=True,
110+
user_id=john_doe_id,
111+
)
112+
113+
# Send a message to the agent that checks the memory is working
114+
agent.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)
115+
116+
# Print the memories for the user
117+
memories = memory.get_user_memories(user_id=john_doe_id)
118+
print("Memories about John Doe:")
119+
pprint(memories)
120+
121+
# Send a message to the agent that removes all memories for the user
122+
agent.print_response(
123+
"Remove all existing memories of me.",
124+
stream=True,
125+
user_id=john_doe_id,
126+
)
127+
memories = memory.get_user_memories(user_id=john_doe_id)
128+
print("Memories about John Doe:")
129+
pprint(memories)
130+
```
19131

20132
## Memory Architecture
21133

@@ -35,16 +147,8 @@ memory_db = SqliteMemoryDb(table_name="memory", db_file="memory.db")
35147
memory = Memory(db=memory_db)
36148
```
37149

38-
## Managing Memory
39-
40-
The core `Memory` class orchestrates all memory-related operations.
150+
### Adding a new memory
41151

42-
### User Memories
43-
44-
The `UserMemory` class represents individual facts or insights about users.
45-
46-
47-
#### Adding a new memory
48152
```python
49153
from agno.memory.v2.memory import Memory
50154
from agno.memory.v2.schema import UserMemory
@@ -61,7 +165,8 @@ memory_id = memory.add_user_memory(
61165
)
62166
```
63167

64-
#### Updating a memory
168+
### Updating a memory
169+
65170
```python
66171
from agno.memory.v2.memory import Memory
67172
from agno.memory.v2.schema import UserMemory
@@ -70,7 +175,9 @@ memory = Memory()
70175

71176
# Replace a user memory
72177
memory_id = memory.replace_user_memory(
178+
# The id of the memory to replace
73179
memory_id=previous_memory_id,
180+
# The new memory to replace it with
74181
memory=UserMemory(
75182
memory="The user's name is Verna Doe",
76183
topics=["personal", "name"]
@@ -79,7 +186,8 @@ memory_id = memory.replace_user_memory(
79186
)
80187
```
81188

82-
#### Deleting a memory
189+
### Deleting a memory
190+
83191
```python
84192
from agno.memory.v2.memory import Memory
85193

@@ -89,10 +197,6 @@ memory = Memory()
89197
memory.delete_user_memory(user_id="[email protected]", memory_id=memory_id)
90198
```
91199

92-
## Agentic Memory
93-
94-
You can use a model to create memories from user information or conversations.
95-
96200
### Creating memories from user information
97201

98202
```python

memory/storage.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ title: Storage
44

55
# Memory Storage
66

7-
Agno's memory system provides persistent storage options to ensure memories are retained across application restarts. This is critical for production applications where users expect consistent experiences over time.
7+
To persist memories across sessions and application restarts, store memories in a persistent storage like a database.
8+
9+
If you're using Memory in production, persistent storage is critical as you'd want to retain user memories across application restarts.
10+
11+
Agno's memory system supports multiple persistent storage options.
812

913
## Storage Options
1014

@@ -115,14 +119,14 @@ from agno.storage.sqlite import SqliteStorage
115119

116120
# Create memory storage
117121
memory_db = SqliteMemoryDb(
118-
table_name="memories",
122+
table_name="memories",
119123
db_file="tmp/memory.db"
120124
)
121125
memory = Memory(db=memory_db)
122126

123127
# Create agent storage
124128
agent_storage = SqliteStorage(
125-
table_name="agent_sessions",
129+
table_name="agent_sessions",
126130
db_file="tmp/agent_storage.db"
127131
)
128132

models/introduction.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
title: Introduction
33
---
44

5-
Language Models are machine-learning programs that are trained to understand natural language and code. They provide reasoning and planning capabilities to Agents.
6-
7-
Use any `model` with an `Agent` like:
5+
Language Models are machine-learning programs that are trained to understand natural language and code. They act as the **brain** of the Agent - helping it reason, act, and respond to the user. Better the model, smarter the Agent.
86

97
```python
108
from agno.agent import Agent

reasoning/introduction.mdx

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

5-
Reasoning is the ability to **think and validate** before responding or taking action.
5+
**Reasoning** gives Agents the ability to "think" before responding and "analyze" the results of their actions (i.e. tool calls), greatly improving the Agents' ability to solve problems that require sequential tool calls.
66

77
Reasoning Agents go through an internal chain of thought before responding, working through different ideas, validating and correcting as needed. Agno supports 3 approaches to reasoning:
88
1. [Reasoning Models](#reasoning-models)
@@ -35,7 +35,7 @@ Read more about reasoning models in the [Reasoning Models Guide](/reasoning/reas
3535

3636
## Reasoning Model + Response Model
3737

38-
What if we wanted to use a Reasoning Model to reason but a different model to generate the response? It is well known that reasoning models are great at solving problems but not that great at responding in a natural way (like claude sonnet or gpt-4.5).
38+
What if we wanted to use a Reasoning Model to reason but a different model to generate the response? It is well known that reasoning models are great at solving problems but not that great at responding in a natural way (like claude sonnet or gpt-4o).
3939

4040
By using a separate model for reasoning and a different model for responding, we can have the best of both worlds.
4141

@@ -65,37 +65,34 @@ The research was first published by Anthropic in [this blog post](https://www.an
6565

6666
### Example
6767

68-
```python claude_reasoning_tools.py
69-
from textwrap import dedent
70-
68+
```python claude_thinking_tools.py
7169
from agno.agent import Agent
7270
from agno.models.anthropic import Claude
7371
from agno.tools.thinking import ThinkingTools
7472
from agno.tools.yfinance import YFinanceTools
7573

76-
thinking_agent = Agent(
77-
model=Claude(id="claude-3-7-sonnet-20250219"),
74+
reasoning_agent = Agent(
75+
model=Claude(id="claude-3-7-sonnet-latest"),
7876
tools=[
79-
ThinkingTools(),
80-
YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True),
77+
ThinkingTools(add_instructions=True),
78+
YFinanceTools(
79+
stock_price=True,
80+
analyst_recommendations=True,
81+
company_info=True,
82+
company_news=True,
83+
),
8184
],
82-
instructions=dedent("""\
83-
## Using the think tool
84-
Before taking any action or responding to the user after receiving tool results, use the think tool as a scratchpad to:
85-
- List the specific rules that apply to the current request
86-
- Check if all required information is collected
87-
- Verify that the planned action complies with all policies
88-
- Iterate over tool results for correctness
89-
90-
## Rules
91-
- Its expected that you will use the think tool generously to jot down thoughts and ideas.
92-
- Use tables where possible\
93-
"""),
94-
show_tool_calls=True,
95-
)
96-
thinking_agent.print_response(
97-
"Write a report comparing NVDA to TSLA", stream=True, markdown=True
85+
instructions="Use tables where possible",
86+
markdown=True,
9887
)
88+
89+
if __name__ == "__main__":
90+
reasoning_agent.print_response(
91+
"Write a report on NVDA. Only the report, no other text.",
92+
stream=True,
93+
show_full_reasoning=True,
94+
stream_intermediate_steps=True,
95+
)
9996
```
10097

10198
Read more about reasoning tools in the [Reasoning Tools Guide](/reasoning/reasoning-tools).

0 commit comments

Comments
 (0)