Sakeeb commited on
Commit
a48f2de
·
verified ·
1 Parent(s): 68e0b40

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +104 -34
app.py CHANGED
@@ -55,14 +55,16 @@ print("✅ Simple Agent initialized")
55
  # MULTI-AGENT SYSTEMS (Day 1B)
56
  # ============================================================================
57
 
58
- # 1. Research & Summarization System (LLM-based orchestration)
59
  def build_research_system():
60
  research_agent = Agent(
61
  name="ResearchAgent",
62
  model="gemini-2.5-flash-lite",
63
- instruction="""You are a specialized research agent. Your only job is to use the
64
- google_search tool to find 2-3 pieces of relevant information on the given topic
65
- and present the findings with citations.""",
 
 
66
  tools=[google_search],
67
  output_key="research_findings",
68
  )
@@ -70,22 +72,26 @@ def build_research_system():
70
  summarizer_agent = Agent(
71
  name="SummarizerAgent",
72
  model="gemini-2.5-flash-lite",
73
- instruction="""Read the provided research findings: {research_findings}
74
- Create a concise summary as a bulleted list with 3-5 key points.""",
 
 
 
 
 
 
 
 
 
 
 
75
  output_key="final_summary",
76
  )
77
 
78
- root_agent = Agent(
79
- name="ResearchCoordinator",
80
- model="gemini-2.5-flash-lite",
81
- instruction="""You are a research coordinator. Your goal is to answer the user's query by orchestrating a workflow.
82
- 1. First, you MUST call the `ResearchAgent` tool to find relevant information.
83
- 2. Next, after receiving the research findings, you MUST call the `SummarizerAgent` tool to create a concise summary.
84
- 3. Finally, present the final summary clearly to the user as your response.""",
85
- tools=[
86
- AgentTool(research_agent),
87
- AgentTool(summarizer_agent)
88
- ],
89
  )
90
 
91
  return root_agent
@@ -117,7 +123,8 @@ def build_blog_pipeline():
117
  model="gemini-2.5-flash-lite",
118
  instruction="""Edit this draft: {blog_draft}
119
  Your task is to polish the text by fixing any grammatical errors,
120
- improving the flow and sentence structure, and enhancing overall clarity.""",
 
121
  output_key="final_blog",
122
  )
123
 
@@ -257,9 +264,78 @@ def blog_chat(topic):
257
 
258
 
259
  def parallel_chat(briefing_type):
260
- """Parallel Research demo"""
261
- query = f"Run the daily executive briefing on {briefing_type}"
262
- return run_agent_query(parallel_runner, query)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
 
265
  # ============================================================================
