Skip to content

Commit d4b3f63

Browse files
aurbacUriel Ramirez
andauthored
feat(02-use-cases): Long-term AgentCore Memory Facts (#1254)
* Long-term AgentCore Memory Facts * Lib folder updated to utils * Lib folder updated to utils * User name included --------- Co-authored-by: Uriel Ramirez <beralfon@amazon.com>
1 parent 49b49ba commit d4b3f63

30 files changed

Lines changed: 678 additions & 777 deletions

File tree

02-use-cases/video-games-sales-assistant/README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Deploying a Conversational Data Analyst Assistant Solution with Amazon Bedrock AgentCore
22

33
> [!IMPORTANT]
4-
> **🚀 Ready-to-Deploy Agent Web Application**: Use this reference solution to build other agent-powered web applications across different industries. Extend the agent capabilities by adding custom tools for specific industry workflows and adapt it to various business domains.
4+
> **🚀 Ready-to-Deploy Agent Web Application**: Use this reference solution to build agent-powered web applications across different industries. Adapt it to your business domain by adding custom agent tools for specific workflows. To accelerate development, use **[Kiro](https://kiro.dev/)** with its **[Powers](https://kiro.dev/powers/)** for Strands Agents SDK, Amazon Bedrock AgentCore, and AWS Amplify, along with the **[AWS CDK MCP Server](https://awslabs.github.io/mcp/servers/cdk-mcp-server)** for infrastructure guidance — so you can extend this solution **without starting from scratch**.
55
66
This solution provides a Generative AI application reference that allows users to interact with data through a natural language interface. The solution leverages **[Amazon Bedrock AgentCore](https://aws.amazon.com/bedrock/agentcore/)**, a managed service that enables you to deploy, run, and scale custom agent applications, along with the **[Strands Agents SDK](https://strandsagents.com/)** to build an agent that connects to a PostgreSQL database, providing data analysis capabilities through a Next.js web application built with **[AWS Amplify Gen 2](https://docs.amplify.aws/)**.
77

@@ -41,7 +41,10 @@ The AWS CDK stack deploys and configures the following managed services:
4141

4242
**Amazon Bedrock AgentCore Resources:**
4343
- **[AgentCore Runtime](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agents-tools-runtime.html)**: Provides the managed execution environment with invocation endpoints (`/invocations`) and health monitoring (`/ping`) for your agent instances
44-
- **[AgentCore Memory](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory.html)**: A fully managed service that gives AI agents the ability to remember, learn, and evolve through interactions by capturing events, transforming them into memories, and retrieving relevant context when needed
44+
- **[AgentCore Memory](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory.html)**: A fully managed service that gives AI agents the ability to remember, learn, and evolve through interactions. Configured with:
45+
- **Short-term memory (STM)**: Event-based conversation history scoped per user and session, providing immediate conversational context within a session
46+
- **Long-term memory (LTM)**: A semantic "Facts" strategy that asynchronously extracts knowledge from conversations and stores it in per-user namespaces (`/facts/{actorId}`). Facts persist across sessions and are retrieved via vector similarity search, enabling the agent to recall insights from previous conversations
47+
- **Observability**: Runtime application logs and memory extraction logs delivered to CloudWatch Logs, plus runtime traces to AWS X-Ray — all with 14-day retention
4548

4649
The AgentCore infrastructure handles all storage complexity and provides efficient retrieval without requiring developers to manage underlying infrastructure, ensuring continuity and traceability across agent interactions.
4750

@@ -57,10 +60,11 @@ All configuration values (database ARNs, secret ARNs, model ID, etc.) are passed
5760
### Amplify Deployment for the Front-End Application
5861

5962
- **Next.js Web Application (Amplify Gen 2)**: Delivers the user interface for the assistant
60-
- Uses Amazon Cognito (via Amplify Gen 2) for user authentication and IAM permissions — no manual IAM configuration needed
63+
- Uses Amazon Cognito (via Amplify Gen 2) for user authentication and IAM permissions — no manual IAM configuration needed. Each authenticated user's Cognito `sub` is used as the `actorId` for memory, ensuring isolated per-user memory namespaces
6164
- The application invokes Amazon Bedrock AgentCore for interacting with the assistant (client-side streaming)
6265
- For chart generation, the application directly invokes the Claude Haiku 4.5 model (client-side)
6366
- DynamoDB query results are fetched through a Next.js API route (server-side)
67+
- A Memory Facts panel lets users view the long-term knowledge extracted from their conversations by AgentCore Memory
6468

6569
### Strands Agent Features
6670

@@ -84,7 +88,7 @@ The **user interaction workflow** operates as follows:
8488
- The web application sends user business questions to the AgentCore Invoke (via client-side streaming)
8589
- The Strands Agent (powered by Claude Haiku 4.5) processes natural language and determines when to execute database queries
8690
- The agent's built-in tools execute SQL queries against the Aurora PostgreSQL database and formulate an answer to the question
87-
- AgentCore Memory captures session interactions and retrieves previous conversations for context
91+
- AgentCore Memory manages conversation context through the `AgentCoreMemorySessionManager` integration. STM provides conversation continuity within a session (scoped by `sessionId`), while LTM retrieves relevant facts from the `/facts/{actorId}` namespace across all past sessions for that user. LTM extraction is asynchronous (20-40 seconds after events are saved)
8892
- After the agent's streaming response completes, the raw data query results are fetched from DynamoDB through a Next.js API route to display both the answer and the corresponding records
8993
- For chart generation, the application invokes a model (powered by Claude Haiku 4.5) to analyze the agent's answer and raw data query results to generate the necessary data to render an appropriate chart visualization
9094

@@ -105,23 +109,29 @@ The deployment consists of two main steps:
105109

106110
The following images showcase a conversational experience analysis that includes: natural language answers, the reasoning process used by the LLM to generate SQL queries, the database records retrieved from those queries, and the resulting chart visualizations.
107111

108-
![Video Games Sales Assistant](./images/preview.png)
112+
- **AgentCore data analyst assistant welcome with Memory Facts access**
109113

110-
- **Conversational interface with an agent responding to user questions**
114+
![Welcome screen with AgentCore branding](./images/preview.png)
111115

112-
![Video Games Sales Assistant](./images/preview1.png)
116+
- **Long-term Memory Facts from AgentCore Memory**
113117

114-
- **Raw query results displayed in tabular format**
118+
![Memory Facts panel with extracted knowledge](./images/preview1.png)
115119

116-
![Video Games Sales Assistant](./images/preview2.png)
120+
- **Conversational agent with tool use and reasoning**
117121

118-
- **Chart visualization generated from the agent's answer and the data query results (created using [Apexcharts](https://apexcharts.com/))**.
122+
![Agent conversation with SQL query execution](./images/preview2.png)
119123

120-
![Video Games Sales Assistant](./images/preview3.png)
124+
- **Raw query results in tabular format**
121125

122-
- **Summary and conclusion derived from the data analysis conversation**
126+
![Query results displayed as data table](./images/preview3.png)
123127

124-
![Video Games Sales Assistant](./images/preview4.png)
128+
- **Auto-generated chart from answer and data**
129+
130+
![Chart visualization from query results](./images/preview4.png)
131+
132+
- **Conversation summary and data analysis conclusion**
133+
134+
![Summary and conclusion of analysis conversation](./images/preview5.png)
125135

126136
## Thank You
127137

02-use-cases/video-games-sales-assistant/amplify-video-games-sales-assistant-agentcore-strands/.env.local.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ AGENT_RUNTIME_ARN="arn:aws:bedrock-agentcore:us-east-1:000000000000:runtime/Your
2323
# The endpoint name for the agent (usually "DEFAULT")
2424
AGENT_ENDPOINT_NAME="DEFAULT"
2525

26-
# Number of conversation turns to keep in memory for context
27-
LAST_K_TURNS="10"
26+
# The AgentCore Memory ID for long-term memory
27+
MEMORY_ID=""
2828

2929
# ──────────────────────────────────────────────────────────────
3030
# Assistant UI Configuration

0 commit comments

Comments
 (0)