|
| 1 | +--- |
| 2 | +title: "Guide: Add AgentCore Runtime Memory with Hindsight" |
| 3 | +authors: [benfrank241] |
| 4 | +date: 2026-05-04T15:00:00Z |
| 5 | +tags: [how-to, agentcore, bedrock, memory] |
| 6 | +description: "Add AgentCore Runtime memory with Hindsight using the runtime adapter, stable user bank IDs, and recall plus retain hooks across session churn." |
| 7 | +image: /img/guides/guide-agentcore-memory-with-hindsight.png |
| 8 | +hide_table_of_contents: true |
| 9 | +--- |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +If you want **AgentCore Runtime memory with Hindsight**, the cleanest pattern is to wrap your Bedrock AgentCore handler with `HindsightRuntimeAdapter` and key memory to a stable user identity instead of the ephemeral runtime session ID. That gives AgentCore durable memory across session churn, which is the main gap teams hit when they move from demos to real user traffic. |
| 14 | + |
| 15 | +This matters because AgentCore Runtime sessions are intentionally short lived. Without an external memory layer, the agent can keep losing context whenever the runtime environment turns over. |
| 16 | + |
| 17 | +If you want the underlying reference open while you work, keep [the AgentCore Runtime integration docs](https://hindsight.vectorize.io/docs/integrations/agentcore), [the docs home](https://hindsight.vectorize.io/docs), [the quickstart guide](https://hindsight.vectorize.io/docs/quickstart), [Hindsight's recall API](https://hindsight.vectorize.io/docs/api/recall), and [Hindsight's retain API](https://hindsight.vectorize.io/docs/api/retain) nearby. |
| 18 | + |
| 19 | +<!-- truncate --> |
| 20 | + |
| 21 | +> **Quick answer** |
| 22 | +> |
| 23 | +> 1. Install the AgentCore Runtime integration or plugin. |
| 24 | +> 2. Point it at Hindsight Cloud or a local Hindsight API. |
| 25 | +> 3. Wire memory into your AgentCore Runtime runtime with a stable bank ID. |
| 26 | +> 4. Store one preference or project fact, then start a fresh run. |
| 27 | +> 5. Confirm that recall brings the earlier context back automatically. |
| 28 | +
|
| 29 | +## Why this setup works |
| 30 | + |
| 31 | +The runtime adapter gives you a clean recall, execute, retain loop around each turn. `before_turn()` fetches context, `run_turn()` wraps the whole exchange, and `after_turn()` stores the result. The critical design rule is simple: bank IDs must track stable user identity, not `runtimeSessionId`. |
| 32 | + |
| 33 | +## Prerequisites |
| 34 | + |
| 35 | +- An AgentCore Runtime handler that already receives a trusted user identifier |
| 36 | +- Python and `hindsight-agentcore` installed |
| 37 | +- A stable bank pattern, usually tenant plus user plus agent name |
| 38 | + |
| 39 | +## Step 1: Install the integration |
| 40 | + |
| 41 | +```bash |
| 42 | +pip install hindsight-agentcore |
| 43 | +``` |
| 44 | + |
| 45 | +## Step 2: Connect AgentCore Runtime to Hindsight |
| 46 | + |
| 47 | +```python |
| 48 | +import os |
| 49 | +from hindsight_agentcore import configure |
| 50 | + |
| 51 | +configure( |
| 52 | + hindsight_api_url="https://api.hindsight.vectorize.io", |
| 53 | + api_key=os.environ["HINDSIGHT_API_KEY"], |
| 54 | +) |
| 55 | +``` |
| 56 | + |
| 57 | +## Step 3: Wire memory into your runtime |
| 58 | + |
| 59 | +```python |
| 60 | +from hindsight_agentcore import HindsightRuntimeAdapter, TurnContext |
| 61 | + |
| 62 | +adapter = HindsightRuntimeAdapter(agent_name="support-agent") |
| 63 | + |
| 64 | +async def handler(event: dict) -> dict: |
| 65 | + context = TurnContext( |
| 66 | + runtime_session_id=event["sessionId"], |
| 67 | + user_id=event["userId"], |
| 68 | + agent_name="support-agent", |
| 69 | + tenant_id=event.get("tenantId"), |
| 70 | + request_id=event.get("requestId"), |
| 71 | + ) |
| 72 | + |
| 73 | + result = await adapter.run_turn( |
| 74 | + context=context, |
| 75 | + payload={"prompt": event["prompt"]}, |
| 76 | + agent_callable=run_my_agent, |
| 77 | + ) |
| 78 | + return result |
| 79 | +``` |
| 80 | + |
| 81 | +The default bank format follows `tenant:{tenant_id}:user:{user_id}:agent:{agent_name}`. That is exactly what you want for durable memory across Runtime session churn. |
| 82 | + |
| 83 | +## Step 4: Choose the right bank strategy |
| 84 | + |
| 85 | +Do not key memory to `runtimeSessionId`. That ID is ephemeral and will fragment memory immediately. Use a stable identity that survives across sessions, such as tenant plus user plus agent name. If several agent personas share the same account, give each persona its own suffix so memory stays coherent. |
| 86 | + |
| 87 | +## Step 5: Verify that memory is working |
| 88 | + |
| 89 | +1. Run one turn for a test user and store a preference or account detail. |
| 90 | +2. Trigger another Runtime session for the same user. |
| 91 | +3. Ask for the earlier detail and confirm that the adapter recalls it before the agent answers. |
| 92 | +4. Repeat the test for a second user to confirm that banks stay isolated. |
| 93 | + |
| 94 | +If the second run can answer with details from the first run, your setup is working. If it cannot, turn on debug logging, check the configured bank ID, and confirm that the retain call actually completed. |
| 95 | + |
| 96 | +## Common mistakes |
| 97 | + |
| 98 | +- Using a client supplied identifier that is not trusted, which can mix memory between users |
| 99 | +- Keying the bank to `runtimeSessionId`, which breaks continuity by design |
| 100 | +- Turning on reflect everywhere when recall would be faster and simpler for most turns |
| 101 | + |
| 102 | +## FAQ |
| 103 | + |
| 104 | +### Why should I avoid runtimeSessionId for memory? |
| 105 | + |
| 106 | +Because AgentCore Runtime sessions are ephemeral. A memory bank tied to that ID dies with the session pattern you are trying to outgrow. |
| 107 | + |
| 108 | +### When should I use reflect mode? |
| 109 | + |
| 110 | +Use reflect selectively for harder reasoning steps. Keep normal turns on recall mode for lower latency. |
| 111 | + |
| 112 | +### Can retention run in the background? |
| 113 | + |
| 114 | +Yes. The integration supports async retention so user turns do not have to wait for retain to finish. |
| 115 | + |
| 116 | +## Next Steps |
| 117 | + |
| 118 | +- Start with [Hindsight Cloud](https://hindsight.vectorize.io) if you want a hosted memory backend |
| 119 | +- Read [the full Hindsight docs](https://hindsight.vectorize.io/docs) |
| 120 | +- Follow [the quickstart guide](https://hindsight.vectorize.io/docs/quickstart) |
| 121 | +- Review [Hindsight's recall API](https://hindsight.vectorize.io/docs/api/recall) |
| 122 | +- Review [Hindsight's retain API](https://hindsight.vectorize.io/docs/api/retain) |
| 123 | +- Compare a related workflow in [Agno persistent memory](https://hindsight.vectorize.io/blog/agno-persistent-memory) |
0 commit comments