aws / aws/bedrock-agentcore-sdk-python

AgentCoreMemorySessionManager: allow excluding binary content from persisted messages

オープン
#646 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

enhancement
主要言語
Python
スター
764
フォーク
148
平均マージ
1日 23時間
マージ済み PR(30日)
7

説明

Summary

When a tool result carries a Bedrock document or image block, AgentCoreMemorySessionManager persists the raw bytes to AgentCore Memory.

For a large document, CreateEvent rejects the request with HTTP 413 and the agent's turn is destroyed. There is currently no way to persist the message without its binary payload.

Reproduction

Agent configured with AgentCoreMemorySessionManager (defaults: persistence_mode=FULL, batch_size=1, async_mode=False). A tool returns a document block containing a ~16.5 MB PDF. Strands appends the tool-result message, the MessageAddedEvent hook persists it, and CreateEvent returns 413:

File ".../bedrock_agentcore/memory/integrations/strands/session_manager.py", line 631, in create_message
    event = self.memory_client.gmdp_client.create_event(**create_event_kwargs)
botocore.exceptions.ClientError: An error occurred (413) when calling the CreateEvent operation:

The above exception was the direct cause of the following exception:

File ".../strands/event_loop/event_loop.py", line 832, in _handle_tool_execution
    await agent._append_messages(tool_result_message)
File ".../strands/session/session_manager.py", line 46, in <lambda>
    registry.add_callback(MessageAddedEvent, lambda event: self.append_message(...))
File ".../bedrock_agentcore/memory/integrations/strands/session_manager.py", line 840, in append_message
File ".../bedrock_agentcore/memory/integrations/strands/session_manager.py", line 636, in create_message
    raise SessionException(f"Failed to create message: {e}") from e

strands.types.exceptions.SessionException: Failed to create message: An error occurred (413) ...
strands.types.exceptions.EventLoopException: Failed to create message: An error occurred (413) ...

The tool call itself succeeded. The failure is in persistence, and it aborts the whole invocation, losing every prior step of the turn.

Observed with bedrock-agentcore 1.21.0. A 612 KB document persists fine, so the threshold sits somewhere between that and 16.5 MB. It does not appear to be documented, and 413 is not among the modelled CreateEvent errors in the API reference.

Why the existing configuration does not cover this
Option Limitation
persistence_mode=NONE All or nothing. Disables session history entirely, which is the reason for using the session manager.
filter_restored_tool_context Applies on the read side when restoring messages. The failure is on write.
batch_size, flush_interval_seconds Batching happens downstream of the oversized payload.
Why binary content is not worth persisting

Beyond the size failure, storing the bytes has little upside:

  1. Long-term memory extraction cannot use base64 document or image payloads.
  2. On restore, replaying the bytes into every subsequent model request is usually undesirable.
  3. It writes megabytes per turn for content the caller can re-fetch from its own source of truth.
Proposed change

A hook applied to each message before create_event, so callers can substitute or drop content they do
not want persisted:

AgentCoreMemoryConfig(
    memory_id=...,
    session_id=...,
    actor_id=...,
    message_transform=lambda message: ...,  # Callable[[Message], Message] | None
)

A narrower declarative option would also solve the reported case, and may be easier to land:

AgentCoreMemoryConfig(..., persist_binary_content=False)

replacing document and image blocks (including blocks nested inside a toolResult) with a short text placeholder, so the restored history stays structurally valid for a subsequent model request.

Either shape would let callers keep session durability without the SDK deciding what belongs in memory.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

bedrock_agentcore/memory/integrations/strands/session_manager.py から始め、特に append_message と create_message を確認し、AgentCoreMemoryConfig がどのように永続化処理まで到達するかを追跡します。提案されている設定形式のうち適切なものを決定し、そのうえで、toolResult 内にネストされたものを含むドキュメントブロックと画像ブロックが、サイズの大きすぎる CreateEvent リクエストを引き起こさなくなっていること、また復元されたメッセージが有効なままであることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
aws, python
領域
api, backend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。