Skip to content

Commit 234ec2c

Browse files
gather tasks results
1 parent ecf3508 commit 234ec2c

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

examples/agents/todo_example.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ class PlanningPrompt(Prompt[HikingPlanInput]):
4343
Complete this specific planning task with detailed, actionable recommendations.
4444
"""
4545

46+
class SummaryInput(BaseModel):
47+
"""Input for summary generation with task results."""
48+
49+
location: str
50+
duration_days: int
51+
group_size: int
52+
skill_level: str
53+
season: str
54+
preferences: str
55+
task_results: str # Compiled task results
56+
4657

4758
class TaskGenerationPrompt(Prompt[HikingPlanInput]):
4859
"""Prompt for AI to generate planning tasks."""
@@ -70,7 +81,7 @@ class TaskGenerationPrompt(Prompt[HikingPlanInput]):
7081
"""
7182

7283

73-
class SummaryPrompt(Prompt[HikingPlanInput]):
84+
class SummaryPrompt(Prompt[SummaryInput]):
7485
"""Prompt for creating final comprehensive summary."""
7586

7687
system_prompt = """
@@ -82,22 +93,18 @@ class SummaryPrompt(Prompt[HikingPlanInput]):
8293
"""
8394

8495
user_prompt = """
85-
Create a comprehensive hiking trip plan for:
96+
Create a comprehensive hiking trip plan based on the completed research:
97+
98+
TRIP DETAILS:
8699
- {{ duration_days }}-day trip in {{ location }}
87100
- {{ group_size }} {{ skill_level }} hikers
88101
- Season: {{ season }}
89102
- Preferences: {{ preferences }}
90103
91-
Provide a complete plan including:
92-
• Trail routes and difficulty assessments
93-
• Accommodation recommendations near trailheads
94-
• Detailed budget breakdown with costs
95-
• Weather analysis and gear recommendations
96-
• Daily schedule with sunrise/sunset times
97-
• Post-hike activities and relaxation options
98-
• Safety protocols and emergency contacts
104+
COMPLETED RESEARCH:
105+
{{ task_results }}
99106
100-
Make this a step-by-step plan someone could follow immediately.
107+
Based on this research, provide a complete plan...
101108
"""
102109

103110

@@ -229,14 +236,19 @@ async def smart_hiking_planner() -> None:
229236
print("\n🚀 Processing tasks under the hood...")
230237
await asyncio.sleep(1)
231238

232-
# Process all tasks under the hood (user sees progress, not details)
239+
# Process all tasks and capture results
240+
task_results = []
233241
for task in planning_agent.tasks:
234242
# Show current progress
235243
planning_agent.mark_task(task.id, "in-progress")
236244
display_task_list(planning_agent, f"Processing: {task.description[:40]}...")
237245

238-
# Process task with AI (under the hood)
239-
await planning_agent.run(trip_input)
246+
# Process task with AI and CAPTURE results
247+
task_result = await planning_agent.run(trip_input)
248+
task_results.append({
249+
"task": task.description,
250+
"result": task_result.content if hasattr(task_result, 'content') else str(task_result)
251+
})
240252

241253
# Mark as completed
242254
planning_agent.mark_task(task.id, "done")
@@ -246,12 +258,29 @@ async def smart_hiking_planner() -> None:
246258
display_task_list(planning_agent, "All Planning Tasks Completed!")
247259
await asyncio.sleep(2)
248260

261+
# Compile task results
262+
compiled_results = "\n\n".join([
263+
f"TASK: {result['task']}\nRESULT: {result['result']}"
264+
for result in task_results
265+
])
266+
267+
# Create summary input with all task results
268+
summary_input = SummaryInput(
269+
location=trip_input.location,
270+
duration_days=trip_input.duration_days,
271+
group_size=trip_input.group_size,
272+
skill_level=trip_input.skill_level,
273+
season=trip_input.season,
274+
preferences=trip_input.preferences,
275+
task_results=compiled_results
276+
)
277+
249278
# Generate and stream comprehensive summary
250279
print("\n🎯 Generating comprehensive trip plan...")
251280
print("🤖 AI compiling all research into actionable plan...")
252281
await asyncio.sleep(2)
253282

254-
# Create summary agent with all gathered information
283+
# Summary agent now has access to all task research!
255284
summary_agent = TodoAgent(llm=llm, prompt=SummaryPrompt)
256285

257286
# Clear screen for final summary
@@ -262,7 +291,7 @@ async def smart_hiking_planner() -> None:
262291
print()
263292

264293
# Stream the comprehensive summary
265-
streaming_result = summary_agent.run_streaming(trip_input)
294+
streaming_result = summary_agent.run_streaming(summary_input)
266295

267296
async for chunk in streaming_result:
268297
if isinstance(chunk, str):

0 commit comments

Comments
 (0)