This directory contains tools for integrating MemMachine memory operations into AWS Strands Agent SDK workflows.
MemMachine provides memory tools that can be integrated into AWS Strands Agent SDK to enable AI agents with persistent memory capabilities. This allows agents to remember past interactions, user preferences, and context across multiple sessions.
Ensure you have the required dependencies:
pip install memmachine
# If using AWS Strands Agent SDK
pip install strands-agents bedrock-agentcoreAWS Strands Agent SDK requires AWS credentials to access AWS Bedrock services. Configure credentials using one of these methods:
-
AWS CLI (recommended):
aws configure
-
Environment variables:
export AWS_ACCESS_KEY_ID=your_access_key export AWS_SECRET_ACCESS_KEY=your_secret_key export AWS_REGION=us-east-1
-
IAM role (if running on EC2/ECS/Lambda)
-
AWS credentials file:
~/.aws/credentials
The tools can be configured via environment variables or directly in code:
| Variable | Description | Default |
|---|---|---|
MEMORY_BACKEND_URL |
URL of the MemMachine backend service | http://localhost:8080 |
MEMORY_API_KEY |
API key for MemMachine authentication | None |
STRANDS_GROUP_ID |
Group identifier for the demo | strands_group |
STRANDS_AGENT_ID |
Agent identifier for the demo | strands_agent |
STRANDS_USER_ID |
User identifier for the demo | default_user |
STRANDS_SESSION_ID |
Session identifier for the demo | Auto-generated |
from tool import get_memmachine_tools, create_tool_handler
# Initialize tools
tools, tool_schemas = get_memmachine_tools(
base_url="http://localhost:8080",
group_id="my_group",
agent_id="my_agent",
user_id="user123",
)
# Get tool schemas for Strands Agent SDK
# tool_schemas can be passed to your Strands Agent configuration
# Create tool handler for executing tool calls
tool_handler = create_tool_handler(tools)
# Use tools directly
result = tools.add_memory(
content="User prefers Python for backend development",
metadata={"category": "preference"}
)
search_result = tools.search_memory(
query="What does the user prefer for development?",
limit=5
)from strands import Agent
from tool import get_memmachine_tools, create_tool_handler
from strands_tools import set_tools_instance
import sys
import os
# Initialize MemMachine tools
tools, tool_schemas = get_memmachine_tools(
base_url="http://localhost:8080",
group_id="my_group",
agent_id="my_agent",
user_id="user123",
)
# Set up tools for Strands SDK
script_dir = os.path.dirname(os.path.abspath(__file__))
if script_dir not in sys.path:
sys.path.insert(0, script_dir)
from strands_tools import add_memory, search_memory, get_context
set_tools_instance(tools)
# Create tool handler for manual execution
tool_handler = create_tool_handler(tools)
# Create Strands Agent with function objects
agent = Agent(
tools=[add_memory, search_memory, get_context], # Pass function objects
system_prompt="You are a helpful assistant with memory capabilities."
)
# The agent can now use the memory tools automatically
response = agent("Remember that I like Python programming")
print(response)
# Later, the agent can recall memories
response = agent("What programming language do I prefer?")
print(response)
# Cleanup
tools.close()Note: AWS credentials must be configured for the Strands Agent to work. See AWS Credentials Configuration below.
from tool import MemMachineTools
# Initialize tools
tools = MemMachineTools(
base_url="http://localhost:8080",
group_id="my_group",
agent_id="my_agent",
user_id="user123",
)
# Add a memory
result = tools.add_memory(
content="User mentioned they have a meeting tomorrow at 10 AM",
metadata={"type": "reminder", "time": "10:00 AM"}
)
# Search memories
search_result = tools.search_memory(
query="What meetings does the user have?",
limit=5
)
# Get context
context = tools.get_context()
print(f"Current context: {context}")
# Cleanup
tools.close()Store important information about the user or conversation into memory.
Parameters:
content(required): The content to store in memoryuser_id(optional): User ID overrideepisode_type(optional): Type of episode (default: "text")metadata(optional): Additional metadata dictionary
Returns:
- Dictionary with
status,message, andcontentfields
Retrieve relevant context, memories, or profile for a user.
Parameters:
query(required): Search query stringuser_id(optional): User ID overridelimit(optional): Maximum number of results (default: 5, max: 20)
Returns:
- Dictionary with
status,results, andsummaryfields
Get the current memory context configuration.
Parameters:
user_id(optional): User ID override
Returns:
- Dictionary containing
group_id,agent_id,user_id, andsession_id
- MemMachine server running (default: http://localhost:8080)
- Python 3.8+
- AWS Strands Agent SDK (for full integration)
- Configure AWS Credentials: Set up AWS credentials (see above)
- Start MemMachine Server: Ensure MemMachine server is running
- Initialize Tools: Create MemMachine tools with your configuration
- Set Up Tool Functions: Import and configure
strands_toolsfunctions - Create Agent: Pass function objects to Strands Agent
- Use Agent: The agent automatically calls tools when needed
- Cleanup: Close the client when done
All tool methods return dictionaries with a status field:
"success": Operation completed successfully"error": Operation failed (checkmessagefield for details)
- The tools automatically manage memory sessions
- Memories are stored in both episodic (short-term) and profile (long-term) memory
- Search queries are embedded and compared semantically
- Tool schemas follow AWS Bedrock tool specification format