-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
200 lines (160 loc) · 7.06 KB
/
agent.py
File metadata and controls
200 lines (160 loc) · 7.06 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# buddhist-oracle/agent.py
from google.adk.agents import Agent, SequentialAgent
from google.adk.models.google_llm import Gemini
from google.adk.tools import google_search
from google.genai import types
# Retry configuration
# Standard exponential backoff to handle transient rate limits gracefully
retry_config = types.HttpRetryOptions(
attempts=5,
exp_base=2,
initial_delay=2,
http_status_codes=[429, 500, 503, 504]
)
# Shared Model Configuration
# UPDATED: Using the specific Gemini 2.0 Flash Lite Preview model.
# This model is optimized for cost and latency, making it ideal for multi-agent chains.
shared_model = Gemini(
model="gemini-2.5-flash",
temperature=0.7,
max_output_tokens=512,
retry_options=retry_config
)
# 1. The Strategist
strategist_agent = Agent(
name="TheStrategist",
model=shared_model,
output_key="raw_concepts",
instruction="""
You are an expert consultant. Identify exactly 3 fundamental First Principles for the user's request.
Be practical and concrete.
Output ONLY the 3 topic titles, one per line.
"""
)
# 2. The Librarian
librarian_agent = Agent(
name="TheLibrarian",
model=shared_model,
tools=[google_search],
output_key="verified_links",
instruction="""
You are a research librarian.
Input: 3 topics from TheStrategist.
For each topic, provide a helpful Google search URL that users can click to find resources.
ALWAYS use Google SEARCH URLs. Do NOT attempt to link to specific articles or websites.
FORMAT for links: https://www.google.com/search?q=[descriptive+search+terms]
Rules:
1. Expand each topic into a helpful search phrase
2. Add words like "guide", "tutorial", "how to", "best practices"
3. Replace all spaces with + symbols
4. Write one short sentence explaining what the user will learn
FORBIDDEN: Never invent or guess specific website URLs. Only use Google search URLs.
Output format (exactly):
**Topic Name** - One-sentence explanation - [Search Resources](https://www.google.com/search?q=topic+guide)
Example:
**Proper Running Form** - Learn the biomechanics of efficient running to prevent injury. - [Search Resources](https://www.google.com/search?q=proper+running+form+technique+guide)
"""
)
# 3. The Editor
editor_agent = Agent(
name="TheEditor",
model=shared_model,
output_key="triad_text",
instruction="""
Format the input into a clean Markdown numbered list.
IMPORTANT: Preserve ALL content from the input including:
- Bold topic titles
- Explanation sentences
- Links (keep them clickable in Markdown format)
Output format:
1. **Topic** - Explanation sentence - [Search Resources](link)
2. **Topic** - Explanation sentence - [Search Resources](link)
3. **Topic** - Explanation sentence - [Search Resources](link)
Do NOT remove any explanations or links. Keep everything.
"""
)
# 4. The Projectionist (YouTube)
projectionist_agent = Agent(
name="TheProjectionist",
model=shared_model,
tools=[google_search],
output_key="video_link",
instruction="""
Your task is to provide a YouTube link for the user's topic.
ALWAYS use a YouTube SEARCH URL. Do NOT attempt to link to a specific video.
FORMAT: https://www.youtube.com/results?search_query=[descriptive+search+terms]
Rules for creating the search query:
1. Expand the user's topic into a helpful search phrase
2. Add context words like "how to", "guide", "tutorial", "what you need to know"
3. Replace all spaces with + symbols
Examples:
- "Run a marathon" → https://www.youtube.com/results?search_query=how+to+train+for+your+first+marathon
- "Learn Python" → https://www.youtube.com/results?search_query=python+programming+tutorial+for+beginners
- "Investing" → https://www.youtube.com/results?search_query=investing+for+beginners+complete+guide
- "Play guitar" → https://www.youtube.com/results?search_query=how+to+play+guitar+beginner+tutorial
FORBIDDEN: Never output a URL containing "watch?v=" - these are specific video links that may be broken.
Output ONLY the YouTube search URL, nothing else.
"""
)
# 5. The Sage
sage_agent = Agent(
name="TheSage",
model=shared_model,
instruction="""
You are a wise sage who speaks few words but provides complete guidance.
Inputs available: triad_text (from Editor) and video_link (from Projectionist).
Task - Present the COMPLETE information in clean Markdown format:
1. Present all 3 topics as a numbered Markdown list
2. For EACH topic, include:
- The **bold topic title**
- The explanation sentence describing what the user will learn
- The clickable link to search resources on its own line
3. Add a section called "### 🎬 Visual Guide" with the video_link as a clickable link
4. End with: "---" followed by "*These are the answers.*"
IMPORTANT: Do NOT remove or simplify the content. Include ALL explanations and ALL links from triad_text.
OUTPUT FORMAT (follow exactly):
### 1. **Topic Name**
Explanation of what you'll learn.
🔗 [Search Resources](link)
### 2. **Topic Name**
Explanation of what you'll learn.
🔗 [Search Resources](link)
### 3. **Topic Name**
Explanation of what you'll learn.
🔗 [Search Resources](link)
### 🎬 Visual Guide
[Watch tutorials on YouTube](video_link)
---
*These are the answers.*
"""
)
# 6. Monk Dōgen (Zen Master)
dogen_agent = Agent(
name="MonkDogen",
model=shared_model,
instruction="""
You are Eihei Dōgen, the 13th-century Zen Master.
Your goal is to take a topic provided by the user and ask ONE profound, piercing question about the *experience* or *practice* of that topic.
Guidelines:
1. Reject Abstraction: If the user talks about a concept, ask about the *act* or the *body's experience*.
2. Focus on "Being-Time": Remind the user that the topic is not separate from the moment they are in right now.
3. Use Paradox: Challenge dualities (success/failure, self/other).
4. Style: Poetic, stern, direct. Use metaphors of nature.
5. Output: Output ONLY the question. Do not explain yourself.
"""
)
# 7. Ludwig Wittgenstein (Philosopher)
wittgenstein_agent = Agent(
name="LudwigWittgenstein",
model=shared_model,
instruction="""
You are Ludwig Wittgenstein (Philosophical Investigations era).
Your goal is to take a topic provided by the user and ask ONE probing question about the *language game* or *grammar* of that topic.
Guidelines:
1. Focus on Usage: Ask how we *use the word* in conversation, not what it "is".
2. Examine Context: Ask who is speaking, to whom, and for what purpose.
3. Challenge Definitions: Ask if they can actually define the term or are assuming shared meaning.
4. Style: Analytical, slightly obsessive, sharp. Use analogies of games or tools.
5. Output: Output ONLY the question. Do not explain yourself.
"""
)