2626
2727load_dotenv ()
2828
29+ ANTHROPIC_MODEL = "claude-sonnet-4-20250514"
30+ REPRO_INSTRUCTION = (
31+ "Step 1: Use the goto tool to open https://example.com/.\n "
32+ "Step 2: After it loads, scroll down and click the 'More information...' link "
33+ "to open the iana.org page, then report the heading text you see."
34+ )
35+ ERROR_SIGNATURES = [
36+ "messages.1.content.1.tool_use.caller" ,
37+ "Extra inputs are not permitted" ,
38+ ]
39+
2940# Configure logging with the utility function
3041configure_logging (
3142 level = logging .INFO , # Set to INFO for regular logs, DEBUG for detailed
3243 quiet_dependencies = True , # Reduce noise from dependencies
3344)
3445
46+
47+ def require_env_var (var_name : str ) -> str :
48+ """Fetch a required env var with a helpful error for local runs."""
49+ value = os .getenv (var_name )
50+ if not value :
51+ raise RuntimeError (
52+ f"{ var_name } is not set. Add it to your .env before running this example."
53+ )
54+ return value
55+
56+
3557async def main ():
3658 # Build a unified configuration object for Stagehand
3759 config = StagehandConfig (
@@ -53,19 +75,37 @@ async def main():
5375 await stagehand .page .goto ("https://google.com/" )
5476 console .print ("✅ [success]Navigated to Google[/]" )
5577
56- console .print ("\n ▶️ [highlight] Using Agent to perform a task[/]: playing a game of 2048" )
78+ console .print (
79+ "\n ▶️ [highlight]Using Anthropic CUA agent[/]: reproducing the tool_use caller bug"
80+ )
81+ anthropic_api_key = require_env_var ("ANTHROPIC_API_KEY" )
5782 agent = stagehand .agent (
58- model = "gemini-2.5-computer-use-preview-10-2025" ,
59- instructions = "You are a helpful web navigation assistant that helps users find information. You are currently on the following page: google.com. Do not ask follow up questions, the user will trust your judgement." ,
60- options = {"apiKey" : os .getenv ("GEMINI_API_KEY" )}
83+ model = ANTHROPIC_MODEL ,
84+ instructions = (
85+ "You are controlling a fullscreen local browser with the Anthropic computer-use tools. "
86+ "Read the current page carefully, decide on your next action, and avoid asking follow-up questions."
87+ ),
88+ options = {"apiKey" : anthropic_api_key }
6189 )
6290 agent_result = await agent .execute (
63- instruction = "Play a game of 2048" ,
64- max_steps = 20 ,
91+ instruction = REPRO_INSTRUCTION ,
92+ max_steps = 5 ,
6593 auto_screenshot = True ,
6694 )
6795
6896 console .print (agent_result )
97+ if agent_result .message and any (
98+ signature in agent_result .message for signature in ERROR_SIGNATURES
99+ ):
100+ console .print (
101+ "🐛 [error]Reproduced the Anthropic `tool_use.caller` validation error.[/]\n "
102+ " Check the logs above for 'Extra inputs are not permitted' to link back to the GitHub issue."
103+ )
104+ else :
105+ console .print (
106+ "⚠️ [warning]Bug signature not detected in this run. "
107+ "Re-run the example or tweak the instructions if you need the failing payload."
108+ )
69109
70110 console .print ("📊 [info]Agent execution result:[/]" )
71111 console .print (f"🎯 Completed: [bold]{ 'Yes' if agent_result .completed else 'No' } [/]" )
@@ -100,4 +140,4 @@ async def main():
100140 padding = (1 , 10 ),
101141 ),
102142 )
103- asyncio .run (main ())
143+ asyncio .run (main ())
0 commit comments