code: [code] produced error: """ RuntimeError Traceback (most recent call last) Cell…
- User
code:
codefrom langchain_openai import AzureChatOpenAI from browser_use import Agent from browser_use import BrowserConfig from browser_use.browser.context import BrowserContextConfig import asyncio import os llm = AzureChatOpenAI( azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"], azure_deployment=os.environ["AZURE_OPENAI_DEPLOYMENT_ID"], openai_api_version=os.environ["OPENAI_API_VERSION"], ) config = BrowserConfig( headless=False, disable_security=True, chrome_instance_path=r"C:\Program Files\Google\Chrome\Application\chrome.exe", extra_chromium_args=[ r"--user-data-dir=C:\Users\YINL\AppData\Local\Google\Chrome\User Data" ] ) config = BrowserContextConfig( browser_window_size={'width': 1920, 'height': 1080} ) async def main(): agent = Agent( task="Find a one-way flight from Bali to Oman on 12 January 2025 on Google Flights. Return me the cheapest option.", llm=llm, use_vision=True, save_conversation_path="logs/conversation.json" ) result = await agent.run() print(result) asyncio.run(main())produced error: """ RuntimeError Traceback (most recent call last) Cell In[7], line 37 34 result = await agent.run() 35 print(result) ---> 37 asyncio.run(main())
File c:\Users\YINLADMIN\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py:186, in run(main, debug) 161 """Execute the coroutine and return the result. 162 163 This function runs the passed coroutine, taking care of (...) 182 asyncio.run(main()) 183 """ 184 if events._get_running_loop() is not None: 185 # fail fast with short traceback --> 186 raise RuntimeError( 187 "asyncio.run() cannot be called from a running event loop") 189 with Runner(debug=debug) as runner: 190 return runner.run(main)
RuntimeError: asyncio.run() cannot be called from a running event loop """
Assistant
This error occurs because you're trying to run an async function using
asyncio.run()from within a Jupyter notebook or IPython environment that already has a running event loop. Here's how to fix it:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.