huytofu92 commited on
Commit
58c2c51
·
1 Parent(s): 59377f3

modify async run

Browse files
Files changed (1) hide show
  1. mini_agents.py +8 -7
mini_agents.py CHANGED
@@ -169,15 +169,15 @@ class MasterAgentWrapper:
169
  description="This agent is responsible for managing audio, vlm, arithmetic and pandas agents."
170
  )
171
 
172
- async def _run_with_browser_tools(self, question: str, browser_tools: List[Tool]) -> str:
173
- """Async method to run agent with browser tools"""
174
  # Temporarily add browser tools
175
  original_tools = self.master_agent.tools
176
  self.master_agent.tools = original_tools + browser_tools
177
 
178
  try:
179
- # Run the agent using async run
180
- result = await self.master_agent.arun(question)
181
  return result
182
  finally:
183
  # Restore original tools
@@ -188,15 +188,16 @@ class MasterAgentWrapper:
188
  try:
189
  # Get browser tools in the correct context
190
  with browser_manager.get_browser_tools() as browser_tools:
191
- # Get or create event loop
192
  try:
193
  loop = anyio.get_current_loop()
194
  except RuntimeError:
195
  loop = anyio.new_event_loop()
196
  anyio.set_event_loop(loop)
197
 
198
- # Run with browser tools in async context
199
- return loop.run_until_complete(self._run_with_browser_tools(question, browser_tools))
 
200
 
201
  except Exception as e:
202
  logging.error(f"Error in master agent run: {e}")
 
169
  description="This agent is responsible for managing audio, vlm, arithmetic and pandas agents."
170
  )
171
 
172
+ def _run_with_browser_tools(self, question: str, browser_tools: List[Tool]) -> str:
173
+ """Run agent with browser tools in the current event loop"""
174
  # Temporarily add browser tools
175
  original_tools = self.master_agent.tools
176
  self.master_agent.tools = original_tools + browser_tools
177
 
178
  try:
179
+ # Run the agent using sync run
180
+ result = self.master_agent.run(question)
181
  return result
182
  finally:
183
  # Restore original tools
 
188
  try:
189
  # Get browser tools in the correct context
190
  with browser_manager.get_browser_tools() as browser_tools:
191
+ # Get or create event loop for browser tools
192
  try:
193
  loop = anyio.get_current_loop()
194
  except RuntimeError:
195
  loop = anyio.new_event_loop()
196
  anyio.set_event_loop(loop)
197
 
198
+ # Run with browser tools
199
+ # The browser tools will handle their own async operations
200
+ return self._run_with_browser_tools(question, browser_tools)
201
 
202
  except Exception as e:
203
  logging.error(f"Error in master agent run: {e}")