From 9f956597ba35aff3f42348436704db9f4d3a68f3 Mon Sep 17 00:00:00 2001 From: "T.J Ariyawansa" Date: Wed, 11 Feb 2026 13:55:02 -0500 Subject: [PATCH] docs: update memory READMEs with metadata types and message batching Add documentation for EventMetadataFilter, StringValue, MetadataValue types and batch_size parameter with usage examples for message batching. --- src/bedrock_agentcore/memory/README.md | 3 ++ .../memory/integrations/strands/README.md | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/bedrock_agentcore/memory/README.md b/src/bedrock_agentcore/memory/README.md index 91927f3..de586dc 100644 --- a/src/bedrock_agentcore/memory/README.md +++ b/src/bedrock_agentcore/memory/README.md @@ -563,6 +563,8 @@ event = session.add_turns([ - **ActorSummary**: Actor information summary - **SessionSummary**: Session information summary - **MemoryRecord**: Long-term memory records +- **EventMetadataFilter**: Filter expression for querying events by metadata +- **StringValue**: Metadata value type for string data ### Configuration Classes @@ -570,5 +572,6 @@ event = session.add_turns([ - **MessageRole**: Enumeration of message roles (USER, ASSISTANT, TOOL, OTHER) - **MemoryStatus**: Memory resource status enumeration - **StrategyType**: Memory strategy type enumeration +- **MetadataValue**: Type alias for metadata value types (StringValue) For detailed API documentation, refer to the inline docstrings and type hints in the source code. diff --git a/src/bedrock_agentcore/memory/integrations/strands/README.md b/src/bedrock_agentcore/memory/integrations/strands/README.md index 5da1018..6186bf3 100644 --- a/src/bedrock_agentcore/memory/integrations/strands/README.md +++ b/src/bedrock_agentcore/memory/integrations/strands/README.md @@ -218,6 +218,7 @@ result = agent_with_tools("/path/to/image.png") - `session_id`: Unique identifier for the conversation session - `actor_id`: Unique identifier for the user/actor - `retrieval_config`: Dictionary mapping namespaces to RetrievalConfig objects +- `batch_size`: Number of messages to buffer before sending to AgentCore Memory (1-100, default: 1). A value of 1 sends immediately (no batching). ### RetrievalConfig Parameters @@ -238,6 +239,55 @@ https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory-strategies. - `/summaries/{actorId}/{sessionId}/`: Session-specific summaries +--- + +## Message Batching + +When `batch_size` is greater than 1, messages are buffered in memory and sent to AgentCore Memory +in a single API call once the buffer reaches the configured size. This reduces the number of API +requests in high-throughput conversations. + +> **Important:** When using `batch_size > 1`, you **must** use a `with` block or call `close()` +> when the session is complete. Otherwise, any buffered messages that have not yet reached the +> batch threshold will be lost. + +### Recommended: Context Manager + +```python +config = AgentCoreMemoryConfig( + memory_id=MEM_ID, + session_id=SESSION_ID, + actor_id=ACTOR_ID, + batch_size=10, # Buffer up to 10 messages before sending +) + +# The `with` block guarantees all buffered messages are flushed on exit +with AgentCoreMemorySessionManager(config, region_name='us-east-1') as session_manager: + agent = Agent( + system_prompt="You are a helpful assistant.", + session_manager=session_manager, + ) + agent("Hello!") + agent("Tell me about AWS") +# All remaining buffered messages are automatically flushed here +``` + +### Alternative: Explicit close() + +If you cannot use a `with` block, call `close()` manually: + +```python +session_manager = AgentCoreMemorySessionManager(config, region_name='us-east-1') +try: + agent = Agent( + system_prompt="You are a helpful assistant.", + session_manager=session_manager, + ) + agent("Hello!") +finally: + session_manager.close() # Flush any remaining buffered messages +``` + --- ## Important Notes @@ -255,3 +305,4 @@ https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory-strategies. - Use consistent `actor_id` for the same user across sessions - Configure appropriate `relevance_score` thresholds for your use case - Test with different `top_k` values to optimize retrieval performance +- When using `batch_size > 1`, always use a `with` block or call `close()` to ensure buffered messages are flushed before the session ends