Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Anthropic CUA fix (#2238)
Shuchang Zheng1530338cad69
diff --git a/skyvern/config.py b/skyvern/config.pyindex 9114e24d8..9cfc637e7 100644--- a/skyvern/config.py+++ b/skyvern/config.py@@ -131,6 +131,7 @@ class Settings(BaseSettings):OPENAI_API_KEY: str | None = None# ANTHROPICANTHROPIC_API_KEY: str | None = None+ ANTHROPIC_CUA_LLM_KEY: str = "ANTHROPIC_CLAUDE3.7_SONNET"# OPENAI COMPATIBLEOPENAI_COMPATIBLE_MODEL_NAME: str | None = Nonediff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.pyindex 79586bee3..bcf67c403 100644--- a/skyvern/forge/agent.py+++ b/skyvern/forge/agent.py@@ -385,7 +385,7 @@ class ForgeAgent:# llm_caller = LLMCaller(llm_key="BEDROCK_ANTHROPIC_CLAUDE3.5_SONNET_INFERENCE_PROFILE")llm_caller = LLMCallerManager.get_llm_caller(task.task_id)if not llm_caller:- llm_caller = LLMCaller(llm_key="ANTHROPIC_CLAUDE3.5_SONNET")+ llm_caller = LLMCaller(llm_key=settings.ANTHROPIC_CUA_LLM_KEY)LLMCallerManager.set_llm_caller(task.task_id, llm_caller)step, detailed_output = await self.agent_step(task,diff --git a/skyvern/forge/sdk/api/llm/api_handler_factory.py b/skyvern/forge/sdk/api/llm/api_handler_factory.pyindex d704efaa0..c7fd87459 100644--- a/skyvern/forge/sdk/api/llm/api_handler_factory.py+++ b/skyvern/forge/sdk/api/llm/api_handler_factory.py@@ -6,6 +6,7 @@ from typing import Anyimport litellmimport structlog+from anthropic import NOT_GIVENfrom anthropic.types.beta.beta_message import BetaMessage as AnthropicMessagefrom jinja2 import Templatefrom litellm.utils import CustomStreamWrapper, ModelResponse@@ -663,7 +664,7 @@ class LLMCaller:**active_parameters: dict[str, Any],) -> ModelResponse | CustomStreamWrapper | AnthropicMessage:if self.llm_key and self.llm_key.startswith("ANTHROPIC"):- return await self._call_anthropic(messages, tools, timeout)+ return await self._call_anthropic(messages, tools, timeout, **active_parameters)return await litellm.acompletion(model=self.llm_config.model_name, messages=messages, tools=tools, timeout=timeout, **active_parameters@@ -678,15 +679,16 @@ class LLMCaller:) -> AnthropicMessage:max_tokens = active_parameters.get("max_completion_tokens") or active_parameters.get("max_tokens") or 4096model_name = self.llm_config.model_name.replace("bedrock/", "").replace("anthropic/", "")+ betas = active_parameters.get("betas", NOT_GIVEN)response = await app.ANTHROPIC_CLIENT.beta.messages.create(max_tokens=max_tokens,messages=messages,model=model_name,tools=tools,timeout=timeout,- betas=active_parameters.get("betas", None),+ betas=betas,)- LOG.info("Anthropic response", response=response)+ LOG.info("Anthropic response", response=response, betas=betas, tools=tools, timeout=timeout)return responsediff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.pyindex 184f20904..f943a863c 100644--- a/skyvern/webeye/actions/handler.py+++ b/skyvern/webeye/actions/handler.py@@ -374,6 +374,7 @@ class ActionHandler:"content": {"result": "Tool execution failed"},}llm_caller.add_tool_result(tool_call_result)+ LOG.info("Tool call result", tool_call_result=tool_call_result, action=action)return actions_resultif llm_caller and action.tool_call_id:@@ -382,6 +383,7 @@ class ActionHandler:"tool_use_id": action.tool_call_id,"content": {"result": "Tool executed successfully"},}+ LOG.info("Tool call result", tool_call_result=tool_call_result, action=action)llm_caller.add_tool_result(tool_call_result)# do the teardowndiff --git a/skyvern/webeye/actions/parse_actions.py b/skyvern/webeye/actions/parse_actions.pyindex 325705d57..719209fb9 100644--- a/skyvern/webeye/actions/parse_actions.py+++ b/skyvern/webeye/actions/parse_actions.py@@ -512,7 +512,7 @@ async def parse_anthropic_actions(task_id=task.task_id,step_id=step.step_id,step_order=step.order,- action_order=idx - 1,+ action_order=idx,tool_call_id=tool_call_id,))