Skip to content

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

Support Azure OpenAI API GPT-4

Max Comperatore9289e0f7f20f
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 00200a989..71864293a 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -384,7 +384,13 @@ class Agent(Generic[Context]):
elif self.chat_model_library == 'ChatOpenAI':
return 'function_calling'
elif self.chat_model_library == 'AzureChatOpenAI':
- return 'function_calling'
+ # Azure OpenAI API requires 'tools' parameter for GPT-4
+ # The error 'content must be either a string or an array' occurs when
+ # the API expects a tools array but gets something else
+ if 'gpt-4' in self.model_name.lower():
+ return 'tools'
+ else:
+ return 'function_calling'
else:
return None
else:
@@ -501,7 +507,6 @@ class Agent(Generic[Context]):
model_output.action = [action_instance]
# Check again for paused/stopped state after getting model output
- # This is needed in case Ctrl+C was pressed during the get_next_action call
await self._raise_if_stopped_or_paused()
self.state.n_steps += 1
diff --git a/browser_use/agent/views.py b/browser_use/agent/views.py
index 932371ad0..030401a29 100644
--- a/browser_use/agent/views.py
+++ b/browser_use/agent/views.py
@@ -24,7 +24,7 @@ from browser_use.dom.history_tree_processor.service import (
)
from browser_use.dom.views import SelectorMap
-ToolCallingMethod = Literal['function_calling', 'json_mode', 'raw', 'auto']
+ToolCallingMethod = Literal['function_calling', 'json_mode', 'raw', 'auto', 'tools']
REQUIRED_LLM_API_ENV_VARS = {
'ChatOpenAI': ['OPENAI_API_KEY'],
'AzureChatOpenAI': ['AZURE_OPENAI_ENDPOINT', 'AZURE_OPENAI_KEY'],