Skip to main content

hindsight-agentcore

Persistent memory for Amazon Bedrock AgentCore Runtime agents using Hindsight.

AgentCore Runtime sessions are explicitly ephemeral — they terminate on inactivity and reprovision fresh environments. This package adds durable cross-session memory so agents remember users, decisions, and learned patterns across any number of Runtime sessions.

How It Works

AgentCore Runtime invocation
        │
        ▼
   before_turn()         ← Recall relevant memories from Hindsight
        │
        ▼
  Agent executes          ← Prompt enriched with prior context
        │
        ▼
   after_turn()          ← Retain output to Hindsight (async)

Memory is keyed to stable user identity — not the runtimeSessionId. Banks survive session churn.

Default bank format:

tenant:{tenant_id}:user:{user_id}:agent:{agent_name}

Installation

pip install hindsight-agentcore

Quick Start

✨ Recommended: Hindsight Cloud — free tier, no self-hosting required. Sign up and grab an API key in under a minute.

import os
from hindsight_agentcore import HindsightRuntimeAdapter, TurnContext, configure

configure(
    hindsight_api_url="https://api.hindsight.vectorize.io",
    api_key=os.environ["HINDSIGHT_API_KEY"],
)

adapter = HindsightRuntimeAdapter(agent_name="support-agent")


# Your AgentCore Runtime handler
async def handler(event: dict) -> dict:
    context = TurnContext(
        runtime_session_id=event["sessionId"],
        user_id=event["userId"],       # from validated auth — never client-supplied
        agent_name="support-agent",
        tenant_id=event.get("tenantId"),
        request_id=event.get("requestId"),
    )

    result = await adapter.run_turn(
        context=context,
        payload={"prompt": event["prompt"]},
        agent_callable=run_my_agent,
    )
    return result


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)
    return {"output": output}

Lower-Level Hooks

# Manual recall → execute → retain
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)

Retrieval Modes

Recall (default)

Fast multi-strategy retrieval (semantic + keyword + graph + temporal):

from hindsight_agentcore import RecallPolicy

adapter = HindsightRuntimeAdapter(
    recall_policy=RecallPolicy(mode="recall", budget="mid", max_tokens=1500)
)

Reflect

LLM-synthesized context for complex reasoning tasks:

adapter = HindsightRuntimeAdapter(
    recall_policy=RecallPolicy(mode="reflect")
)

Use reflect selectively — it's slower. Reserve it for explicit planning steps or routing decisions.

Async Retention

By default, after_turn() fires retention as a background task — the user turn is never delayed:

configure(retain_async=True)   # default
configure(retain_async=False)  # await retention before returning

Async and Long-Running Workflows

For jobs spanning multiple Runtime sessions, retain at start and completion:

# Task start
await adapter.after_turn(
    context,
    result="Started QBR analysis for Acme Corp",
    query=task_description,
)

# ... long-running work across potentially multiple sessions ...

# Task completion
await adapter.after_turn(
    context,
    result=f"Completed QBR analysis. Finding: {summary}",
    query=task_description,
)

Identity and Auth

Never use runtimeSessionId as the bank ID. Sessions expire. Memory must survive session churn.

Preferred identity sources (in order):

  1. Validated user ID from AgentCore JWT/OAuth context
  2. X-Amzn-Bedrock-AgentCore-Runtime-User-Id header
  3. Application-supplied user ID in trusted server-side deployments
context = TurnContext(
    runtime_session_id=event["sessionId"],
    user_id=jwt_claims["sub"],         # stable identity from validated token
    agent_name="support-agent",
    tenant_id=jwt_claims.get("tenant"),
)

Configuration Reference

Option Env Variable Default Description
hindsight_api_url HINDSIGHT_API_URL Hindsight Cloud Hindsight server URL
api_key HINDSIGHT_API_KEY — API key for Hindsight Cloud
recall_budget — "mid" Search depth: low, mid, high
recall_max_tokens — 1500 Max tokens recalled
retain_async — True Non-blocking retention
timeout — 15.0 HTTP timeout in seconds
tags — [] Tags applied to all retained memories
verbose — False Log memory operations

Custom Bank Resolution

Override the default tenant:user:agent format:

from hindsight_agentcore import TurnContext

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

adapter = HindsightRuntimeAdapter(bank_resolver=my_resolver)

Security rule: The resolver must fail closed (BankResolutionError) rather than leak memory across users when identity is missing.

Failure Modes

Failure Behavior
Hindsight unavailable before_turn() returns "", agent continues
Recall timeout Returns "", agent continues
Retain failure Logged as warning, user turn unaffected
Bad bank resolution Fails closed — no cross-user memory leakage

Deployment

Hindsight Cloud — sign up, set hindsight_api_url to your Cloud endpoint.

Self-hosted on AWS — run Hindsight on ECS/EKS with RDS PostgreSQL (pgvector). Network path stays in your AWS account.

Requirements

  • Python 3.10+
  • hindsight-client>=0.4.0

Metadata

Release files for hindsight-agentcore 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hindsight-agentcore 0.1.3
File Size Uploaded
hindsight_agentcore-0.1.3.tar.gz 105.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hindsight-agentcore 0.1.3
File Interpreter ABI Platform
hindsight_agentcore-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 117.8 kB

Release files / hindsight_agentcore-0.1.3.tar.gz

Download URL hindsight_agentcore-0.1.3.tar.gz
Size 105.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c2a8d5d8e0445d0a78b0314b5a06469cc9d5f14af47d5afc4ea53b26f6ea85df
BLAKE2b-256 checksum
How to use checksums
3f8ba6875d380a876eb9ff7b2c47bced5f46261103d7e2c5154fb24f60eece7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / hindsight_agentcore-0.1.3-py3-none-any.whl

Download URL hindsight_agentcore-0.1.3-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c78e6495754c2e4af6343bcdf6e3e3b0e09e0ace016278ec26f00ba77e88ef2
BLAKE2b-256 checksum
How to use checksums
6fd17e049edd0e823dd82bdb57eea198af1421ee690704e29c80c097a7e62318
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page