Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4526,6 +4526,11 @@ jobs:
needs.detect-changes.outputs.ci == 'true')
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
# uv.lock pins 1.x; the oldest supported (1.71.0) and 2.x are overlaid on top of it.
pydantic-ai: ["locked", "pydantic-ai-slim==1.71.0", "pydantic-ai-slim>=2,<3"]

steps:
- uses: actions/checkout@v6
Expand Down Expand Up @@ -4553,7 +4558,14 @@ jobs:

- name: Run tests
working-directory: ./hindsight-integrations/pydantic-ai
run: uv run pytest tests -v
env:
PYDANTIC_AI: ${{ matrix.pydantic-ai }}
run: |
if [ "$PYDANTIC_AI" = "locked" ]; then
uv run pytest tests -v
else
uv run --with "$PYDANTIC_AI" pytest tests -v
fi

test-hermes-integration:
needs: [detect-changes]
Expand Down
63 changes: 54 additions & 9 deletions hindsight-docs/docs-integrations/pydantic-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ Persistent memory tools for [Pydantic AI](https://ai.pydantic.dev/) agents via H

## 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

Expand All @@ -32,28 +34,26 @@ pip install hindsight-pydantic-ai

```python
from hindsight_client import Hindsight
from hindsight_pydantic_ai import create_hindsight_tools, memory_instructions
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",
tools=create_hindsight_tools(client=client, bank_id="user-123"),
instructions=[memory_instructions(client=client, bank_id="user-123")],
capabilities=[HindsightMemory(client=client, bank_id="user-123")],
)

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

The agent now has three tools it can call:
`HindsightMemory` is a Pydantic AI [capability](https://ai.pydantic.dev/capabilities/): 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
- **`hindsight_reflect`** — Synthesize a reasoned answer from memories

The `memory_instructions` callable automatically recalls relevant memories and injects them into the system prompt on every run.
Pass `reflect=True` to add **`hindsight_reflect`**, which synthesizes a reasoned answer from memories.

### Self-hosting (local development)

Expand All @@ -65,7 +65,32 @@ client = Hindsight(base_url="http://localhost:8888")

See the [installation guide](/developer/installation) for self-hosting setup.

## Tools Only (No Auto-Injection)
## 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:

```python
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:

Expand All @@ -76,7 +101,7 @@ agent = Agent(
)
```

## Instructions Only (No Tools)
### Instructions Only (No Tools)

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

Expand All @@ -87,7 +112,7 @@ agent = Agent(
)
```

## Selecting Tools
### Selecting Tools

Include only the tools you need:

Expand Down Expand Up @@ -155,6 +180,26 @@ instructions_fn = memory_instructions(

## API 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 |
Expand Down
2 changes: 1 addition & 1 deletion hindsight-docs/src/data/integrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
{
"id": "pydantic-ai",
"name": "Pydantic AI",
"description": "Integrate Hindsight memory into Pydantic AI agents with a simple dependency injection pattern.",
"description": "Give Pydantic AI agents long-term memory with one capability: retain, recall and reflect tools, plus relevant memories recalled into every run.",
"type": "official",
"by": "hindsight",
"category": "framework",
Expand Down
2 changes: 1 addition & 1 deletion hindsight-docs/src/lib/integration-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const INTEGRATION_GROUPS: IntegrationGroup[] = [
{
label: 'Frameworks & SDKs',
categories: ['framework'],
previewIds: ['langgraph', 'vercel-ai-sdk', 'vercel-chat', 'eve', 'crewai'],
previewIds: ['langgraph', 'vercel-ai-sdk', 'vercel-chat', 'pydantic-ai', 'eve', 'crewai'],
},
// Chat apps, note-taking, voice platforms, MCP gateways — and the catch-all: an entry whose
// category isn't listed above lands here rather than silently vanishing from the sidebar.
Expand Down
65 changes: 55 additions & 10 deletions hindsight-integrations/pydantic-ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ Persistent memory tools for Pydantic AI agents via Hindsight. Give your agents l

## 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

Expand All @@ -22,28 +24,26 @@ pip install hindsight-pydantic-ai

```python
from hindsight_client import Hindsight
from hindsight_pydantic_ai import create_hindsight_tools, memory_instructions
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",
tools=create_hindsight_tools(client=client, bank_id="user-123"),
instructions=[memory_instructions(client=client, bank_id="user-123")],
capabilities=[HindsightMemory(client=client, bank_id="user-123")],
)

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

The agent now has three tools it can call:
`HindsightMemory` is a Pydantic AI [capability](https://ai.pydantic.dev/capabilities/): 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
- **`hindsight_reflect`** — Synthesize a reasoned answer from memories

The `memory_instructions` callable automatically recalls relevant memories and injects them into the system prompt on every run.
Pass `reflect=True` to add **`hindsight_reflect`**, which synthesizes a reasoned answer from memories.

### Self-hosting (local development)

Expand All @@ -55,7 +55,32 @@ client = Hindsight(base_url="http://localhost:8888")

See the [Hindsight installation guide](https://hindsight.ai/oss/developer/installation) for self-hosting setup.

## Tools Only (No Auto-Injection)
## 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:

```python
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):

Expand All @@ -66,7 +91,7 @@ agent = Agent(
)
```

## Instructions Only (No Tools)
### Instructions Only (No Tools)

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

Expand All @@ -77,7 +102,7 @@ agent = Agent(
)
```

## Selecting Tools
### Selecting Tools

Include only the tools you need:

Expand Down Expand Up @@ -145,6 +170,26 @@ instructions_fn = memory_instructions(

## 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 |
Expand Down Expand Up @@ -194,7 +239,7 @@ instructions_fn = memory_instructions(
## Requirements

- Python >= 3.10
- pydantic-ai-slim >= 1.0.0
- 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
Basic usage::

from hindsight_client import Hindsight
from hindsight_pydantic_ai import create_hindsight_tools, memory_instructions
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",
tools=create_hindsight_tools(client=client, bank_id="user-123"),
instructions=[memory_instructions(client=client, bank_id="user-123")],
capabilities=[HindsightMemory(client=client, bank_id="user-123")],
)

result = await agent.run("What do you remember about my preferences?")
Expand All @@ -27,7 +26,7 @@
reset_config,
)
from .errors import HindsightError
from .tools import create_hindsight_tools, memory_instructions
from .tools import HindsightMemory, create_hindsight_tools, memory_instructions

__version__ = "0.1.0"

Expand All @@ -37,6 +36,7 @@
"reset_config",
"HindsightPydanticAIConfig",
"HindsightError",
"HindsightMemory",
"create_hindsight_tools",
"memory_instructions",
]
Loading