You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_filter_restored_tool_context() stripped toolUse/toolResult blocks from restored session history but left reasoningContent (extended thinking) blocks intact.
Bedrock rejects an assistant message where reasoningContent blocks are present without their companion toolUse blocks, raising a ValidationException.
Fix: add "reasoningContent" not in content to the filter predicate so thinking blocks are stripped together with the tool calls they preceded.
Root cause
When extended thinking is enabled, an assistant turn produces a message like:
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
test_strips_reasoning_content_alongside_tool_use — assistant message with reasoningContent+toolUse → both stripped, only plain-text assistant message survives
test_message_with_only_reasoning_and_tool_use_is_dropped_entirely — message becomes empty after stripping → excluded from output
test_text_alongside_reasoning_and_tool_use_is_preserved — text content survives after stripping reasoning+toolUse
test_messages_without_tool_context_are_unchanged — plain text messages pass through unchanged (no regression)
test_existing_tool_use_filtering_still_works — original toolUse/toolResult behaviour preserved
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.
Fixesaws#621
Signed-off-by: gingeekrishna <gingeekrishna@gmail.com>
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
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:
Update _filter_restored_tool_context() to also strip reasoningContent blocks when filtering restored history.
Expand the session manager integration test suite with regression cases covering reasoning+tool interactions and preservation of plain text.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
…_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_filter_restored_tool_context()strippedtoolUse/toolResultblocks from restored session history but leftreasoningContent(extended thinking) blocks intact.reasoningContentblocks are present without their companiontoolUseblocks, raising aValidationException."reasoningContent" not in contentto the filter predicate so thinking blocks are stripped together with the tool calls they preceded.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": {}}} ] }reasoningContentandtoolUseare semantically coupled — the Bedrock API requires them to appear together.filter_restored_tool_contextwas removingtoolUsewhile keepingreasoningContent, producing a partial message that the API refuses.Test plan
test_strips_reasoning_content_alongside_tool_use— assistant message with reasoningContent+toolUse → both stripped, only plain-text assistant message survivestest_message_with_only_reasoning_and_tool_use_is_dropped_entirely— message becomes empty after stripping → excluded from outputtest_text_alongside_reasoning_and_tool_use_is_preserved— text content survives after stripping reasoning+toolUsetest_messages_without_tool_context_are_unchanged— plain text messages pass through unchanged (no regression)test_existing_tool_use_filtering_still_works— original toolUse/toolResult behaviour preservedFixes#621