huytofu92 commited on
Commit
ed00413
·
1 Parent(s): 58c2c51
Files changed (2) hide show
  1. browser.py +5 -6
  2. mini_agents.py +4 -4
browser.py CHANGED
@@ -1,12 +1,11 @@
1
  import subprocess
2
- import anyio
3
  from contextlib import contextmanager
4
  from typing import List, Optional
5
  from threading import Lock
6
  from smolagents.tools import Tool
7
  from langchain_community.tools.playwright.utils import (
8
  create_async_playwright_browser,
9
- create_sync_playwright_browser
10
  )
11
  from langchain_community.agent_toolkits import PlayWrightBrowserToolkit
12
 
@@ -52,11 +51,11 @@ class BrowserManager:
52
  if self._browser_tools is None:
53
  # Create new event loop for this thread if needed
54
  try:
55
- loop = anyio.get_current_loop()
56
  except RuntimeError:
57
  # Create new event loop in this thread
58
- loop = anyio.new_event_loop()
59
- anyio.set_event_loop(loop)
60
 
61
  # Create tools in the event loop
62
  self._browser_tools = loop.run_until_complete(self._create_async_tools())
@@ -75,7 +74,7 @@ class BrowserManager:
75
  if hasattr(tool, 'browser'):
76
  try:
77
  # Run cleanup in event loop
78
- loop = anyio.get_current_loop()
79
  loop.run_until_complete(tool.browser.close())
80
  except:
81
  pass
 
1
  import subprocess
2
+ import asyncio
3
  from contextlib import contextmanager
4
  from typing import List, Optional
5
  from threading import Lock
6
  from smolagents.tools import Tool
7
  from langchain_community.tools.playwright.utils import (
8
  create_async_playwright_browser,
 
9
  )
10
  from langchain_community.agent_toolkits import PlayWrightBrowserToolkit
11
 
 
51
  if self._browser_tools is None:
52
  # Create new event loop for this thread if needed
53
  try:
54
+ loop = asyncio.get_event_loop()
55
  except RuntimeError:
56
  # Create new event loop in this thread
57
+ loop = asyncio.new_event_loop()
58
+ asyncio.set_event_loop(loop)
59
 
60
  # Create tools in the event loop
61
  self._browser_tools = loop.run_until_complete(self._create_async_tools())
 
74
  if hasattr(tool, 'browser'):
75
  try:
76
  # Run cleanup in event loop
77
+ loop = asyncio.get_event_loop()
78
  loop.run_until_complete(tool.browser.close())
79
  except:
80
  pass
mini_agents.py CHANGED
@@ -9,7 +9,7 @@ from browser import browser_manager
9
  import os
10
  import logging
11
  import yaml
12
- import anyio
13
  from typing import List, Optional
14
  from smolagents.tools import Tool
15
 
@@ -190,10 +190,10 @@ class MasterAgentWrapper:
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
 
9
  import os
10
  import logging
11
  import yaml
12
+ import asyncio
13
  from typing import List, Optional
14
  from smolagents.tools import Tool
15
 
 
190
  with browser_manager.get_browser_tools() as browser_tools:
191
  # Get or create event loop for browser tools
192
  try:
193
+ loop = asyncio.get_event_loop()
194
  except RuntimeError:
195
+ loop = asyncio.new_event_loop()
196
+ asyncio.set_event_loop(loop)
197
 
198
  # Run with browser tools
199
  # The browser tools will handle their own async operations