Skip to content

Commit 898a2fd

Browse files
rm caller field from Anthropic tool_use blocks (#256)
* Strip caller field from Anthropic tool_use blocks * changeset * formatting * revert changes to agent_example_local.py * formatting
1 parent 3b27747 commit 898a2fd

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stagehand": patch
3+
---
4+
5+
fix: invalid_request_error when using anthropic cua client

stagehand/agent/anthropic_cua.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,13 @@ def _process_provider_response(
295295
if hasattr(response, "content") and isinstance(response.content, list):
296296
# Serialize Pydantic models from response.content for history
297297
try:
298-
raw_assistant_content_blocks = [
299-
block.model_dump() for block in response.content
300-
]
298+
for block in response.content:
299+
block_dict = block.model_dump()
300+
if isinstance(block_dict, dict):
301+
# Anthropic beta responses include a `caller` field on tool_use blocks
302+
# but the API rejects that key on subsequent requests.
303+
block_dict.pop("caller", None)
304+
raw_assistant_content_blocks.append(block_dict)
301305
except Exception as e:
302306
self.logger.error(
303307
f"Could not model_dump response.content blocks: {e}",

stagehand/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ async def _handle_page_close(self, closing_page: StagehandPage):
147147
Uses the page switch lock to prevent race conditions with ongoing operations.
148148
"""
149149
try:
150+
150151
async def handle_with_lock():
151152
async with self.stagehand._page_switch_lock:
152153
if self.active_stagehand_page is not closing_page:

0 commit comments

Comments
 (0)