| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
When extended thinking is enabled, assistant messages contain reasoningContent blocks alongside toolUse blocks. The filter was stripping toolUse/toolResult but leaving reasoningContent intact, producing a partial assistant message that Bedrock rejects with: ValidationException: `thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. reasoningContent blocks are semantically coupled to the tool calls that follow them — stripping the tool context without the accompanying reasoning leaves an incoherent and API-rejected message. The fix adds reasoningContent to the set of block types removed by the filter. Fixes aws#621 Signed-off-by: gingeekrishna <gingeekrishna@gmail.com>
There was a problem hiding this comment.
This PR fixes restored-session filtering for Bedrock extended thinking by ensuring reasoningContent blocks are removed alongside toolUse/toolResult blocks, preventing invalid assistant messages from being sent to Bedrock.
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/bedrock_agentcore/memory/integrations/strands/test_agentcore_memory_session_manager.py | Adds regression tests validating restored-history filtering when reasoningContent is present. |
| src/bedrock_agentcore/memory/integrations/strands/session_manager.py | Extends restored tool-context filtering to remove reasoningContent blocks and documents the rationale. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
| """Strip historical toolUse/toolResult context from restored messages. | ||
|
|
||
| Extended-thinking (reasoningContent) blocks are coupled to the tool | ||
| calls that follow them. Bedrock rejects an assistant message whose | ||
| reasoningContent blocks have been separated from their companion |
…_context Clarify that the flag strips reasoningContent (extended thinking) blocks in addition to toolUse/toolResult, and explain why the two are always removed together. Signed-off-by: gingeekrishna <gingeekrishna@gmail.com>
|
Done - addressed Copilot review: updated the filter_restored_tool_context docstring in AgentCoreMemoryConfig (commit d4f9b5d) to clarify that it strips toolUse, toolResult, and reasoningContent (extended thinking) blocks, with a note explaining that reasoning blocks must always be removed alongside the tool calls that followed them. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Root cause
When extended thinking is enabled, an assistant turn produces a message like:
{ "role": "assistant", "content": [ {"reasoningContent": {"reasoningText": {"text": "…"}}}, {"toolUse": {"toolUseId": "t1", "name": "my_tool", "input": {}}} ] }reasoningContent and toolUse are semantically coupled — the Bedrock API requires them to appear together. filter_restored_tool_context was removing toolUse while keeping reasoningContent, producing a partial message that the API refuses.
Test plan
Fixes #621