All docs
Examples
Hosted workflow

RAG app with governed memory

Store memory facts that can be approved, retired, replayed, or forgotten.

Problem

RAG apps need memory, but bad facts and stale preferences silently leak into future runs.

Why app glue gets messy

Typical vector memory has weak provenance, weak lifecycle controls, and poor operator review.

How Synapsor helps

Synapsor memory facts are scoped, evidenced, approved, retired, and forgotten through database primitives.

Value sources

Example names and seed ids are developer-defined. SESSION values are set by your backend. ARG values come from the SDK/HTTP call. Handles such as wrp://..., evidence://..., and agent-run://... are returned by Synapsor and should be stored for audit/replay.

Read the value-source guide
Expected outcome

The agent recalls approved memory only and operators can remove stale facts later.

Production checks

  • Only approved facts are available to normal recall.
  • Retired facts remain auditable but no longer influence context.
  • Forgotten facts are unavailable to future recall.
  • Memory scope includes tenant and subject boundaries.
schema.sql
CREATE TABLE conversations (
  id INT PRIMARY KEY,
  tenant_id VARCHAR NOT NULL,
  user_id VARCHAR NOT NULL,
  body TEXT NOT NULL
);
agent.ddl.sql
CREATE AGENT WORKFLOW chat.thread_turn_flow
SESSION REQUIRE tenant_id, user_id, active_thread_id
ALLOWED CAPABILITIES (
  chat.prepare_llm_context
)
EVIDENCE REQUIRED
CHECKPOINT EVERY STEP
RETENTION RUNS 90 DAYS, EVIDENCE 90 DAYS;

CREATE AGENT CONTEXT chat.thread_context
ROOT conversations AS conversation
LOOKUP conversation.id = SESSION active_thread_id
BIND tenant_id FROM SESSION tenant_id
BIND user_id FROM SESSION user_id
OUTPUT SLOTS
  thread_id AS conversation.id,
  user_id AS conversation.user_id
EVIDENCE ON;

CREATE AGENT CAPABILITY chat.prepare_llm_context
DESCRIPTION 'Prepare compact governed context for one chat turn'
ARG prompt VARCHAR REQUIRED
HIDDEN tenant_id FROM SESSION tenant_id
HIDDEN user_id FROM SESSION user_id
HIDDEN active_thread_id FROM SESSION active_thread_id
USE CONTEXT chat.thread_context
EXECUTION READ ONLY
TOKEN BUDGET MAX OUTPUT TOKENS 1200, MAX INLINE EVIDENCE ITEMS 3,
             MAX REASON COUNT 4, PREFER HANDLES
PLAN
DEFAULT DECISION prepared
MEMORY relevant_memory
  SCOPE tenant
  SUBJECT user ARG user_id
  BUDGET_TOKENS 400
  PROFILE minimal
  INLINE_EVIDENCE handles_only
  PREFER_HANDLES
PAYLOAD memory = STEP_OUTPUT relevant_memory
EVIDENCE memory = STEP_OUTPUT relevant_memory
END PLAN
RETURNS JSON '{"type":"object","properties":{"decision":{},"memory":{},"evidence_bundle":{}}}'
PROFILE MINIMAL
INLINE EVIDENCE handles_only;
python
proposal = db.propose_memory_fact(
    scope=("tenant", "acme"),
    subject=("user", "u_42"),
    claim="Prefers concise technical answers.",
    source=("conversation", "conv_884"),
    trust="verified",
    approval="pending",
    reason="Repeated explicit preference.",
)

db.approve_memory_proposal(proposal["proposal"]["proposal_id"], "User stated this twice.")
facts = db.recall_memory(scope=("tenant", "acme"), subject=("user", "u_42"))
print(facts)