Integration

Long-term memory for PydanticAI

PydanticAI is the Pydantic team's typed-agent framework: fully typed, fully validated, the kind of thing you'd expect from the Pydantic crew. `register_engram_tools(agent, bucket=...)` adds two memory tools to any `Agent` with one call. Types stay intact, and schemas are auto-generated from the tool functions.

Install

Three steps: sign up for an Engram API key, paste a BYOK LLM-provider key on /models, then drop the snippet below into PydanticAI.

Three steps to memory in your agent

  1. Sign up. Free, no card. You'll land on a Getting Started page that walks the next two steps.
  2. Add your LLM key. Engram is BYOK. Paste an OpenAI / Anthropic / Groq / Together / Fireworks key and we'll route every extraction and query call through your provider. You pay your provider directly. We never see your inference.
  3. Paste the snippet below into your agent and restart it. Use Authorization: Bearer <api-key>with the API key from your portal.

engram-pydantic-ai: durable memory for typed agents

One register_engram_tools(agent, bucket=...) call adds two tools to your PydanticAI Agent. Source: github.com/lumetra-io/engram-pydantic-ai.

  1. Install:
  2. Terminal
    pip install lumetra-engram pydantic-ai
  3. Vendor engram_pydantic_ai.py (~45 LOC) and export your API key:
  4. Terminal
    curl -fsSL https://raw.githubusercontent.com/lumetra-io/engram-pydantic-ai/main/engram_pydantic_ai.py -o engram_pydantic_ai.py
    export ENGRAM_API_KEY="<api-key>"
  5. Register the tools on your Agent:
  6. Python
    from pydantic_ai import Agent
    from engram_pydantic_ai import register_engram_tools
    
    agent = Agent("openai:gpt-4o-mini", instructions="""
    You are a helpful assistant with durable memory. Before answering
    questions about prior context, call engram_query_memory. When the
    user shares a fact worth remembering, call engram_store_memory.
    """)
    
    register_engram_tools(agent, bucket="my-agent")
    
    result = await agent.run("My name is Jacob, please remember that.")

What you can do once memory's wired in

  • Add memory to a strongly-typed agent without losing PydanticAI's validation guarantees
  • Set per-user buckets via `register_engram_tools(agent, bucket=f'user-{user_id}')` on every request
  • Use PydanticAI's `TestModel` for unit tests; Engram client roundtrips work the same way
  • Combine with PydanticAI's structured-output mode to store extracted Pydantic models as memories

FAQ

Does this work with `Agent.run()` and `Agent.run_sync()` both?

Yes. Both invoke the registered tools the same way. Async vs sync is independent of memory.

Where does the API key come from?

`ENGRAM_API_KEY` in the environment, like the other Python framework integrations. You don't pass it to `register_engram_tools` explicitly.

Can I use a different model for PydanticAI vs Engram's internal LLM calls?

Yes. PydanticAI's model is for the agent loop, while Engram's BYOK provider (configured at lumetra.io/models) handles extraction and synthesis inside Engram. They're independent.

Ship durable memory in PydanticAI today

Free tier: 10K memories and 50K retrievals per month. No credit card. Same Engram backend powers all 41 integrations, so memories you write from one client are immediately queryable from the rest.