Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,9 @@ from bs4 import BeautifulSoup
|
|
| 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,7 +138,7 @@ class BasicAgent:
|
|
| 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,25 +177,17 @@ When you've found the answer, stop reasoning and return ONLY the answer.
|
|
| 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 |
async for update in Runner.run_streamed(my_agent, input=question, max_turns=25):
|
| 195 |
-
if update.new_items:
|
| 196 |
for step in update.new_items:
|
| 197 |
print("🧠 Thought:", step.thought)
|
| 198 |
print("⚙️ Action:", step.tool_call)
|
|
@@ -200,23 +195,12 @@ When you've found the answer, stop reasoning and return ONLY the answer.
|
|
| 200 |
print("-" * 50)
|
| 201 |
print(f"Agent gave answer (first 50 chars): {update.final_output[:50]}...")
|
| 202 |
return update.final_output
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
# result = Runner.run_sync(
|
| 207 |
-
# my_agent,
|
| 208 |
-
# input=question,
|
| 209 |
-
# max_turns=25
|
| 210 |
-
# )
|
| 211 |
-
# print("\n--- Intermediate Reasoning ---")
|
| 212 |
-
# for step in result.steps:
|
| 213 |
-
# print("🧠 Thought:", step.thought)
|
| 214 |
-
# print("⚙️ Action:", step.tool_call)
|
| 215 |
-
# print("🔍 Observation:", step.observation)
|
| 216 |
-
# print("-" * 50)
|
| 217 |
-
|
| 218 |
-
# print(f"Agent returning fixed answer(first 50 chars): {result.final_output[:50]}...")
|
| 219 |
-
# return result.final_output
|
| 220 |
|
| 221 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 222 |
"""
|
|
|
|
| 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 |
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 |
- 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)
|
| 193 |
print("⚙️ Action:", step.tool_call)
|
|
|
|
| 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 |
"""
|