AgentCore Memory + Browser Tool: Conversation history corruption causing orphaned toolUse
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- aws, python
- 领域
- ai, backend-api-design
调研方向
从 AgentCoreMemorySessionManager 开始,使用提供的 Browser Tool 和内存配置重现故障,并比较保存前和加载后的对话历史。第二次 agent 调用成功,且加载后的历史保留有效的 toolUse/toolResult 配对,即表示完成;issue 中未指定具体文件或测试。
由索引模型根据 Issue 内容生成。
描述
Bug Description
When using AgentCoreMemorySessionManager with AgentCoreBrowser (Browser Tool) in Strands Agents, the conversation history becomes corrupted after the first message, leading to ValidationException errors.
Environment
- bedrock-agentcore: Latest version
- Strands Agents: Latest version
- strands-agents-tools: Latest version
- Region: us-east-1
- Memory ID: memory_agentcore_demo_complex-MOvGs2AZQ5
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: Memory works correctly with other tools (Gateway tools)
- ❌ With Browser Tool: Memory appears to save corrupted conversation history
Code Example
from bedrock_agentcore.memory.integrations.strands.config import AgentCoreMemoryConfig
from bedrock_agentcore.memory.integrations.strands.session_manager import AgentCoreMemorySessionManager
from strands import Agent
from strands_tools.browser import AgentCoreBrowser
# Memory configuration
memory_config = AgentCoreMemoryConfig(
memory_id="memory_agentcore_demo_complex-MOvGs2AZQ5",
session_id="test_session_123",
actor_id="test_user"
)
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 ❌
# Memory loads corrupted history with orphaned toolUse
result2 = agent("How are you?")
Root Cause Hypothesis
The issue appears to be in how AgentCoreMemorySessionManager saves and loads conversation history when Browser Tool is involved:
Possible Causes:
-
Incomplete tool call persistence:
- Browser Tool creates
tool_useblocks - Memory saves the conversation
- On reload,
tool_useblocks are missing or corrupted - But
tool_resultblocks are preserved - This creates "orphaned toolUse"
- Browser Tool creates
-
Serialization/Deserialization issue:
- Browser Tool's conversation format may not be fully compatible with Memory's storage format
- Some data is lost during save/load cycle
-
Context truncation without cleanup:
- Memory may truncate conversation history
- But doesn't properly clean up orphaned tool blocks
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.
Testing Results
| Configuration | Result |
|---|---|
| Memory + Gateway Tools | ✅ Works |
| Memory + Browser Tool | ❌ Fails after first message |
| No Memory + Browser Tool | ❓ Not tested (Memory required) |
| Memory + Gateway + Browser | ❌ Fails after first message |
This strongly suggests the issue is in how Memory handles Browser Tool's conversation history.
Questions
- Is Browser Tool + Memory a tested and supported combination?
- Are there known limitations or special handling required for Browser Tool with Memory?
- Does Memory have special serialization logic for different tool types?
- Is there documentation on conversation history format requirements?
Expected Behavior
AgentCore Memory should correctly save and restore conversation history when Browser Tool is used, maintaining proper tool_use/tool_result pairing.
Actual Behavior
After the first message, Memory loads corrupted conversation history with orphaned tool blocks, causing Bedrock API to reject subsequent requests.
Related Issues
- Similar issue reported in Strands Agents: strands-agents/sdk-python#1610
- Anthropic Claude Code #13964: orphaned tool_result blocks after context truncation
- browser-use #710: Browser-use fails with Bedrock Converse API
Suggested Investigation
- Add logging to show exactly what Memory saves vs. what it loads
- Compare conversation history format for Browser Tool vs. other tools
- Check if Browser Tool's message format requires special handling
- Verify that all tool blocks are properly paired during save/load
Suggested Fix
Add validation and cleanup in AgentCoreMemorySessionManager:
- Before saving: Validate that all
tool_useblocks have correspondingtool_resultblocks - After loading: Sanitize conversation history to remove orphaned tool blocks
- Add specific handling for Browser Tool if its format differs from standard tools
Impact
This bug prevents using Browser Tool with Memory, which is a critical limitation for building context-aware agents that need web browsing capabilities.
- 主要语言
- Python
- 星标
- 786
- 派生
- 163
- 平均合并
- 4 小时
- 30 天内合并 PR
- 22
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aws/bedrock-agentcore-sdk-python 的其他 Issue
-
bug high-severity
难度 2/5 1-3 小时 新手友好度 72/100
aws/bedrock-agentcore-sdk-python#752 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
aws/bedrock-agentcore-sdk-python#751 · 1 个 reaction ·
维护者通常 1 天内回复
-
delete_all_long_term_memories_in_namespace deletes only the first 10 records可能已有人在做 @Fire162 于 18 天前认领。 未关闭bug high-severity
难度 2/5 1-3 小时 新手友好度 75/100
aws/bedrock-agentcore-sdk-python#727 ·
维护者通常 1 天内回复
-
MPP: credential is always sent in Authorization, ignoring header="Payment-Authorization" in the challenge可能已有人在做 @abhiramshaji-cyber 于 24 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
aws/bedrock-agentcore-sdk-python#702 ·
维护者通常 1 天内回复
-
[Bug] update_message fails with parameter validation error when SessionMessage.message_id is a Strands positional integer index可能已有人在做 @citizen204 于 144 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
aws/bedrock-agentcore-sdk-python#556 ·
维护者通常 1 天内回复
查看 aws/bedrock-agentcore-sdk-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
-
bug difficulty:2
难度 2/5 1-3 小时 新手友好度 72/100
MakazhanAlpamys/Soup#3167 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
snap-stanford/Biomni#380 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
jsboige/CoursIA#27768 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 66/100
rossant/awesome-math#206 ·