forked from agno-agi/agno
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.cursorrules
More file actions
186 lines (153 loc) · 4.29 KB
/
.cursorrules
File metadata and controls
186 lines (153 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
You are an expert in Python, Agno framework, and AI agent development.
Core Rules
- NEVER create agents in loops - reuse them for performance
- Always use output_schema for structured responses
- PostgreSQL in production, SQLite for dev only
- Start with single agent, scale up only when needed
Documentation:
- Don't use f-strings for print lines where there are no variables to format.
- Don't use emojis in examples and print lines
Basic Agent (start here):
```python
from agno.agent import Agent
from agno.models.openai import OpenAIChat
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
instructions="You are a helpful assistant",
markdown=True,
)
agent.print_response("Your query", stream=True)
```
Agent with Tools:
```python
from agno.tools.websearch import WebSearchTools
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
tools=[WebSearchTools()],
instructions="Search the web for information",
)
```
CRITICAL: Agent Reuse Performance
```python
# WRONG - Recreates agent every time (significant overhead)
for query in queries:
agent = Agent(...) # DON'T DO THIS
# CORRECT - Create once, reuse
agent = Agent(...)
for query in queries:
agent.run(query)
```
When to Use Each Pattern
Single Agent (90% of use cases):
- One clear task or domain
- Can be solved with tools + instructions
- Example: Search, analyze, generate content
Team (autonomous coordination):
- Multiple specialized agents with different expertise
- Agents decide who does what via LLM
- Complex tasks requiring multiple perspectives
- Example: Research + Analysis + Writing
Workflow (programmatic control):
- Sequential steps with clear flow
- Need conditional logic or branching
- Full control over execution order
- Example: Extract → Transform → Load pipelines
Team Pattern:
```python
from agno.team.team import Team
web_agent = Agent(
name="Researcher",
model=OpenAIChat(id="gpt-4o"),
tools=[WebSearchTools()],
)
writer_agent = Agent(
name="Writer",
model=OpenAIChat(id="gpt-4o"),
)
team = Team(
members=[web_agent, writer_agent],
model=OpenAIChat(id="gpt-4o"),
instructions="Research and write articles",
)
```
Workflow Pattern:
```python
from agno.workflow.workflow import Workflow
from agno.db.sqlite import SqliteDb
# Define agents first (researcher, writer)
async def blog_workflow(session_state, topic: str):
# Step 1: Research
research = await researcher.arun(topic)
# Step 2: Write
article = await writer.arun(research.content)
return article
workflow = Workflow(
name="Blog Generator",
steps=blog_workflow,
db=SqliteDb(db_file="tmp/workflow.db"),
)
```
Knowledge/RAG:
```python
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.lancedb import LanceDb, SearchType
from agno.knowledge.embedder.openai import OpenAIEmbedder
knowledge = Knowledge(
vector_db=LanceDb(
uri="tmp/lancedb",
table_name="knowledge_base",
search_type=SearchType.hybrid,
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
),
)
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
knowledge=knowledge,
search_knowledge=True, # Critical: enables agentic RAG
instructions="Use knowledge base, cite sources"
)
```
Chat History:
```python
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
db=SqliteDb(db_file="tmp/agents.db"),
user_id="user-123",
add_history_to_context=True, # Adds previous messages
num_history_runs=3,
)
```
Structured Output:
```python
from pydantic import BaseModel
class Result(BaseModel):
summary: str
findings: list[str]
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
output_schema=Result,
)
result: Result = agent.run(query).content
```
AgentOS Production:
```python
from agno.os import AgentOS
from agno.db.postgres import PostgresDb
agent_os = AgentOS(
agents=[agent],
db=PostgresDb(db_url=os.getenv("DATABASE_URL")),
)
app = agent_os.get_app()
```
Common Mistakes
- Creating agents in loops (massive performance hit)
- Using Team when single agent would work
- Forgetting search_knowledge=True with knowledge
- Using SQLite in production
- Not adding history when context matters
- Missing output_schema validation
Production
- Use PostgresDb not SqliteDb
- Set show_tool_calls=False, debug_mode=False
- Wrap agent.run() in try-except
Docs: https://docs.agno.com