diff --git a/skyvern/config.py b/skyvern/config.py index 9114e24d..9cfc637e 100644 --- a/skyvern/config.py +++ b/skyvern/config.py @@ -131,6 +131,7 @@ class Settings(BaseSettings): OPENAI_API_KEY: str | None = None # ANTHROPIC ANTHROPIC_API_KEY: str | None = None + ANTHROPIC_CUA_LLM_KEY: str = "ANTHROPIC_CLAUDE3.7_SONNET" # OPENAI COMPATIBLE OPENAI_COMPATIBLE_MODEL_NAME: str | None = None diff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.py index 79586bee..bcf67c40 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.py index d704efaa..c7fd8745 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 Any import litellm import structlog +from anthropic import NOT_GIVEN from anthropic.types.beta.beta_message import BetaMessage as AnthropicMessage from jinja2 import Template from 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 4096 model_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 response diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py index 184f2090..f943a863 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_result if 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 teardown diff --git a/skyvern/webeye/actions/parse_actions.py b/skyvern/webeye/actions/parse_actions.py index 325705d5..719209fb 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, ) )