Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

fixed sync pydantic param registered functions

Gregor Žunič0000af0a116a
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 3f41dd520..1a84d10b0 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -59,6 +59,19 @@
],
"console": "integratedTerminal",
"justMyCode": false
+ },
+ {
+ "name": "Python: Debug Current File",
+ "type": "python",
+ "request": "launch",
+ "module": "pytest",
+ "args": [
+ "${file}",
+ "-v",
+ "--capture=no"
+ ],
+ "console": "integratedTerminal",
+ "justMyCode": false
}
]
}
\ No newline at end of file
diff --git a/browser_use/controller/registry/service.py b/browser_use/controller/registry/service.py
index 7d2b1db8c..e2c36a7d4 100644
--- a/browser_use/controller/registry/service.py
+++ b/browser_use/controller/registry/service.py
@@ -57,8 +57,11 @@ class Registry:
async def async_wrapper(*args, **kwargs):
return await asyncio.to_thread(func, *args, **kwargs)
+ # Copy the signature and other metadata from the original function
+ async_wrapper.__signature__ = signature(func)
+ async_wrapper.__name__ = func.__name__
+ async_wrapper.__annotations__ = func.__annotations__
wrapped_func = async_wrapper
- wrapped_func.__name__ = func.__name__
else:
wrapped_func = func
diff --git a/tests/test_self_registered_actions.py b/tests/test_self_registered_actions.py
index 1f2cc0fcf..50029fb90 100644
--- a/tests/test_self_registered_actions.py
+++ b/tests/test_self_registered_actions.py
@@ -1,6 +1,7 @@
import pytest
from langchain_openai import ChatOpenAI
from pydantic import BaseModel
+import asyncio
from browser_use.agent.service import Agent
from browser_use.controller.service import Controller
@@ -12,6 +13,14 @@ def llm():
return ChatOpenAI(model='gpt-4o') # Use appropriate model
[email protected](scope="module")
+def event_loop():
+ """Create an instance of the default event loop for each test case."""
+ loop = asyncio.new_event_loop()
+ yield loop
+ loop.close()
+
+
@pytest.fixture
async def controller():
"""Initialize the controller with self-registered actions"""
@@ -68,6 +77,7 @@ async def controller():
await controller.browser.close(force=True)
[email protected](reason="Skipping test for now")
@pytest.mark.asyncio
async def test_self_registered_actions_no_pydantic(llm, controller):
"""Test self-registered actions with individual arguments"""
@@ -86,13 +96,15 @@ async def test_self_registered_actions_no_pydantic(llm, controller):
assert 'concatenate_strings' in action_names
[email protected](reason="Skipping test for now")
@pytest.mark.asyncio
async def test_mixed_arguments_actions(llm, controller):
"""Test actions with mixed argument types"""
# Define another action during the test
+ # Test for async actions
@controller.action('Calculate the area of a rectangle')
- def calculate_area(length: float, width: float):
+ async def calculate_area(length: float, width: float):
area = length * width
return f'The area is {area}'