@@ -374,10 +450,10 @@ with gr.Blocks(
374
  with gr.Tab("🔍 Research System"):
375
  gr.Markdown("""
376
  ### Research & Summarization System (Day 1B)
377
- Multi-agent system with **LLM-based orchestration**:
378
- 1. **Research Agent** searches the web for information
379
- 2. **Summarizer Agent** creates a concise summary
380
- 3. **Coordinator Agent** orchestrates the workflow
381
  """)
382
 
383
  research_topic = gr.Textbox(
@@ -387,10 +463,8 @@ with gr.Blocks(
387
 
388
  research_btn = gr.Button("🔬 Research & Summarize", variant="primary")
389
 
390
- research_output = gr.Textbox(
391
  label="Summary",
392
- lines=15,
393
- show_copy_button=True,
394
  )
395
 
396
  gr.Examples(
@@ -421,10 +495,8 @@ with gr.Blocks(
421
 
422
  blog_btn = gr.Button("📝 Generate Blog Post", variant="primary")
423
 
424
- blog_output = gr.Textbox(
425
  label="Blog Post",
426
- lines=20,
427
- show_copy_button=True,
428
  )
429
 
430
  gr.Examples(
@@ -460,10 +532,8 @@ with gr.Blocks(
460
 
461
  parallel_btn = gr.Button("📈 Generate Executive Briefing", variant="primary")
462
 
463
- parallel_output = gr.Textbox(
464
  label="Executive Summary",
465
- lines=20,
466
- show_copy_button=True,
467
  )
468
 
469
  parallel_btn.click(parallel_chat, inputs=briefing_type, outputs=parallel_output)
 
55
  # MULTI-AGENT SYSTEMS (Day 1B)
56
  # ============================================================================
57
 
58
+ # 1. Research & Summarization System (Sequential workflow)
59
  def build_research_system():
60
  research_agent = Agent(
61
  name="ResearchAgent",
62
  model="gemini-2.5-flash-lite",
63
+ instruction="""You are a specialized research agent.
64
+ Research the given topic thoroughly using google_search.
65
+ Find 3-5 pieces of relevant, current information.
66
+ Present your findings in a clear, structured format with sources.
67
+ Include key facts, statistics, and developments.""",
68
  tools=[google_search],
69
  output_key="research_findings",
70
  )
 
72
  summarizer_agent = Agent(
73
  name="SummarizerAgent",
74
  model="gemini-2.5-flash-lite",
75
+ instruction="""Read the research findings provided below and create a concise executive summary.
76
+
77
+ Research Findings:
78
+ {research_findings}
79
+
80
+ Create a well-formatted markdown summary with:
81
+ - A header (## Research Summary)
82
+ - 4-6 bullet points highlighting the most important findings
83
+ - Use **bold** for key terms and findings
84
+ - Include specific details like numbers, dates, or names when available
85
+ - Keep it concise but informative (150-200 words)
86
+
87
+ Format your output in proper markdown.""",
88
  output_key="final_summary",
89
  )
90
 
91
+ # Use Sequential workflow instead of LLM orchestration for reliability
92
+ root_agent = SequentialAgent(
93
+ name="ResearchPipeline",
94
+ sub_agents=[research_agent, summarizer_agent],
 
 
 
 
 
 
 
95
  )
96
 
97
  return root_agent
 
123
  model="gemini-2.5-flash-lite",
124
  instruction="""Edit this draft: {blog_draft}
125
  Your task is to polish the text by fixing any grammatical errors,
126
+ improving the flow and sentence structure, and enhancing overall clarity.
127
+ Output the final blog post in proper markdown format with headers (##), bold (**), and other formatting.""",
128
  output_key="final_blog",
129
  )
130
 
 
264
 
265
 
266
  def parallel_chat(briefing_type):
267
+ """Parallel Research demo - dynamically build agents based on topics"""
268
+ if not briefing_type or not briefing_type.strip():
269
+ return "Please select briefing topics."
270
+
271
+ # Parse the topics
272
+ topics = [t.strip() for t in briefing_type.split(",")]
273
+
274
+ if len(topics) != 3:
275
+ return f"Please provide exactly 3 topics separated by commas. Got {len(topics)} topics."
276
+
277
+ # Build dynamic parallel research system
278
+ agent1 = Agent(
279
+ name=f"{topics[0]}Researcher",
280
+ model="gemini-2.5-flash-lite",
281
+ instruction=f"""Research the latest trends in {topics[0]}. Include 3 key developments,
282
+ the main companies/organizations involved, and the potential impact. Keep the report concise (100-150 words).""",
283
+ tools=[google_search],
284
+ output_key=f"research_1",
285
+ )
286
+
287
+ agent2 = Agent(
288
+ name=f"{topics[1]}Researcher",
289
+ model="gemini-2.5-flash-lite",
290
+ instruction=f"""Research recent developments in {topics[1]}. Include 3 significant advances,
291
+ their practical applications, and estimated timelines. Keep the report concise (100-150 words).""",
292
+ tools=[google_search],
293
+ output_key=f"research_2",
294
+ )
295
+
296
+ agent3 = Agent(
297
+ name=f"{topics[2]}Researcher",
298
+ model="gemini-2.5-flash-lite",
299
+ instruction=f"""Research current trends in {topics[2]}. Include 3 key trends,
300
+ their market implications, and the future outlook. Keep the report concise (100-150 words).""",
301
+ tools=[google_search],
302
+ output_key=f"research_3",
303
+ )
304
+
305
+ aggregator = Agent(
306
+ name="AggregatorAgent",
307
+ model="gemini-2.5-flash-lite",
308
+ instruction=f"""Combine these three research findings into a single executive summary:
309
+
310
+ **{topics[0]} Trends:**
311
+ {{research_1}}
312
+
313
+ **{topics[1]} Developments:**
314
+ {{research_2}}
315
+
316
+ **{topics[2]} Innovations:**
317
+ {{research_3}}
318
+
319
+ Your summary should highlight common themes, surprising connections, and the most important
320
+ key takeaways from all three reports. Format your output in clear markdown with headers and bullet points.
321
+ The final summary should be around 250-300 words.""",
322
+ output_key="executive_summary",
323
+ )
324
+
325
+ parallel_team = ParallelAgent(
326
+ name="DynamicResearchTeam",
327
+ sub_agents=[agent1, agent2, agent3],
328
+ )
329
+
330
+ dynamic_system = SequentialAgent(
331
+ name="DynamicResearchSystem",
332
+ sub_agents=[parallel_team, aggregator],
333
+ )
334
+
335
+ dynamic_runner = InMemoryRunner(agent=dynamic_system)
336
+
337
+ query = f"Generate an executive briefing on {briefing_type}"
338
+ return run_agent_query(dynamic_runner, query)
339
 
340
 
341
  # ============================================================================
 
450
  with gr.Tab("🔍 Research System"):
451
  gr.Markdown("""
452
  ### Research & Summarization System (Day 1B)
453
+ Multi-agent system with **Sequential workflow**:
454
+ 1. **Research Agent** searches the web for current information
455
+ 2. **Summarizer Agent** creates a concise markdown summary
456
+ 3. Agents execute in guaranteed order for reliable results
457
  """)
458
 
459
  research_topic = gr.Textbox(
 
463
 
464
  research_btn = gr.Button("🔬 Research & Summarize", variant="primary")
465
 
466
+ research_output = gr.Markdown(
467
  label="Summary",
 
 
468
  )
469
 
470
  gr.Examples(
 
495
 
496
  blog_btn = gr.Button("📝 Generate Blog Post", variant="primary")
497
 
498
+ blog_output = gr.Markdown(
499
  label="Blog Post",
 
 
500
  )
501
 
502
  gr.Examples(
 
532
 
533
  parallel_btn = gr.Button("📈 Generate Executive Briefing", variant="primary")
534
 
535
+ parallel_output = gr.Markdown(
536
  label="Executive Summary",
 
 
537
  )
538
 
539
  parallel_btn.click(parallel_chat, inputs=briefing_type, outputs=parallel_output)