Skip to content

How AI agent memory works, from event to receipt

Send Statewave what happened. Your agent gets back the facts that matter, ranked and traced to their source.

API calls
3
Telemetry paths to Statewave
0
Container
1
Support eval criteria
8

Four steps from event to answer

One loop, from the raw event to the signed bundle your agent receives.

Record every event, untouched

Chats, tickets, tool calls and decisions land as immutable, append-only episodes under a subject. Nothing is ever overwritten.

POST /v1/episodes
  • Immutable
  • Idempotent ingest
  • One timeline per subject
account:northwind● Recording
“We moved our renewal to the 14th.”2 Sep
Duplicate charge on INV-2291 refunded9 Sep
Please send invoices to billing@14 Aug
Billing webhook retry fixed30 Sep
New

What Statewave remembers

Raw events go in, facts come out, and your agent gets a ranked bundle. Every fact links back to the event it came from.

1  Episode

What happened

The raw event, saved exactly as it arrived. It is never edited.

Slack#billing · 2 Sep
Heads up, we moved our renewal to the 14th.
Saved as-is7c1e04a2-…
2  Memory

What’s true now

A fact Statewave learns from the episode, with a link back to it.

Profile factActive
Plan renews on the 14th
Plan renews on the 1stReplaced
FromSlack, 2 Sep
3  Bundle

What your agent gets

The best facts for the task, ranked and packed to your token budget.

TaskWhen does our plan renew?
Plan renews on the 14th21.4
Resend invoices from the portal18.2
Onboarding notesDidn’t fit
Token budget1,284 / 2,000

Episodic vs semantic memory

Episodes are the timeline of what happened. Memories are what’s true because of it. Your agent gets both in one bundle.

Episodic the timeline
Semantic what’s true now
14 AugAsked for invoices by email
Prefers email
2 SepMoved renewal to the 14th
Renews on the 14th
9 SepDuplicate charge refunded
Had a duplicate charge refunded

Your data stays in your network by default

Everything lives in your Postgres, with no telemetry path back to us. Policies decide what each caller sees.

How Statewave governs memory →

What can leave, layer by layer

Storage, retrieval and the default compiler run on your infrastructure. Data only leaves if you plug in an outside model.

Your infrastructureNothing leaves
Postgres + pgvectorStorage
Retrieval and rankingLocal and deterministic
Heuristic compilerThe default
Episode batches →
LLM compilerOptional, via LiteLLM
Text to embed →
EmbeddingsOptional. Self-host to keep local
Governed by your agent
Your agent’s LLMWherever you host it

Fully local mode

The heuristic compiler plus a self-hosted embedding model, or text-only retrieval, means no Statewave-driven traffic leaves your network.

Heuristic compiler
Self-hosted embeddings
External LLM provider
Text-only retrieval fallback

Sensitivity labels

pii, financial and secret. Suggested at compile time, promoted by an operator.

  • Billing contact emailSuggested, then promoted
    pii.email
  • Annual contract valueSet by an operator
    financial
  • Admin API tokenSet by an operator
    secret

Declarative policies

YAML or JSON rules that deny or redact by label and caller type.

version: 1
rules:
  - id: deny-secrets-for-research-agent
    when:
      memory_has_any_label: [secret]
      caller_type: research-agent
    action: deny
  - id: redact-pii
    when:
      memory_has_any_label: [pii, pii.email]
    action: redact

Log-only, then enforce

Audit what a policy would do before you switch it on.

  • Admin API tokenresearch-agent
    Would deny
  • Billing contact emailsupport-agent
    Would redact
  • Plan renews on the 14thsupport-agent
    Allowed

Built for support agents first

Support is where Statewave is most tuned and most tested, against eight eval criteria.

Support agent workflow →

Handoff packs

The brief a human needs when an agent escalates, assembled in one call.

Handoff packaccount:northwind✓ Assembled
Customer summary

Northwind, annual plan. Renews on the 14th and prefers email for invoices.

Active issueWants the May invoice resent
Attempted steps✓Checked the billing portal✓Resent the invoice to the billing contact
Suggested next stepConfirm the invoice reached billing, then close the ticket
Health55/ 100Watch
SLA✓ First response 2m 25s1 resolution breach
Prior fixes

