Skip to content

Commit cb57004

Browse files
committed
goto for anthropic
1 parent f547982 commit cb57004

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

stagehand/agent/anthropic_cua.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,8 @@ async def run_task(
148148
tools=self.tools,
149149
betas=["computer-use-2025-01-24"],
150150
)
151-
self.logger.info(f"Anthropic response: {response}")
152151
end_time = asyncio.get_event_loop().time()
153152
total_inference_time_ms += int((end_time - start_time) * 1000)
154-
self.logger.info(f"Total inference time: {total_inference_time_ms}")
155153
if response.usage:
156154
total_input_tokens += response.usage.input_tokens or 0
157155
total_output_tokens += response.usage.output_tokens or 0
@@ -316,23 +314,24 @@ def _process_provider_response(
316314
def _convert_tool_use_to_agent_action(
317315
self, tool_name: str, tool_input: dict[str, Any]
318316
) -> Optional[AgentAction]:
319-
if tool_name != "computer":
317+
if tool_name != "computer" and tool_name != "goto":
320318
self.logger.warning(
321319
f"Unsupported tool name from Anthropic: {tool_name}",
322320
category=StagehandFunctionName.AGENT,
323321
)
324322
return None
325323

326-
action_type_str = tool_input.get("action")
324+
if tool_name == "goto":
325+
action_type_str = "function"
326+
else:
327+
action_type_str = tool_input.get("action")
327328
if not action_type_str:
328329
self.logger.error(
329330
"Missing 'action' in Anthropic computer tool_input",
330331
category=StagehandFunctionName.AGENT,
331332
)
332333
return None
333334

334-
self.logger.info(f"Action type: {action_type_str}")
335-
336335
action_model_payload: Optional[AgentActionType] = None
337336
reasoning = tool_input.get("reasoning")
338337

@@ -527,21 +526,22 @@ def _convert_tool_use_to_agent_action(
527526
)
528527
action_type_str = "screenshot" # Normalize
529528

530-
elif action_type_str == "goto":
531-
url = tool_input.get("url")
532-
if url:
533-
action_model_payload = AgentActionType(
534-
type="function",
535-
name="goto",
536-
arguments=FunctionArguments(url=url),
537-
)
538-
action_type_str = "function"
539-
else:
540-
self.logger.warning(
541-
"Goto action from Anthropic missing URL",
542-
category=StagehandFunctionName.AGENT,
543-
)
544-
return None
529+
elif action_type_str == "function":
530+
if tool_name == "goto":
531+
url = tool_input.get("url")
532+
if url:
533+
action_model_payload = AgentActionType(
534+
type="function",
535+
name="goto",
536+
arguments=FunctionArguments(url=url),
537+
)
538+
action_type_str = "function"
539+
else:
540+
self.logger.warning(
541+
"Goto action from Anthropic missing URL",
542+
category=StagehandFunctionName.AGENT,
543+
)
544+
return None
545545
else:
546546
self.logger.warning(
547547
f"Unsupported action type '{action_type_str}' from Anthropic computer tool.",

0 commit comments

Comments
 (0)