Skip to content

Commit efea9d4

Browse files
authored
docs: update memory READMEs with metadata types and message batching (aws#264)
Add documentation for EventMetadataFilter, StringValue, MetadataValue types and batch_size parameter with usage examples for message batching.
1 parent 208cc14 commit efea9d4

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/bedrock_agentcore/memory/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,15 @@ event = session.add_turns([
563563
- **ActorSummary**: Actor information summary
564564
- **SessionSummary**: Session information summary
565565
- **MemoryRecord**: Long-term memory records
566+
- **EventMetadataFilter**: Filter expression for querying events by metadata
567+
- **StringValue**: Metadata value type for string data
566568

567569
### Configuration Classes
568570

569571
- **RetrievalConfig**: Configuration for memory retrieval operations
570572
- **MessageRole**: Enumeration of message roles (USER, ASSISTANT, TOOL, OTHER)
571573
- **MemoryStatus**: Memory resource status enumeration
572574
- **StrategyType**: Memory strategy type enumeration
575+
- **MetadataValue**: Type alias for metadata value types (StringValue)
573576

574577
For detailed API documentation, refer to the inline docstrings and type hints in the source code.

src/bedrock_agentcore/memory/integrations/strands/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ result = agent_with_tools("/path/to/image.png")
218218
- `session_id`: Unique identifier for the conversation session
219219
- `actor_id`: Unique identifier for the user/actor
220220
- `retrieval_config`: Dictionary mapping namespaces to RetrievalConfig objects
221+
- `batch_size`: Number of messages to buffer before sending to AgentCore Memory (1-100, default: 1). A value of 1 sends immediately (no batching).
221222

222223
### RetrievalConfig Parameters
223224

@@ -238,6 +239,55 @@ https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory-strategies.
238239
- `/summaries/{actorId}/{sessionId}/`: Session-specific summaries
239240

240241

242+
---
243+
244+
## Message Batching
245+
246+
When `batch_size` is greater than 1, messages are buffered in memory and sent to AgentCore Memory
247+
in a single API call once the buffer reaches the configured size. This reduces the number of API
248+
requests in high-throughput conversations.
249+
250+
> **Important:** When using `batch_size > 1`, you **must** use a `with` block or call `close()`
251+
> when the session is complete. Otherwise, any buffered messages that have not yet reached the
252+
> batch threshold will be lost.
253+
254+
### Recommended: Context Manager
255+
256+
```python
257+
config = AgentCoreMemoryConfig(
258+
memory_id=MEM_ID,
259+
session_id=SESSION_ID,
260+
actor_id=ACTOR_ID,
261+
batch_size=10, # Buffer up to 10 messages before sending
262+
)
263+
264+
# The `with` block guarantees all buffered messages are flushed on exit
265+
with AgentCoreMemorySessionManager(config, region_name='us-east-1') as session_manager:
266+
agent = Agent(
267+
system_prompt="You are a helpful assistant.",
268+
session_manager=session_manager,
269+
)
270+
agent("Hello!")
271+
agent("Tell me about AWS")
272+
# All remaining buffered messages are automatically flushed here
273+
```
274+
275+
### Alternative: Explicit close()
276+
277+
If you cannot use a `with` block, call `close()` manually:
278+
279+
```python
280+
session_manager = AgentCoreMemorySessionManager(config, region_name='us-east-1')
281+
try:
282+
agent = Agent(
283+
system_prompt="You are a helpful assistant.",
284+
session_manager=session_manager,
285+
)
286+
agent("Hello!")
287+
finally:
288+
session_manager.close() # Flush any remaining buffered messages
289+
```
290+
241291
---
242292

243293
## Important Notes
@@ -255,3 +305,4 @@ https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory-strategies.
255305
- Use consistent `actor_id` for the same user across sessions
256306
- Configure appropriate `relevance_score` thresholds for your use case
257307
- Test with different `top_k` values to optimize retrieval performance
308+
- When using `batch_size > 1`, always use a `with` block or call `close()` to ensure buffered messages are flushed before the session ends

0 commit comments

Comments
 (0)