patricksamuel commited on
Commit
700858a
·
verified ·
1 Parent(s): 6315e04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -12
app.py CHANGED
@@ -14,9 +14,6 @@ from bs4 import BeautifulSoup
14
  from pydantic import BaseModel, Field
15
  import nest_asyncio
16
  import requests
17
- import asyncio
18
- from tavily import TavilyClient
19
-
20
 
21
  #from agents.extensions.models.litellm_model import LitellmModel
22
 
@@ -138,7 +135,7 @@ class BasicAgent:
138
  print("BasicAgent initialized.")
139
  def __call__(self, question: str) -> str:
140
  print(f"Agent received question (first 50 chars): {question[:50]}...")
141
-
142
  instructions = """
143
  You are a ReAct (Reason-Act-Observe) agent that searches the internet to find accurate answers to questions.
144
  ## Available Tools
@@ -177,16 +174,25 @@ When you've found the answer, stop reasoning and return ONLY the answer.
177
  - Just the answer text — for example: `California`
178
 
179
  """
180
-
181
  my_agent = Agent(
182
  name="Expert Question Answering Agent",
183
  instructions=instructions,
184
- tools = [tavily_search, visit_website],
 
 
 
185
  model="gpt-4o-mini"
186
  )
187
-
 
 
 
 
 
188
  async def run_agent_streamed():
189
- async for update in Runner.run_streamed(my_agent, input=question, max_turns=25):
 
190
  if hasattr(update, "new_items") and update.new_items:
191
  for step in update.new_items:
192
  print("🧠 Thought:", step.thought)
@@ -195,13 +201,24 @@ When you've found the answer, stop reasoning and return ONLY the answer.
195
  print("-" * 50)
196
  print(f"Agent gave answer (first 50 chars): {update.final_output[:50]}...")
197
  return update.final_output
198
-
199
- result = asyncio.run(run_agent_streamed())
200
- return result
201
-
202
 
203
 
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  def run_and_submit_all( profile: gr.OAuthProfile | None):
206
  """
207
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
14
  from pydantic import BaseModel, Field
15
  import nest_asyncio
16
  import requests
 
 
 
17
 
18
  #from agents.extensions.models.litellm_model import LitellmModel
19
 
 
135
  print("BasicAgent initialized.")
136
  def __call__(self, question: str) -> str:
137
  print(f"Agent received question (first 50 chars): {question[:50]}...")
138
+
139
  instructions = """
140
  You are a ReAct (Reason-Act-Observe) agent that searches the internet to find accurate answers to questions.
141
  ## Available Tools
 
174
  - Just the answer text — for example: `California`
175
 
176
  """
177
+
178
  my_agent = Agent(
179
  name="Expert Question Answering Agent",
180
  instructions=instructions,
181
+ tools = [
182
+ web_search,
183
+ visit_website
184
+ ],
185
  model="gpt-4o-mini"
186
  )
187
+
188
+ import nest_asyncio
189
+ import asyncio
190
+
191
+ nest_asyncio.apply()
192
+
193
  async def run_agent_streamed():
194
+ stream = Runner.run_streamed(my_agent, input=question, max_turns=25)
195
+ for update in stream.iter_steps():
196
  if hasattr(update, "new_items") and update.new_items:
197
  for step in update.new_items:
198
  print("🧠 Thought:", step.thought)
 
201
  print("-" * 50)
202
  print(f"Agent gave answer (first 50 chars): {update.final_output[:50]}...")
203
  return update.final_output
 
 
 
 
204
 
205
 
206
 
207
+ # result = Runner.run_sync(
208
+ # my_agent,
209
+ # input=question,
210
+ # max_turns=25
211
+ # )
212
+ # print("\n--- Intermediate Reasoning ---")
213
+ # for step in result.steps:
214
+ # print("🧠 Thought:", step.thought)
215
+ # print("⚙️ Action:", step.tool_call)
216
+ # print("🔍 Observation:", step.observation)
217
+ # print("-" * 50)
218
+
219
+ # print(f"Agent returning fixed answer(first 50 chars): {result.final_output[:50]}...")
220
+ # return result.final_output
221
+
222
  def run_and_submit_all( profile: gr.OAuthProfile | None):
223
  """
224
  Fetches all questions, runs the BasicAgent on them, submits all answers,