Skip to content

Automate browser based workflows with AI

fix anthropic tool result format (#2246)

Shuchang Zhengf4ea546ae442
diff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.py
index 36cf8e866..93259c520 100644
--- a/skyvern/forge/agent.py
+++ b/skyvern/forge/agent.py
@@ -1405,9 +1405,19 @@ class ForgeAgent:
scraped_page: ScrapedPage,
llm_caller: LLMCaller,
) -> list[Action]:
+ LOG.info(
+ "Anthropic CU call starts",
+ tool_results=llm_caller.current_tool_results,
+ message_length=len(llm_caller.message_history),
+ )
if llm_caller.current_tool_results:
llm_caller.message_history.append({"role": "user", "content": llm_caller.current_tool_results})
llm_caller.clear_tool_results()
+ LOG.info(
+ "Anthropic CU call - appended tool result message to message history and cleared cached tool results",
+ message=llm_caller.current_tool_results,
+ message_length=len(llm_caller.message_history),
+ )
tools = [
{
"type": "computer_20250124",
diff --git a/skyvern/forge/sdk/api/llm/api_handler_factory.py b/skyvern/forge/sdk/api/llm/api_handler_factory.py
index fc575ba49..234ed6982 100644
--- a/skyvern/forge/sdk/api/llm/api_handler_factory.py
+++ b/skyvern/forge/sdk/api/llm/api_handler_factory.py
@@ -700,6 +700,7 @@ class LLMCaller:
betas=betas,
tools=tools,
timeout=timeout,
+ messages_length=len(messages),
)
response = await app.ANTHROPIC_CLIENT.beta.messages.create(
max_tokens=max_tokens,
diff --git a/skyvern/webeye/actions/actions.py b/skyvern/webeye/actions/actions.py
index 72fe8f2e0..a3d3e8aef 100644
--- a/skyvern/webeye/actions/actions.py
+++ b/skyvern/webeye/actions/actions.py
@@ -189,7 +189,7 @@ class ClickAction(WebAction):
button: str = "left"
def __repr__(self) -> str:
- return f"ClickAction(element_id={self.element_id}, file_url={self.file_url}, download={self.download})"
+ return f"ClickAction(element_id={self.element_id}, file_url={self.file_url}, download={self.download}, x={self.x}, y={self.y}, button={self.button}, tool_call_id={self.tool_call_id})"
class InputTextAction(WebAction):
@@ -197,7 +197,7 @@ class InputTextAction(WebAction):
text: str
def __repr__(self) -> str:
- return f"InputTextAction(element_id={self.element_id}, text={self.text})"
+ return f"InputTextAction(element_id={self.element_id}, text={self.text}, tool_call_id={self.tool_call_id})"
class UploadFileAction(WebAction):
diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py
index f943a863c..8a60a5b7a 100644
--- a/skyvern/webeye/actions/handler.py
+++ b/skyvern/webeye/actions/handler.py
@@ -371,7 +371,7 @@ class ActionHandler:
tool_call_result = {
"type": "tool_result",
"tool_use_id": action.tool_call_id,
- "content": {"result": "Tool execution failed"},
+ "content": "Tool execution failed",
}
llm_caller.add_tool_result(tool_call_result)
LOG.info("Tool call result", tool_call_result=tool_call_result, action=action)
@@ -381,7 +381,7 @@ class ActionHandler:
tool_call_result = {
"type": "tool_result",
"tool_use_id": action.tool_call_id,
- "content": {"result": "Tool executed successfully"},
+ "content": "Tool executed successfully",
}
LOG.info("Tool call result", tool_call_result=tool_call_result, action=action)
llm_caller.add_tool_result(tool_call_result)