Skip to main content
Stamp a trust level on every memory write and gate recall on it, so untrusted channel input can never resurface as trusted context.

Quick Start

1

Simple Usage

A gateway callsite stamps inbound channel input as UNTRUSTED; recall gates on TRUSTED so it is fenced out.
2

Wiring the origin

Add a free-form origin label so the write is auditable by channel and session.

How It Works

Untrusted channel input is stamped at the gateway, then dropped at recall time before it can reach the model as trusted context. The trust field is structured metadata, not prose. A hostile group-chat message can put whatever text it wants into text, but it cannot forge metadata["trust"] = "trusted" — that value comes from the caller, not the message content.

Trust Levels

Three levels order as untrusted < trusted < system. Values are plain strings (str, Enum), so "trusted" / "untrusted" / "system" are accepted anywhere a MemoryTrust is. The gate fails closed in every ambiguous case:
  • Legacy records are trusted. A record with no metadata["trust"] field ranks as TRUSTED.
  • Unknown persisted trust labels fail closed (rank as UNTRUSTED).
  • A misspelled min_trust on the search call raises ValueError — the gate must fail loudly, never silently weaken.
  • metadata=None on a returned record does not crash recall — such records are treated as trusted.

API Reference

New keyword arguments on the core Memory methods. Existing callers are unaffected — when no keyword is passed, nothing changes. Defaults are unchanged: a store_* call without trust/origin is treated as trusted; a search_* call without min_trust returns everything, same as before.

Choosing What to Stamp

Pick a trust level by where the content came from.

Common Patterns

Gateway-bot store — stamp every inbound channel message untrusted with an origin.
Trusted-only recall — agents that must not act on channel-derived “facts” gate on TRUSTED.
Backward-compat callsite — no keywords passed, so nothing changes.

Best Practices

Any content originating from a third-party channel (group chat, DM, webhook) should be stamped trust=MemoryTrust.UNTRUSTED at the point it enters memory. Treat trusted as the exception, not the default, for channel-derived writes.
Recall paths that inject memory into a later, unrelated turn should call search_* with min_trust=MemoryTrust.TRUSTED. This is what fences out poisoned memory before it can resurface as trusted context.
origin is a free-form route/channel/session label (e.g. "telegram:group:123"). Use it to audit where a record came from — do not branch trust decisions on it. Trust decisions belong on the trust field.
A misspelled min_trust raises ValueError. Let it surface — do not wrap it in a fallback that silently weakens the gate. Failing loudly is the point.

Untrusted Request Fencing

Fence webhook and hook payloads as data, not instructions.

Prompt Injection Protection

Detect and neutralise injection attempts in inbound content.

Memory

Short-term, long-term, and entity memory overview.