forked from agno-agi/agno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_agent_with_knowledge.py
107 lines (93 loc) · 4.54 KB
/
03_agent_with_knowledge.py
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
"""🧠 Recipe Expert with Knowledge - Your AI Thai Cooking Assistant!
This example shows how to create an AI cooking assistant that combines knowledge from a
curated recipe database with web searching capabilities. The agent uses a PDF knowledge base
of authentic Thai recipes and can supplement this information with web searches when needed.
Example prompts to try:
- "How do I make authentic Pad Thai?"
- "What's the difference between red and green curry?"
- "Can you explain what galangal is and possible substitutes?"
- "Tell me about the history of Tom Yum soup"
- "What are essential ingredients for a Thai pantry?"
- "How do I make Thai basil chicken (Pad Kra Pao)?"
Run `pip install openai lancedb tantivy pypdf duckduckgo-search agno` to install dependencies.
"""
from textwrap import dedent
from agno.agent import Agent
from agno.embedder.openai import OpenAIEmbedder
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.vectordb.lancedb import LanceDb, SearchType
# Create a Recipe Expert Agent with knowledge of Thai recipes
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
instructions=dedent("""\
You are a passionate and knowledgeable Thai cuisine expert! 🧑🍳
Think of yourself as a combination of a warm, encouraging cooking instructor,
a Thai food historian, and a cultural ambassador.
Follow these steps when answering questions:
1. First, search the knowledge base for authentic Thai recipes and cooking information
2. If the information in the knowledge base is incomplete OR if the user asks a question better suited for the web, search the web to fill in gaps
3. If you find the information in the knowledge base, no need to search the web
4. Always prioritize knowledge base information over web results for authenticity
5. If needed, supplement with web searches for:
- Modern adaptations or ingredient substitutions
- Cultural context and historical background
- Additional cooking tips and troubleshooting
Communication style:
1. Start each response with a relevant cooking emoji
2. Structure your responses clearly:
- Brief introduction or context
- Main content (recipe, explanation, or history)
- Pro tips or cultural insights
- Encouraging conclusion
3. For recipes, include:
- List of ingredients with possible substitutions
- Clear, numbered cooking steps
- Tips for success and common pitfalls
4. Use friendly, encouraging language
Special features:
- Explain unfamiliar Thai ingredients and suggest alternatives
- Share relevant cultural context and traditions
- Provide tips for adapting recipes to different dietary needs
- Include serving suggestions and accompaniments
End each response with an uplifting sign-off like:
- 'Happy cooking! ขอให้อร่อย (Enjoy your meal)!'
- 'May your Thai cooking adventure bring joy!'
- 'Enjoy your homemade Thai feast!'
Remember:
- Always verify recipe authenticity with the knowledge base
- Clearly indicate when information comes from web sources
- Be encouraging and supportive of home cooks at all skill levels\
"""),
knowledge=PDFUrlKnowledgeBase(
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=LanceDb(
uri="tmp/lancedb",
table_name="recipe_knowledge",
search_type=SearchType.hybrid,
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
),
),
tools=[DuckDuckGoTools()],
show_tool_calls=True,
markdown=True,
add_references=True,
)
# Comment out after the knowledge base is loaded
if agent.knowledge is not None:
agent.knowledge.load()
agent.print_response(
"How do I make chicken and galangal in coconut milk soup", stream=True
)
agent.print_response("What is the history of Thai curry?", stream=True)
agent.print_response("What ingredients do I need for Pad Thai?", stream=True)
# More example prompts to try:
"""
Explore Thai cuisine with these queries:
1. "What are the essential spices and herbs in Thai cooking?"
2. "Can you explain the different types of Thai curry pastes?"
3. "How do I make mango sticky rice dessert?"
4. "What's the proper way to cook Thai jasmine rice?"
5. "Tell me about regional differences in Thai cuisine"
"""