Skip to content

Browser Tool + Memory: orphaned toolUse causing ValidationException after first message #1610

@very99

Description

@very99

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:

  1. Anthropic Claude Code Issue #13964: "orphaned tool_result blocks after context truncation"

    • When conversation history is truncated/summarized, tool_use blocks are removed
    • But corresponding tool_result blocks are preserved
    • This creates orphaned tool results
  2. 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:

  1. Browser Tool creates tool_use blocks
  2. Memory saves the conversation history
  3. On subsequent requests, Memory loads the history
  4. Something in the Memory/Strands integration causes tool_use/tool_result mismatch
  5. Strands detects "orphaned toolUse" and tries to auto-repair
  6. The auto-repair logic adds extra toolResult blocks
  7. 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

  1. Is Browser Tool + Memory a supported combination?
  2. Is there official documentation for using Browser Tool with Memory?
  3. What is the "orphaned toolUse" auto-repair mechanism? Is it documented?
  4. 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

Suggested Fix

Similar to the fix suggested in Anthropic's issue, add a sanitization function that:

  1. Collects all tool_use_id values from tool_use blocks
  2. Removes any tool_result blocks whose tool_use_id doesn't have a matching tool_use block
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions