Skip to content

Commit d90a0a0

Browse files
authored
add thinking and knowledge tools docs (#239)
1 parent cfd3aae commit d90a0a0

File tree

5 files changed

+251
-2
lines changed

5 files changed

+251
-2
lines changed

mint.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,14 @@
270270
]
271271
},
272272
"tools/mcp",
273-
"tools/reasoning-tools",
273+
{
274+
"group": "Reasoning Tools",
275+
"pages": [
276+
"tools/reasoning_tools/reasoning-tools",
277+
"tools/reasoning_tools/thinking-tools",
278+
"tools/reasoning_tools/knowledge-tools"
279+
]
280+
},
274281
"tools/custom-toolkits",
275282
"tools/selecting-tools",
276283
"tools/async-tools",

reasoning/reasoning-tools.mdx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,57 @@ reasoning_agent.print_response(
6767
)
6868
```
6969

70+
## v2: The Knowledge Tools
71+
72+
The Knowledge Tools take the v1 Reasoning Tools one step further by allowing the Agent to **search** a knowledge base and **analyze** the results of their actions.
73+
74+
**KnowledgeTools = `think` + `search` + `analyze`**
75+
76+
```python knowledge_tools.py
77+
import os
78+
from agno.agent import Agent
79+
from agno.embedder.openai import OpenAIEmbedder
80+
from agno.knowledge.url import UrlKnowledge
81+
from agno.models.openai import OpenAIChat
82+
from agno.tools.knowledge import KnowledgeTools
83+
from agno.vectordb.lancedb import LanceDb, SearchType
84+
85+
86+
agno_docs = UrlKnowledge(
87+
urls=["https://docs.agno.com/llms-full.txt"],
88+
89+
vector_db=LanceDb(
90+
uri="tmp/lancedb",
91+
table_name="agno_docs",
92+
search_type=SearchType.hybrid,
93+
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
94+
),
95+
)
96+
97+
98+
knowledge_tools = KnowledgeTools(
99+
knowledge=agno_docs,
100+
think=True,
101+
search=True,
102+
analyze=True,
103+
add_few_shot=True,
104+
)
105+
106+
107+
agent = Agent(
108+
model=OpenAIChat(id="gpt-4o"),
109+
tools=[knowledge_tools],
110+
show_tool_calls=True,
111+
markdown=True,
112+
)
113+
114+
115+
agno_docs.load(recreate=True)
116+
117+
118+
agent.print_response("How do I build multi-agent teams with Agno?", stream=True)
119+
```
120+
70121
## Developer Resources
71122

72123
You can find more examples in the [Reasoning Tools Cookbook](https://github.com/agno-agi/agno/tree/main/cookbook/reasoning/tools).
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Knowledge Tools
3+
sidebarTitle: Knowledge Tools
4+
---
5+
6+
The `KnowledgeTools` toolkit enables Agents to search, retrieve, and analyze information from knowledge bases. This toolkit integrates with `AgentKnowledge` and provides a structured workflow for finding and evaluating relevant information before responding to users.
7+
8+
The toolkit implements a "Think → Search → Analyze" cycle that allows an Agent to:
9+
1. Think through the problem and plan search queries
10+
2. Search the knowledge base for relevant information
11+
3. Analyze the results to determine if they are sufficient or if additional searches are needed
12+
13+
This approach significantly improves an Agent's ability to provide accurate information by giving it tools to find, evaluate, and synthesize knowledge.
14+
15+
The toolkit includes the following tools:
16+
17+
- `think`: A scratchpad for planning, brainstorming keywords, and refining approaches. These thoughts remain internal to the Agent and are not shown to users.
18+
- `search`: Executes queries against the knowledge base to retrieve relevant documents.
19+
- `analyze`: Evaluates whether the returned documents are correct and sufficient, determining if further searches are needed.
20+
21+
## Example
22+
23+
Here's an example of how to use the `KnowledgeTools` toolkit:
24+
25+
```python
26+
from agno.agent import Agent
27+
from agno.embedder.openai import OpenAIEmbedder
28+
from agno.knowledge.url import UrlKnowledge
29+
from agno.models.openai import OpenAIChat
30+
from agno.tools.knowledge import KnowledgeTools
31+
from agno.vectordb.lancedb import LanceDb, SearchType
32+
33+
# Create a knowledge base containing information from a URL
34+
agno_docs = UrlKnowledge(
35+
urls=["https://docs.agno.com/llms-full.txt"],
36+
# Use LanceDB as the vector database and store embeddings in the `agno_docs` table
37+
vector_db=LanceDb(
38+
uri="tmp/lancedb",
39+
table_name="agno_docs",
40+
search_type=SearchType.hybrid,
41+
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
42+
),
43+
)
44+
45+
knowledge_tools = KnowledgeTools(
46+
knowledge=agno_docs,
47+
think=True,
48+
search=True,
49+
analyze=True,
50+
add_few_shot=True,
51+
)
52+
53+
agent = Agent(
54+
model=OpenAIChat(id="gpt-4o"),
55+
tools=[knowledge_tools],
56+
show_tool_calls=True,
57+
markdown=True,
58+
)
59+
60+
if __name__ == "__main__":
61+
# Load the knowledge base, comment after first run
62+
agno_docs.load(recreate=True)
63+
agent.print_response("How do I build multi-agent teams with Agno?", stream=True)
64+
```
65+
66+
The toolkit comes with default instructions and few-shot examples to help the Agent use the tools effectively. Here is how you can configure them:
67+
68+
```python
69+
from agno.tools.knowledge import KnowledgeTools
70+
71+
knowledge_tools = KnowledgeTools(
72+
knowledge=my_knowledge_base,
73+
think=True, # Enable the think tool
74+
search=True, # Enable the search tool
75+
analyze=True, # Enable the analyze tool
76+
add_instructions=True, # Add default instructions
77+
add_few_shot=True, # Add few-shot examples
78+
few_shot_examples=None, # Optional custom few-shot examples
79+
)
80+
```

tools/reasoning-tools.mdx renamed to tools/reasoning_tools/reasoning-tools.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Reasoning Tools
3-
sidebarTitle: Reasoning
3+
sidebarTitle: Reasoning Tools
44
---
55

66
The `ReasoningTools` toolkit allows an Agent to use reasoning like any other tool, at any point during execution. Unlike traditional approaches that reason once at the start to create a fixed plan, this enables the Agent to reflect after each step, adjust its thinking, and update its actions on the fly.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
title: Thinking Tools
3+
sidebarTitle: Thinking Tools
4+
---
5+
6+
The `ThinkingTools` toolkit provides Agents with a dedicated space for reflection during execution. This toolkit enables an Agent to use a scratchpad for thinking through problems, listing rules, checking information, verifying compliance, and evaluating results before taking actions.
7+
8+
Unlike approaches that have agents immediately respond or take action, this toolkit encourages thoughtful consideration by giving the Agent space to "think" about its actions, examine its own responses, and maintain a log of its thought process throughout the conversation.
9+
10+
The toolkit includes the following tool:
11+
12+
- `think`: This tool serves as a scratchpad for the Agent to reason through problems, list applicable rules, verify collected information, and evaluate planned actions for compliance and correctness.
13+
14+
## Example
15+
16+
Here's an example of how to use the `ThinkingTools` toolkit:
17+
18+
```python
19+
from agno.agent import Agent
20+
from agno.models.anthropic import Claude
21+
from agno.tools.thinking import ThinkingTools
22+
from agno.tools.yfinance import YFinanceTools
23+
24+
thinking_agent = Agent(
25+
model=Claude(id="claude-3-7-sonnet-latest"),
26+
tools=[
27+
ThinkingTools(add_instructions=True),
28+
YFinanceTools(
29+
stock_price=True,
30+
analyst_recommendations=True,
31+
company_info=True,
32+
company_news=True,
33+
),
34+
],
35+
instructions="Use tables where possible",
36+
show_tool_calls=True,
37+
markdown=True,
38+
)
39+
40+
thinking_agent.print_response("Write a report comparing NVDA to TSLA", stream=True)
41+
```
42+
43+
The toolkit comes with default instructions to help the Agent use the tool effectively. Here is how you can enable them:
44+
45+
```python
46+
thinking_agent = Agent(
47+
model=Claude(id="claude-3-7-sonnet-latest"),
48+
tools=[
49+
ThinkingTools(
50+
think=True,
51+
add_instructions=True,
52+
),
53+
],
54+
)
55+
```
56+
57+
`ThinkingTools` can be used with any model provider that supports function calling. Here is an example with of a thinking Agent using `OpenAIChat`:
58+
59+
```python
60+
from textwrap import dedent
61+
62+
from agno.agent import Agent
63+
from agno.models.openai import OpenAIChat
64+
from agno.tools.thinking import ThinkingTools
65+
66+
thinking_agent = Agent(
67+
model=OpenAIChat(id="gpt-4o"),
68+
tools=[ThinkingTools(add_instructions=True)],
69+
instructions=dedent("""\
70+
You are an expert problem-solving assistant with strong analytical skills! 🧠
71+
72+
Your approach to problems:
73+
1. First, break down complex questions into component parts
74+
2. Clearly state your assumptions
75+
3. Develop a structured reasoning path
76+
4. Consider multiple perspectives
77+
5. Evaluate evidence and counter-arguments
78+
6. Draw well-justified conclusions
79+
80+
When solving problems:
81+
- Use explicit step-by-step reasoning
82+
- Identify key variables and constraints
83+
- Explore alternative scenarios
84+
- Highlight areas of uncertainty
85+
- Explain your thought process clearly
86+
\
87+
"""),
88+
add_datetime_to_instructions=True,
89+
stream_intermediate_steps=True,
90+
show_tool_calls=True,
91+
markdown=True,
92+
)
93+
```
94+
95+
This Agent can be used to address complex problems where careful consideration is needed:
96+
97+
```python
98+
thinking_agent.print_response(
99+
"We need to implement a new content moderation policy for our platform. "
100+
stream=True
101+
)
102+
```
103+
104+
or,
105+
106+
```python
107+
thinking_agent.print_response(
108+
"Our company is developing a new AI product. We need to consider ethical implications "
109+
stream=True,
110+
)
111+
```

0 commit comments

Comments
 (0)