-
Notifications
You must be signed in to change notification settings - Fork 658
Description
Bug Description
When using AgentCoreBrowser (Browser Tool) together with AgentCoreMemorySessionManager (AgentCore Memory), the agent fails with a ValidationException after the first successful message in the same session.
Environment
- Strands Agents: Latest version
- bedrock-agentcore: Latest version
- strands-agents-tools: Latest version
- Region: us-east-1
- Runtime: AgentCore Runtime (JWT authentication)
Problem Description
Error Message
Session message history has an orphaned toolUse with no toolResult.
Adding toolResult content blocks to create valid conversation.
ValidationException: The number of toolResult blocks at messages.27.content
exceeds the number of toolUse blocks of previous turn.
Behavior
- ✅ First message in session: Works correctly
- ❌ Subsequent messages in same session: Fails with ValidationException
- ✅ Without Browser Tool (Gateway tools only): Works correctly
- ❌ Without Gateway (Browser Tool + Memory only): Still fails
Code Example
from strands import Agent
from strands_tools.browser import AgentCoreBrowser
from bedrock_agentcore.memory.integrations.strands.config import AgentCoreMemoryConfig
from bedrock_agentcore.memory.integrations.strands.session_manager import AgentCoreMemorySessionManager
# Memory configuration
memory_config = AgentCoreMemoryConfig(
memory_id=MEMORY_ID,
session_id=session_id,
actor_id=actor_id
)
session_manager = AgentCoreMemorySessionManager(
agentcore_memory_config=memory_config,
region_name="us-east-1"
)
# Browser Tool
browser_tool = AgentCoreBrowser(region="us-east-1")
# Agent with Browser Tool + Memory
agent = Agent(
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
system_prompt="You are a helpful assistant.",
session_manager=session_manager,
tools=[browser_tool.browser]
)
# First call: SUCCESS ✅
result1 = agent("Hello")
# Second call in same session: FAILS ❌
result2 = agent("How are you?")Root Cause Analysis
Based on similar issues found in the community:
-
Anthropic Claude Code Issue #13964: "orphaned tool_result blocks after context truncation"
- When conversation history is truncated/summarized,
tool_useblocks are removed - But corresponding
tool_resultblocks are preserved - This creates orphaned tool results
- When conversation history is truncated/summarized,
-
browser-use Issue [BUG] Claude 4 models stop at 8192 output tokens #710: Similar ValidationException with Bedrock Converse API
Hypothesis
The issue appears to be related to how AgentCore Memory saves conversation history when Browser Tool is used:
- Browser Tool creates
tool_useblocks - Memory saves the conversation history
- On subsequent requests, Memory loads the history
- Something in the Memory/Strands integration causes
tool_use/tool_resultmismatch - Strands detects "orphaned toolUse" and tries to auto-repair
- The auto-repair logic adds extra
toolResultblocks - Bedrock API rejects the request due to count mismatch
Logs
2026-02-02T10:12:24.909000+00:00 Session message history has an orphaned toolUse with no toolResult. Adding toolResult content blocks to create valid conversation.
2026-02-02T10:12:25.876000+00:00 botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the ConverseStream operation: The number of toolResult blocks at messages.27.content exceeds the number of toolUse blocks of previous turn.
Questions
- Is Browser Tool + Memory a supported combination?
- Is there official documentation for using Browser Tool with Memory?
- What is the "orphaned toolUse" auto-repair mechanism? Is it documented?
- Should Memory handle Browser Tool's conversation history differently?
Expected Behavior
Browser Tool and Memory should work together seamlessly without ValidationException errors across multiple messages in the same session.
Actual Behavior
After the first successful message, subsequent messages in the same session fail with ValidationException about toolResult/toolUse count mismatch.
Related Issues
- Anthropic Claude Code #13964: orphaned tool_result blocks after context truncation
- browser-use [BUG] Claude 4 models stop at 8192 output tokens #710: Browser-use fails with Bedrock Converse API
Suggested Fix
Similar to the fix suggested in Anthropic's issue, add a sanitization function that:
- Collects all
tool_use_idvalues fromtool_useblocks - Removes any
tool_resultblocks whosetool_use_iddoesn't have a matchingtool_useblock - Runs this sanitization before every API call
This should be done either in:
- Strands Agents' conversation history management
- Or in the AgentCore Memory integration layer