Ark4u commited on
Commit
10cfbc7
·
verified ·
1 Parent(s): 523f2d1

Deploy OmniAssistant smolagent (Hugging Face Agents Course Unit 1)

Browse files
Files changed (2) hide show
  1. Gradio_UI.py +0 -1
  2. app.py +36 -14
Gradio_UI.py CHANGED
@@ -285,7 +285,6 @@ class GradioUI:
285
  ),
286
  resizable=True,
287
  scale=1,
288
- type="messages",
289
  )
290
  # If an upload folder is provided, enable the upload feature
291
  if self.file_upload_folder is not None:
 
285
  ),
286
  resizable=True,
287
  scale=1,
 
288
  )
289
  # If an upload folder is provided, enable the upload feature
290
  if self.file_upload_folder is not None:
app.py CHANGED
@@ -126,27 +126,49 @@ prompts_file = os.path.join(os.path.dirname(__file__), "prompts.yaml")
126
  with open(prompts_file, "r") as stream:
127
  prompt_templates = yaml.safe_load(stream)
128
 
129
- # Aggregate tools list
130
- agent_tools = [
131
- final_answer,
132
- web_search,
133
- get_current_time_in_timezone,
134
- get_weather,
135
- search_wikipedia,
136
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  if image_generation_tool is not None:
138
- agent_tools.append(image_generation_tool)
139
 
140
- agent = CodeAgent(
141
  model=model,
142
- tools=agent_tools,
143
- max_steps=6,
 
144
  verbosity_level=1,
145
  planning_interval=None,
146
- name="OmniAssistant",
147
- description="A multi-functional assistant capable of web search, live weather, Wikipedia summaries, timezone calculations, and image generation.",
148
  prompt_templates=prompt_templates
149
  )
150
 
 
 
 
151
  if __name__ == "__main__":
152
  GradioUI(agent).launch()
 
126
  with open(prompts_file, "r") as stream:
127
  prompt_templates = yaml.safe_load(stream)
128
 
129
+ # --- Specialist Agents (Unit 2: Hierarchical Multi-Agent System) ---
130
+
131
+ # Specialist 1: Web & Wikipedia Researcher
132
+ research_agent = CodeAgent(
133
+ model=model,
134
+ tools=[web_search, search_wikipedia],
135
+ max_steps=4,
136
+ verbosity_level=1,
137
+ name="web_researcher",
138
+ description="A specialist researcher that searches DuckDuckGo and queries Wikipedia to gather accurate facts and summaries.",
139
+ prompt_templates=prompt_templates
140
+ )
141
+
142
+ # Specialist 2: Weather & Timezone Specialist
143
+ local_info_agent = CodeAgent(
144
+ model=model,
145
+ tools=[get_current_time_in_timezone, get_weather],
146
+ max_steps=4,
147
+ verbosity_level=1,
148
+ name="local_info_specialist",
149
+ description="A specialist agent that fetches real-time live weather reports and calculates current time in timezones worldwide.",
150
+ prompt_templates=prompt_templates
151
+ )
152
+
153
+ # Manager Agent: Coordinates specialists and synthesizes the final response
154
+ manager_tools = [final_answer]
155
  if image_generation_tool is not None:
156
+ manager_tools.append(image_generation_tool)
157
 
158
+ manager_agent = CodeAgent(
159
  model=model,
160
+ tools=manager_tools,
161
+ managed_agents=[research_agent, local_info_agent],
162
+ max_steps=8,
163
  verbosity_level=1,
164
  planning_interval=None,
165
+ name="OmniAssistant_Manager",
166
+ description="A senior manager agent that breaks down user tasks and delegates them to specialized team members (web researcher and local info specialist).",
167
  prompt_templates=prompt_templates
168
  )
169
 
170
+ # Main agent interface for Gradio
171
+ agent = manager_agent
172
+
173
  if __name__ == "__main__":
174
  GradioUI(agent).launch()