fdaudens HF Staff commited on
Commit
d2b23ee
·
verified ·
1 Parent(s): 5dbccd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -22
app.py CHANGED
@@ -86,41 +86,71 @@ serper_tool = FunctionTool.from_defaults(
86
  )
87
 
88
  # --- Agents ---
 
89
  google_rss_agent = FunctionAgent(
90
- name="google_rss_agent", llm=oa_llm, memory=memory,
 
 
91
  tools=[google_rss_tool],
92
- system_prompt="Fetch the latest headlines from Google News RSS."
 
93
  )
94
- web_agent = ReActAgent(
95
- name="web_browsing_agent", llm=hf_llm, memory=memory,
96
- tools=[serper_tool, navigate_tool, extract_text],
 
 
97
  system_prompt=(
98
- "When asked for details on a headline, "
99
- "1) call fetch_news_from_serper(query); "
100
- "2) navigate to each URL; 3) extract_text(); "
101
- "4) summarize."
102
- )
 
 
 
103
  )
 
 
104
  weather_agent = ReActAgent(
105
- name="weather_agent", llm=oa_llm,
106
- tools=[weather_cur, weather_fc],
107
- system_prompt="You are a weather agent."
 
 
108
  )
 
 
109
  search_agent = ReActAgent(
110
- name="search_agent", llm=oa_llm,
 
 
111
  tools=[search_tool],
112
- system_prompt="You are a search agent using DuckDuckGo."
113
  )
114
- router = ReActAgent(
115
- name="router_agent", llm=hf_llm,
116
- tools=[FunctionTool.from_defaults(lambda ctx, choice: choice,
117
- name="choose_agent",
118
- description="Return agent name.")],
119
  system_prompt=(
120
- "Route the user query to exactly one of: "
 
121
  "['google_rss_agent','weather_agent','search_agent','web_browsing_agent']."
122
  ),
123
- can_handoff_to=["google_rss_agent","weather_agent","search_agent","web_browsing_agent"]
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  )
125
 
126
  workflow = AgentWorkflow(
 
86
  )
87
 
88
  # --- Agents ---
89
+ # 1. Google News RSS Agent (replaces old google_news_agent)
90
  google_rss_agent = FunctionAgent(
91
+ name="google_rss_agent",
92
+ description="Fetches latest headlines and URLs from Google News RSS feed.",
93
+ system_prompt="You are an agent that fetches the latest headlines and URLs from the Google News RSS feed.",
94
  tools=[google_rss_tool],
95
+ llm=openai_llm,
96
+ memory=memory,
97
  )
98
+
99
+ # 2. Web Browsing Agent
100
+ web_browsing_agent = ReActAgent(
101
+ name="web_browsing_agent",
102
+ description="Fetches Serper URLs, navigates to each link, extracts the text and builds a summary",
103
  system_prompt=(
104
+ "You are a news-content agent. When asked for details on a headline:\n"
105
+ "1. Call `fetch_news_from_serper(query)` to get JSON with article URLs.\n"
106
+ "2. For each top URL, call `web_navigate(url)` then `web_extract_text()`.\n"
107
+ "3. Synthesize those texts into a concise summary."
108
+ ),
109
+ tools=[serper_news_tool, navigate_tool, extract_text_tool, extract_links_tool],
110
+ llm=llm,
111
+ memory=memory,
112
  )
113
+
114
+ # 3. Weather Agent
115
  weather_agent = ReActAgent(
116
+ name="weather_agent",
117
+ description="Answers weather-related questions.",
118
+ system_prompt="You are a weather agent that provides current weather and forecasts.",
119
+ tools=[weather_tool, forecast_tool],
120
+ llm=openai_llm,
121
  )
122
+
123
+ # 4. DuckDuckGo Search Agent
124
  search_agent = ReActAgent(
125
+ name="search_agent",
126
+ description="Searches general info using DuckDuckGo.",
127
+ system_prompt="You are a search agent that uses DuckDuckGo to answer questions.",
128
  tools=[search_tool],
129
+ llm=openai_llm,
130
  )
131
+
132
+ router_agent = ReActAgent(
133
+ name="router_agent",
134
+ description="Routes queries to the correct specialist agent.",
 
135
  system_prompt=(
136
+ "You are RouterAgent. "
137
+ "Given the user query, reply with exactly one name from: "
138
  "['google_rss_agent','weather_agent','search_agent','web_browsing_agent']."
139
  ),
140
+ llm=llm,
141
+ tools=[
142
+ FunctionTool.from_defaults(
143
+ fn=lambda ctx, choice: choice,
144
+ name="choose_agent",
145
+ description="Return the chosen agent name."
146
+ )
147
+ ],
148
+ can_handoff_to=[
149
+ "google_rss_agent",
150
+ "weather_agent",
151
+ "search_agent",
152
+ "web_browsing_agent",
153
+ ],
154
  )
155
 
156
  workflow = AgentWorkflow(