browser-use
browser-use copied to clipboard
Fix Ollama parsing error
It seems that langchain's with_structured_output sometimes fails to parse the structured AgentOutput response, but there's valid json output inside raw response. I'm not langchain expert, if there's a better way to deal with, I'm happy to fix.
Also renames examples/models/ollama.py to examples/models/ollama_example.py to avoid import conflict: ImportError: cannot import name 'ChatOllama' from partially initialized module 'langchain_ollama' (most likely due to a circular import)
Related issues: https://github.com/browser-use/browser-use/issues/584 https://github.com/browser-use/browser-use/issues/442 https://github.com/browser-use/browser-use/issues/238
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.
:x: Hang Zhao
:x: FindBoat
Hang Zhao seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.
I tried to generate new tests but there might be some issues in your codebase that I couldn't fix.
🔄 Could not generate any new tests. 🐛 Found 1 bug 🛠️ 0/7 tests passed
🐛 Bug Detection
Potential issues found in the following files:
browser_use/agent/service.py
The error occurs because when the registry’s execute_action method is called for an action that requires a browser argument, the extra argument is not being forwarded to the action function. In our test, we explicitly pass browser=mock_browser, yet when the function (test_action_with_browser) is invoked, it is missing the required positional argument "browser". This indicates that the implementation in the registry’s execute_action method (in browser_use/controller/registry/service.py) is incorrectly handling (or omitting) the extra keyword arguments that should be passed to the action function.
🛠️ Test Results
0/7 tests passed ⚠️
tests/test_dropdown.py
View error
tests/test_dropdown.py:20: in <module>
llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
self.root_client = openai.OpenAI(**client_params, **sync_specific) # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
raise OpenAIError(
E openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
tests/test_dropdown.py
tests/test_dropdown_complex.py
View error
tests/test_dropdown_complex.py:20: in <module>
llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
self.root_client = openai.OpenAI(**client_params, **sync_specific) # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
raise OpenAIError(
E openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
tests/test_dropdown_complex.py
tests/test_dropdown_error.py
View error
tests/test_dropdown_error.py:20: in <module>
llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
self.root_client = openai.OpenAI(**client_params, **sync_specific) # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
raise OpenAIError(
E openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
tests/test_dropdown_error.py
tests/test_gif_path.py
View error
tests/test_gif_path.py:19: in <module>
llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
self.root_client = openai.OpenAI(**client_params, **sync_specific) # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
raise OpenAIError(
E openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
tests/test_gif_path.py
tests/test_models.py
View error
tests/test_models.py:54: in <module>
ChatOpenAI(
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
self.root_client = openai.OpenAI(**client_params, **sync_specific) # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
raise OpenAIError(
E openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
tests/test_models.py
tests/test_react_dropdown.py
View error
tests/test_react_dropdown.py:20: in <module>
llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
self.root_client = openai.OpenAI(**client_params, **sync_specific) # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
raise OpenAIError(
E openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
tests/test_react_dropdown.py
tests/test_vision.py
View error
tests/test_vision.py:25: in <module>
llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
self.root_client = openai.OpenAI(**client_params, **sync_specific) # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
raise OpenAIError(
E openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
tests/test_vision.py
Settings | Logs | CodeBeaver
I opened a Pull Request with the following:
🔄 1 test added. 🐛 Found 1 bug 🛠️ 1/3 tests passed
🔄 Test Updates
I've added 1 tests. They all pass ☑️ New Tests:
tests/test_prompts.py
No existing tests required updates.
🐛 Bug Detection
Potential issues found in the following files:
browser_use/agent/service.py
The error is caused by a bug in the code being tested rather than a misconfiguration of the test or a problem with the test itself. In the Registry’s execute_action implementation (in browser_use/controller/registry/service.py), the extra arguments (in this case, the browser) are not being passed through correctly to the action function. The test “test_execute_action_with_and_without_browser_context” expects that when a browser is provided via extra arguments, the action function (test_action_with_browser) will receive it. Instead, the action is invoked without the required “browser” parameter, resulting in a TypeError.
🛠️ Test Results
1/3 tests passed ⚠️
tests/test_models.py
View error
tests/test_models.py:84: in <module>
ChatGoogleGenerativeAI(model='gemini-2.0-flash-exp', api_key=api_key_gemini),
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_google_genai/chat_models.py:841: in validate_environment
self.client = genaix.build_generative_service(
/usr/local/lib/python3.11/site-packages/langchain_google_genai/_genai_extension.py:276: in build_generative_service
return v1betaGenerativeServiceClient(**config)
/usr/local/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/generative_service/client.py:667: in __init__
self._transport = transport_init(
/usr/local/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/generative_service/transports/grpc.py:235: in __init__
super().__init__(
/usr/local/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/generative_service/transports/base.py:100: in __init__
credentials, _ = google.auth.default(
/usr/local/lib/python3.11/site-packages/google/auth/_default.py:719: in default
raise exceptions.DefaultCredentialsError(_CLOUD_SDK_MISSING_CREDENTIALS)
E google.auth.exceptions.DefaultCredentialsError: Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information.
tests/test_models.py
tests/test_prompts.py
View error
/usr/local/lib/python3.11/site-packages/_pytest/python.py:493: in importtestmodule
mod = import_path(
/usr/local/lib/python3.11/site-packages/_pytest/pathlib.py:587: in import_path
importlib.import_module(module_name)
/usr/local/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1204: in _gcd_import
???
<frozen importlib._bootstrap>:1176: in _find_and_load
???
<frozen importlib._bootstrap>:1147: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:690: in _load_unlocked
???
/usr/local/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:175: in exec_module
source_stat, co = _rewrite_test(fn, self.config)
/usr/local/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:355: in _rewrite_test
tree = ast.parse(source, filename=strfn)
/usr/local/lib/python3.11/ast.py:50: in parse
return compile(source, filename, mode, flags,
E File "/app/temp_workspace/tests/test_prompts.py", line 488
E assert "Paragraph: Header content" in interactive_block, "Interactive element text missing in output"import pytest
E ^^^^^^
E SyntaxError: invalid syntax
tests/test_prompts.py
☂️ Coverage Improvements
Coverage improvements by file:
tests/test_prompts.pyNew coverage: 100.00% Improvement: +100.00%
🎨 Final Touches
- I ran the hooks included in the pre-commit config.
Settings | Logs | CodeBeaver
In my opinion, this still don't resolve the iusse:
Trying the new implementation, the Response still contains an empty content:
{'raw': AIMessage(content='', additional_kwargs={}, response_metadata={'model': 'llama3.2', 'created_at': '2025-02-15T11:18:59.924575Z', 'done': True, 'done_reason': 'stop', 'total_duration': 1298690250, 'load_duration': 73070250, 'prompt_eval_count': 2318, 'prompt_eval_duration': 475000000, 'eval_count': 27, 'eval_duration': 734000000, 'message': Message(role='assistant', content='', images=None, tool_calls=None)}, id='run-4f2677a4-a3f8-4a6f-9033-bbcc206a0549-0', tool_calls=[{'name': 'go_to_url', 'args': {'url': 'https://www.kayak.com/flights/'}, 'id': '1f56e00e-5521-4594-acbc-aa29b9906633', 'type': 'tool_call'}], usage_metadata={'input_tokens': 2318, 'output_tokens': 27, 'total_tokens': 2345}), 'parsing_error': KeyError('go_to_url'), 'parsed': None}
I tried with llama3.2
Same here, I still have this error.
ditto
👋 This PR has been automatically marked as stale because it hasn't had activity for 45 days.
To keep this PR open:
- Rebase against the latest main branch
- Address any review feedback or merge conflicts
- Add a comment explaining the current status
- Add the
work-in-progresslabel if you're still actively working on this
This will be automatically closed in 14 days if no further activity occurs.
Thanks for contributing to browser-use! 🤖