Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/certain-nice-caracara.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stagehand": patch
---

fix: invalid_request_error when using anthropic cua client
10 changes: 7 additions & 3 deletions stagehand/agent/anthropic_cua.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,13 @@ def _process_provider_response(
if hasattr(response, "content") and isinstance(response.content, list):
# Serialize Pydantic models from response.content for history
try:
raw_assistant_content_blocks = [
block.model_dump() for block in response.content
]
for block in response.content:
block_dict = block.model_dump()
if isinstance(block_dict, dict):
# Anthropic beta responses include a `caller` field on tool_use blocks
# but the API rejects that key on subsequent requests.
block_dict.pop("caller", None)
raw_assistant_content_blocks.append(block_dict)
except Exception as e:
self.logger.error(
f"Could not model_dump response.content blocks: {e}",
Expand Down
1 change: 1 addition & 0 deletions stagehand/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ async def _handle_page_close(self, closing_page: StagehandPage):
Uses the page switch lock to prevent race conditions with ongoing operations.
"""
try:

async def handle_with_lock():
async with self.stagehand._page_switch_lock:
if self.active_stagehand_page is not closing_page:
Expand Down