patricksamuel commited on
Commit
143a3a8
·
verified ·
1 Parent(s): bfcf281

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -4
app.py CHANGED
@@ -19,6 +19,7 @@ from agents.extensions.models.litellm_model import LitellmModel
19
 
20
  #os.getenv("OPENAI_API_KEY")
21
  os.getenv("GEMINI_API_KEY")
 
22
 
23
 
24
  # add this
@@ -27,6 +28,29 @@ nest_asyncio.apply()
27
 
28
  #Tools
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  @function_tool
31
  def web_search(query: str) -> str:
32
  """
@@ -115,7 +139,7 @@ class BasicAgent:
115
  instructions = """
116
  You are a ReAct (Reason-Act-Observe) agent that searches the internet to find accurate answers to questions.
117
  ## Available Tools
118
- - **web_search**: Search the web for information
119
  - **visit_website**: Visit specific webpages for detailed content
120
  ## Output Format Rules
121
  Your final answer must be **exactly one** of these formats:
@@ -155,7 +179,7 @@ When you've found the answer, stop reasoning and return ONLY the answer.
155
  name="Expert Question Answering Agent",
156
  instructions=instructions,
157
  tools = [
158
- web_search,
159
  visit_website
160
  ],
161
  model=LitellmModel(
@@ -170,8 +194,12 @@ When you've found the answer, stop reasoning and return ONLY the answer.
170
  input=question,
171
  max_turns=25
172
  )
173
-
174
-
 
 
 
 
175
 
176
  print(f"Agent returning fixed answer(first 50 chars): {result.final_output[:50]}...")
177
  return result.final_output
 
19
 
20
  #os.getenv("OPENAI_API_KEY")
21
  os.getenv("GEMINI_API_KEY")
22
+ os.getenv("TAVILY_API_KEY")
23
 
24
 
25
  # add this
 
28
 
29
  #Tools
30
 
31
+ @function_tool
32
+ def tavily_search(query: str) -> str:
33
+ """
34
+ Perform a Tavily web search.
35
+ Args:
36
+ query (str): The search query string.
37
+ Returns:
38
+ str: Formatted search results.
39
+ """
40
+ try:
41
+ client = TavilyClient()
42
+ results = client.search(query=query, max_results=5)
43
+
44
+ formatted = []
45
+ for result in results.get("results", []):
46
+ formatted.append(f"**Title**: {result['title']}\n**URL**: {result['url']}\n**Content**: {result['content']}\n")
47
+
48
+ return "\n\n".join(formatted) or "No results found."
49
+
50
+ except Exception as e:
51
+ return f"Error using Tavily Search: {e}"
52
+
53
+
54
  @function_tool
55
  def web_search(query: str) -> str:
56
  """
 
139
  instructions = """
140
  You are a ReAct (Reason-Act-Observe) agent that searches the internet to find accurate answers to questions.
141
  ## Available Tools
142
+ - **tavily_search**: Search the web for information
143
  - **visit_website**: Visit specific webpages for detailed content
144
  ## Output Format Rules
145
  Your final answer must be **exactly one** of these formats:
 
179
  name="Expert Question Answering Agent",
180
  instructions=instructions,
181
  tools = [
182
+ tavily_search,
183
  visit_website
184
  ],
185
  model=LitellmModel(
 
194
  input=question,
195
  max_turns=25
196
  )
197
+ print("\n--- Intermediate Reasoning ---")
198
+ for step in result.steps:
199
+ print("🧠 Thought:", step.thought)
200
+ print("⚙️ Action:", step.tool_call)
201
+ print("🔍 Observation:", step.observation)
202
+ print("-" * 50)
203
 
204
  print(f"Agent returning fixed answer(first 50 chars): {result.final_output[:50]}...")
205
  return result.final_output