Duplicate INV-2291 refunded · 9 Sep

Renewal moved to the 14th · 2 Sep

Health scoring

Deterministic 0–100 with explainable factors.

  • Open issue−15
  • Repeated issue−20
  • SLA breach−10
55/ 100 · Watch

SLA tracking

First response, resolution and breaches.

  • First response2m 25s · target 5m
  • Resolution26h · target 24h

Repeat-issue detection

Surfaces the prior fix when a problem comes back.

May invoice not receivedNewDuplicate INV-2291 refunded · 9 SepSeen before

Runs on Postgres, works with any LLM

One container plus Postgres with pgvector. Compilation goes through LiteLLM, so OpenAI, Anthropic, Bedrock, Vertex, Mistral or a local model via Ollama all work.

Read the quickstart →
from statewave import StatewaveClient

with StatewaveClient("http://localhost:8100") as sw:
    sw.create_episode(
        subject_id="account:northwind",
        source="chat", type="conversation",
        payload={"messages": [{"role": "user", "content": "We moved our renewal to the 14th."}]},
    )
    sw.compile_memories("account:northwind")

    bundle = sw.get_context(
        subject_id="account:northwind",
        task="When does our plan renew?",
        max_tokens=2000, emit_receipt=True,
    )
    print(bundle.receipt_id)
    # 01J9ZK4T7M3QX8R2V6N0B5HCWD
Responsereceipt_id: 01J9ZK4T7M3QX8R2V6N0B5HCWD3 memories · 1 episode · 1,284 / 2,000 tokens · signed

Install

npx @statewavedev/statewaveCLI
pip install statewavePython
npm install @statewavedev/sdkTypeScript
docker compose up -dDocker

Requirements

Database
PostgreSQL 15+ with pgvector 0.4.2+
Runtime
Python 3.11+, CPU-only, no GPU
Image
linux/amd64 and arm64
Deploy
Docker Compose, Helm, Fly.io or Railway
Also included
  • OpenTelemetry
  • Webhooks
  • Multi-tenant
  • Apache-2.0

FAQ

How does a raw event become retrievable memory?

Three endpoints carry the loop. POST /v1/episodes appends an immutable, append-only event under a subject. POST /v1/memories/compile turns new episodes into typed memories with confidence, a validity window and source episode IDs. POST /v1/context returns a ranked, token-bounded bundle. Compilation is idempotent, so re-running it never duplicates.

What’s inside a context bundle?

Sections for the task, compiled facts, procedures, recent history and raw episodes, packed by score until the token budget is spent and never cut mid-item. Every row carries its kind, confidence, validity window, source episode IDs and supersession state.

How does Statewave decide which memories make the cut?

A fixed scoring model, not embedding distance alone. Kind priority, recency, task relevance and temporal validity add up to a composite score. Support workloads add session, urgency and repeat-issue signals. The top items are packed until the budget runs out.

Does Statewave need an LLM to work?

No. The default heuristic compiler runs fully locally, and retrieval can fall back to text matching. Add an LLM key to use LLM compilation and semantic search through LiteLLM, or point it at a self-hosted model to keep everything in your network.

What happens when two memories conflict?

Newer overlapping memories supersede older ones automatically. Each memory is marked active, superseded or tombstoned, superseded facts stay out of the bundle, and the status is recorded in receipts so you can see which version the agent used.

What is a state-assembly receipt?

An immutable record of one context call, signed when a signing key is configured. It carries an integrity hash of the exact bytes handed to the model, the policy in force and the source of every memory it used. Replay re-runs that retrieval against today’s memories and shows what would change.

Can I change the ranking weights?

Not today. The weights are fixed so ranking stays deterministic and reproducible. You can scope requests by subject, filter by memory kind, or modify the context assembler in your own self-hosted deployment.

Run it on your own data

Inspect every bundle your agent receives. Start with one command on your own infrastructure, with storage and retrieval in your own Postgres.

Need an SLA or an architecture review? Talk to us →
npx @statewavedev/statewave
Receipt01J9ZK4T7M3QX8R2…✓ Signed
Subject
account:northwind
Selected
3 memories · 1 episode
Budget
1,284 / 2,000 tokens
Policy
support-standard