> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memanto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Amazon Bedrock AgentCore

> Durable cross-session memory for Bedrock AgentCore Runtime agents using the memanto-agentcore adapter.

# Amazon Bedrock AgentCore Runtime + Memanto

<img src="https://mintcdn.com/memanto/Hkd0jQgagCbuAH-r/logo/integrations/aws-light.svg?fit=max&auto=format&n=Hkd0jQgagCbuAH-r&q=85&s=9d5a7cd9dc9ebf30d25879dffe597b83" alt="AWS" width="140" style={{marginBottom: "1.5rem"}} className="block dark:hidden" data-path="logo/integrations/aws-light.svg" />

<img src="https://mintcdn.com/memanto/Hkd0jQgagCbuAH-r/logo/integrations/aws-dark.svg?fit=max&auto=format&n=Hkd0jQgagCbuAH-r&q=85&s=63d576ef9aa9a2c18b336c342cc0373a" alt="AWS" width="140" style={{marginBottom: "1.5rem"}} className="hidden dark:block" data-path="logo/integrations/aws-dark.svg" />

[Amazon Bedrock AgentCore Runtime](https://docs.aws.amazon.com/bedrock/latest/userguide/agentcore.html) sessions are **ephemeral** — they terminate on inactivity and reprovision fresh environments. The **`memanto-agentcore`** package adds **durable memory** keyed to stable user identity (not `runtimeSessionId`), using the same recall → execute → retain loop as other Memanto framework adapters.

<CardGroup cols={2}>
  <Card title="Cross-session recall" icon="rotate">
    `before_turn()` runs semantic recall before your Bedrock call so a new runtime session still sees prior context.
  </Card>

  <Card title="Automatic retention" icon="floppy-disk">
    `after_turn()` stores each turn to Memanto (async by default so responses are not blocked).
  </Card>

  <Card title="Stable identity" icon="fingerprint">
    Memory is scoped to `tenant` + `user_id` + `agent_name` — never to ephemeral `sessionId`.
  </Card>

  <Card title="Fail-open recall" icon="shield">
    If Memanto is unavailable, recall returns empty context and your agent continues.
  </Card>
</CardGroup>

## How It Works

```text theme={null}
AgentCore invokes your handler(event)
        │
        ▼
  MemantoRuntimeAdapter.before_turn()  →  Memanto recall (Moorcheh)
        │
        ▼
  your agent_callable(payload, memory_context)  →  Bedrock / tools
        │
        ▼
  MemantoRuntimeAdapter.after_turn()   →  Memanto remember
```

Memanto does **not** replace AgentCore or Bedrock. You deploy your handler on AgentCore Runtime; the adapter only wraps each turn with memory I/O against [Moorcheh](https://moorcheh.ai).

Default Memanto **agent id** (memory namespace):

```text theme={null}
tenant-{tenant_id}-user-{user_id}-agent-{agent_name}
```

Only `[A-Za-z0-9_-]` are allowed in Memanto agent ids. Ids longer than 64 characters are replaced by a 64-character SHA-256 digest of `tenant` + `user_id` + `agent_name`, so they stay stable and unique.

## Prerequisites

* Python **3.10+**
* [Memanto](https://pypi.org/project/memanto/) and a [Moorcheh API key](https://console.moorcheh.ai/api-keys) (or on-prem Memanto backend configured)
* An AgentCore Runtime handler that receives a **trusted** `userId` (JWT, AgentCore identity header, or server-side auth — never client-supplied)
* AWS credentials and permissions for **deploying and invoking** AgentCore separately from Memanto

## Install

<Steps>
  <Step title="Install the adapter">
    ```bash theme={null}
    pip install memanto-agentcore
    ```

    This pulls in **`memanto`** automatically (PyPI dependency). Add `pip install memanto` only if you want to upgrade the core package independently of the adapter.
  </Step>

  <Step title="Configure Moorcheh">
    ```bash theme={null}
    export MOORCHEH_API_KEY=your_key_xxxxxxxxxxxxxxxxxx
    ```

    Or run `memanto` once to write `~/.memanto/.env`. On-prem users: `memanto config backend on-prem` and set the Moorcheh URL per [on-prem docs](/on-prem/server-deployment).
  </Step>
</Steps>

## Wrap your handler

```python theme={null}
import os
from memanto.cli.client.sdk_client import SdkClient
from memanto_agentcore import MemantoRuntimeAdapter, TurnContext

client = SdkClient(api_key=os.environ["MOORCHEH_API_KEY"])
adapter = MemantoRuntimeAdapter(client, agent_name="support-agent")


async def handler(event: dict) -> dict:
    context = TurnContext(
        runtime_session_id=event["sessionId"],
        user_id=event["userId"],  # validated identity — not from the client
        agent_name="support-agent",
        tenant_id=event.get("tenantId"),
        request_id=event.get("requestId"),
    )
    return await adapter.run_turn(
        context=context,
        payload={"prompt": event["prompt"]},
        agent_callable=run_my_agent,
    )


async def run_my_agent(payload: dict, memory_context: str) -> dict:
    prompt = payload["prompt"]
    if memory_context:
        prompt = f"Past context:\n{memory_context}\n\nCurrent request: {prompt}"
    output = await call_bedrock(prompt)  # your Bedrock integration
    return {"output": output}
```

### Lower-level hooks

```python theme={null}
memory_context = await adapter.before_turn(context, query=user_message)
result = await run_my_agent(payload, memory_context=memory_context)
await adapter.after_turn(context, result=result["output"], query=user_message)
```

## Identity rules

<Warning>
  **Never** use `runtimeSessionId` as the Memanto agent id. Sessions expire; memory must survive session churn.
</Warning>

Preferred identity sources:

1. Validated user ID from AgentCore JWT/OAuth (`sub`)
2. `X-Amzn-Bedrock-AgentCore-Runtime-User-Id` header
3. Application-supplied user ID in trusted server-side deployments

Custom namespace resolution:

```python theme={null}
from memanto_agentcore import MemantoRuntimeAdapter, TurnContext

def my_resolver(context: TurnContext) -> str:
    return f"acme_{context.user_id}_{context.agent_name}"

adapter = MemantoRuntimeAdapter(client, agent_id_resolver=my_resolver)
```

If `user_id` is missing, the default resolver raises `AgentResolutionError` (fail closed).

## Verify cross-session memory

Manual checklist (no AWS required for the Memanto side):

1. Run one turn for a test user and store a preference via `after_turn` or `run_turn`.
2. Use a **new** `runtimeSessionId` for the same `userId`.
3. Call `before_turn` — recalled context should include the stored detail.
4. Repeat with a second user — they must **not** see the first user's memory.

From the Memanto repo you can run the automated smoke script:

```bash theme={null}
python integrations/agentcore/scripts/smoke_test.py
```

CI publishes the adapter when you tag `integrations/agentcore/vX.Y.Z` on the [memanto](https://github.com/moorcheh-ai/memanto) repository.

## Shared memory across integrations

All Memanto integration packages use the same Moorcheh-backed agents when they share an `agent_id`:

| Integration                                                 | Package             | What it does                                                  |
| ----------------------------------------------------------- | ------------------- | ------------------------------------------------------------- |
| [`integrations/ag2`](/integrations/ag2)                     | `memanto-ag2`       | AG2 tool registration for remember / recall / answer.         |
| **AgentCore**                                               | `memanto-agentcore` | Recall/retain wrapper for Bedrock AgentCore Runtime handlers. |
| [`integrations/mcp`](/integrations/mcp)                     | `memanto-mcp`       | MCP server for Claude Desktop, Cursor, etc.                   |
| [`integrations/crewai`](/integrations/crewai)               | `crewai-memanto`    | CrewAI tools for multi-agent memory.                          |
| [`integrations/langgraph`](/integrations/langgraph)         | `langgraph-memanto` | LangGraph `BaseStore`, nodes, and tools.                      |
| [`integrations/hermes-agents`](/integrations/hermes-agents) | `hermes-memanto`    | Hermes memory provider.                                       |

## Next Steps

* [AgentCore integration source & README](https://github.com/moorcheh-ai/memanto/tree/main/integrations/agentcore)
* [AWS AgentCore Runtime docs](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/develop-agents.html)
* [Remember API](/api-reference/data/remember)
* [Recall API](/api-reference/search/recall)
