DEV Community

Cover image for AWS Strands - AgentCore Shorterm Memory Integration
Vimal Venugopal
Vimal Venugopal

Posted on

AWS Strands - AgentCore Shorterm Memory Integration

Prerequisites

Prior Knowledge of

  • Strands Agents
  • Python 3.1x
  • AWS Credentials with access to Bedrock and related components
  • Access to Anthropic Claude Haiku 4.5
  • AgentCore Short-term Memory with MemoryManager, AgentInitializedEvent and MessageAddedEvent hooks

We will use MemoryManager to store short term conversational history and retrieve n number of conversations
This is a simple AWS Strands agents that uses a web search tool to query and store the results.
Initialize agents with conversation history using session management
Can use this to help Migrate from MemoryClient to MemoryManager architecture

This example demonstrates Short Term Memory of AgentCore. Below is the high level architecture.

Architecture

Project Structure

ProjectStructure

STEP1: Requirements.txt - Packages Needed

Packages Needed

STEP2: Packages Installation

Packages Install

STEP3: Import all packages

Import

STEP4: Memory Manager Initialization(Memory_Manager.py)

Memory_Manager

STEP5: Memory SessionManager Initialization(Memory_Manager.py)

SessionManager

STEP6.1: MemoryHookProvider Initialization - Part 1
MemoryHookProvider

STEP6.2: MemoryHookProvider Initialization - Part 2
MemoryHookProvider

STEP7: Agent Tools Definition (Agent_Tools.py)
Agent Tools

STEP8: Agent Initialization (Personal_Agent.py)

Agent Initialization

Agent Initialization

AGENT Testing in Terminal

AGENT TESTING

AGENT TESTING-1

AGENT TESTING-2

AGENT TESTING-3

*Using Streamlit we can display the same history in Web App
*

Summary
This tutorial showed how to build a personal agent using both MemorySessionManager and MemorySession.

You've learned:

MemorySessionManager: High-level manager for memory operations across multiple sessions
MemorySession: Session-specific interface that eliminates repetitive parameter passing. Using MemorySession removes the need to pass actor_id/session_id to every method
Type Safety: Session is bound to specific actor/session at creation time
Better Encapsulation: Session-specific operations are contained within the session object
Memory Hooks: Agent hooks can work with the session-based architecture
Conversation Continuity: Maintaining short-term memory functionality with MemoryManager & MemorySession

Key Benefits of MemorySession:
Simplified API: No need to pass actor_id/session_id to every method call
Pre-configured Context: Session is bound to specific actor/session at creation
Consistent Interface: All session operations use the same pre-configured context

Top comments (0)