Skip to main content

hindsight-pydantic-ai

Persistent memory tools for Pydantic AI agents via Hindsight. Give your agents long-term memory with retain, recall, and reflect — all async-native with no thread-pool hacks.

Features

  • One Capability - HindsightMemory adds memory tools and auto-recalled memories to an agent in one object
  • Async-Native Tools - Uses Pydantic AI's async tool interface directly (aretain, arecall, areflect)
  • Memory Instructions - Auto-inject relevant memories into every agent run via instructions=[...]
  • Three Memory Tools - Retain (store), Recall (search), Reflect (synthesize) — include any combination
  • Simple Configuration - Configure once globally, or pass a client directly
  • Lightweight - Depends on pydantic-ai-slim to avoid pulling in all model providers
  • Pydantic AI 1.x and 2.x - Works with pydantic-ai-slim 1.71.0 and later, including 2.x

Installation

pip install hindsight-pydantic-ai

Quick Start

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

from hindsight_client import Hindsight
from hindsight_pydantic_ai import HindsightMemory
from pydantic_ai import Agent

client = Hindsight(base_url="https://api.hindsight.ai", api_key="hsk_...")

agent = Agent(
    "openai:gpt-4o",
    capabilities=[HindsightMemory(client=client, bank_id="user-123")],
)

result = await agent.run("What do you remember about my preferences?")
print(result.output)

HindsightMemory is a Pydantic AI capability: one object that gives the agent its memory tools and, on every run, recalls relevant memories into its instructions. By default the agent gets two tools:

  • hindsight_retain — Store information to long-term memory
  • hindsight_recall — Search long-term memory for relevant facts

Pass reflect=True to add hindsight_reflect, which synthesizes a reasoned answer from memories.

Self-hosting (local development)

If you're running Hindsight locally with ./scripts/dev/start-api.sh, point at your local server instead:

client = Hindsight(base_url="http://localhost:8888")

See the Hindsight installation guide for self-hosting setup.

Choosing What Memory Does

Flags on HindsightMemory pick the tools and turn auto-recall on or off. Bank, client, tags and budget are given once and apply to the tools and auto-recall alike:

memory = HindsightMemory(
    client=client,
    bank_id="user-123",
    retain=True,          # hindsight_retain tool
    recall=True,          # hindsight_recall tool
    reflect=False,        # hindsight_reflect tool
    auto_recall=True,     # recall memories into the instructions on every run
    recall_query="relevant context about the user",
    tags=["env:prod"],    # tags for stored memories
    recall_tags=["scope:global"],  # filter for recall and auto-recall
    budget="mid",
    max_tokens=4096,
)
agent = Agent("openai:gpt-4o", capabilities=[memory])

Building Blocks: Tools and Instructions

HindsightMemory is built from two functions you can also use on their own.

Tools Only (No Auto-Injection)

If you want the agent to decide when to use memory (rather than always injecting context):

agent = Agent(
    "openai:gpt-4o",
    tools=create_hindsight_tools(client=client, bank_id="user-123"),
)

Instructions Only (No Tools)

If you just want memories auto-injected without giving the agent explicit memory tools:

agent = Agent(
    "openai:gpt-4o",
    instructions=[memory_instructions(client=client, bank_id="user-123")],
)

Selecting Tools

Include only the tools you need:

tools = create_hindsight_tools(
    client=client,
    bank_id="user-123",
    include_retain=True,
    include_recall=True,
    include_reflect=False,  # Omit reflect
)

Global Configuration

Instead of passing a client to every call, configure once:

from hindsight_pydantic_ai import configure, create_hindsight_tools

configure(
    hindsight_api_url="https://api.hindsight.ai",  # Hindsight Cloud (default)
    api_key="your-api-key",       # Or set HINDSIGHT_API_KEY env var
    budget="mid",                  # Recall budget: low/mid/high
    max_tokens=4096,               # Max tokens for recall results
    tags=["env:prod"],             # Tags for stored memories
    recall_tags=["scope:global"],  # Tags to filter recall
    recall_tags_match="any",       # Tag match mode: any/all/any_strict/all_strict
)

# Now create tools without passing client — uses global config
tools = create_hindsight_tools(bank_id="user-123")

Per-Tool Overrides

Constructor arguments override global configuration:

tools = create_hindsight_tools(
    bank_id="user-123",
    budget="high",             # Override global budget
    max_tokens=8192,           # Override global max_tokens
    tags=["session:abc"],      # Override global tags
)

Memory Instructions Options

Customize what memories get injected and how:

instructions_fn = memory_instructions(
    client=client,
    bank_id="user-123",
    query="relevant context about the user",  # What to search for
    budget="low",                              # Keep it fast
    max_results=5,                             # Limit injected memories
    max_tokens=4096,                           # Max recall tokens
    prefix="Relevant memories:\n",             # Text before the memory list
    tags=["scope:global"],                     # Filter by tags
    tags_match="any",                          # Tag match mode
)

Configuration Reference

HindsightMemory

Parameter Default Description
bank_id required Hindsight memory bank ID
client None Pre-configured Hindsight client
hindsight_api_url None API URL (used if no client provided)
api_key None API key (used if no client provided)
retain True Add the retain (store) tool
recall True Add the recall (search) tool
reflect False Add the reflect (synthesize) tool
auto_recall True Recall memories into the instructions on every run
recall_query "relevant context about the user" Query auto-recall searches with
max_results 5 Maximum memories auto-recall adds
budget "mid" Recall/reflect budget level (low/mid/high)
max_tokens 4096 Maximum tokens for recall results
tags None Tags applied when storing memories
recall_tags None Tags to filter recall and auto-recall
recall_tags_match "any" Tag matching mode

create_hindsight_tools()

Parameter Default Description
bank_id required Hindsight memory bank ID
client None Pre-configured Hindsight client
hindsight_api_url None API URL (used if no client provided)
api_key None API key (used if no client provided)
budget "mid" Recall/reflect budget level (low/mid/high)
max_tokens 4096 Maximum tokens for recall results
tags None Tags applied when storing memories
recall_tags None Tags to filter when searching
recall_tags_match "any" Tag matching mode
include_retain True Include the retain (store) tool
include_recall True Include the recall (search) tool
include_reflect True Include the reflect (synthesize) tool

memory_instructions()

Parameter Default Description
bank_id required Hindsight memory bank ID
client None Pre-configured Hindsight client
hindsight_api_url None API URL (used if no client provided)
api_key None API key (used if no client provided)
query "relevant context about the user" Recall query for memory injection
budget "low" Recall budget level
max_results 5 Maximum memories to inject
max_tokens 4096 Maximum tokens for recall results
prefix "Relevant memories:\n" Text prepended before memory list
tags None Tags to filter recall results
tags_match "any" Tag matching mode

configure()

Parameter Default Description
hindsight_api_url Hindsight Cloud (https://api.hindsight.ai) Hindsight API URL
api_key HINDSIGHT_API_KEY env API key for authentication
budget "mid" Default recall budget level
max_tokens 4096 Default max tokens for recall
tags None Default tags for retain operations
recall_tags None Default tags to filter recall
recall_tags_match "any" Default tag matching mode
verbose False Enable verbose logging

Requirements

  • Python >= 3.10
  • pydantic-ai-slim >= 1.71.0 (1.x and 2.x are both tested in CI)
  • hindsight-client >= 0.4.0
  • A running Hindsight API server

License

MIT

Metadata

Release files for hindsight-pydantic-ai 0.5.0

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-pydantic-ai 0.5.0
File Size Uploaded Provenance Actions
hindsight_pydantic_ai-0.5.0.tar.gz 108.1 kB With provenance Details for hindsight_pydantic_ai-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hindsight-pydantic-ai 0.5.0
File Interpreter ABI Platform Actions
hindsight_pydantic_ai-0.5.0-py3-none-any.whl Python 3 none any Details for hindsight_pydantic_ai-0.5.0-py3-none-any.whl

Total release size: 117.8 kB

Release files / hindsight_pydantic_ai-0.5.0.tar.gz

Download URL hindsight_pydantic_ai-0.5.0.tar.gz
Size 108.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f7db7ee1dd091e42b81010cb617646aced2c579f28d44541d7dcd1bf862d5f9f
BLAKE2b-256 checksum
How to use checksums
1d3e78fb1aaaa21f7eb880c5776a756bf7c6e7578f6c97d89e14dee4a140811c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 2, 2026.

Transparency log

Release files / hindsight_pydantic_ai-0.5.0-py3-none-any.whl

Download URL hindsight_pydantic_ai-0.5.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ef0a7cfebdd6945e51854ba5ed5a6e079319c0d5b90a707315c42adc923258e
BLAKE2b-256 checksum
How to use checksums
071fd2499f1c2f2c25e7da82e04e054df931a8d8cdf1e5bb9d6c52deda5bb75b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 2, 2026.

Transparency log

Security for hindsight-pydantic-ai 0.5.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hindsight_pydantic_ai-0.5.0.tar.gz

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 Dec 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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