Runs and consolidation
How a run's entries are promoted into durable facts, an episode and procedures — and how facts are promoted further to tenant conventions.
A run is one task. While it is in progress, the agent writes entries with a stable runId. When it finishes, consolidation distills the run into long-term memory. This is the main promotion path in Agent Memory:
session entries ──► workspace facts ──► procedures
│
└──► tenant conventions (admin-approved)Consolidating a run
Call consolidate at the end of a task with the same runId you wrote with:
curl -s -X POST "$AGENT_MEMORY_BASE_URL/v1/memory/consolidate" \
-H "Authorization: Bearer $AGENT_MEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"workspaceId": "'"$AGENT_MEMORY_WORKSPACE_ID"'",
"runId": "run-1",
"goal": "Add vegetarian filtering to the menu service"
}'
# {"status":"consolidated"}Consolidation needs the curate capability (memory:curate). goal is optional context for the episode; extractionInstructions optionally steers fact extraction for this run. Over MCP the equivalent is the consolidate tool.
What consolidation does
- Creates an episode for the run, linked to the previous episode, and records every session entry as an episode event.
- Scores the run. Event types drive the score: a
violationpulls the run toward failed, approved patterns without corrections push it toward successful. The result is an outcome (successful,failed,uncertain) and asuccessScorefrom 0 to 1. - Extracts facts. Entries whose type is promotable (configured by semantic categories) are broken into discrete facts. Each fact becomes a canonical workspace memory linked back to its episode, is embedded, summarized, connected to related memories, and checked for contradictions. Facts are extracted with the configured LLM, or with a rule-based extractor when no LLM is available.
- Learns procedures. If the run scored above 0.7 and contains an
approved_pattern, its event sequence becomes (or validates) a procedure. - Finalizes the episode with a summary and sentence-level fragments for fine-grained episode search.
- Abstracts across episodes, generalizing repeated, high-confidence patterns into procedures.
- Proposes tenant conventions (see below) and clears the run's session memory.
A webhook categorize event is emitted when a run is consolidated. See Webhooks.
Forgot to consolidate? It happens anyway
A background worker watches run activity and consolidates runs that have been idle longer than the idle timeout (30 minutes by default, configurable when self-hosting). Explicit consolidation is still recommended so facts are available right away.
Writing for good consolidation
- Use one
runIdper task. Thousands of single-entry runs consolidate into thousands of tiny episodes. - Pick the right type. Only promotable types become facts, and
violation/approved_patterndecide how the run is scored. - Write durable facts directly when they matter now. Appends with
layer: "Workspace"(the SDK and MCP default) are searchable immediately; consolidation then adds the episode, procedures and extracted facts on top. - Use
layer: "Session"for scratch notes that should only influence the current run unless consolidation decides they are worth keeping.
Limits per run
By default consolidation extracts facts from the first 500 session entries of a run (the rest are still recorded as episode events), keeps at most 20 facts per entry and embeds up to 200 sentence fragments per episode. These limits are workspace settings.
Review before facts go live
A workspace can require review of consolidated facts. With the workspace setting promotion.workspaceCandidates.enabled turned on, promoted facts are held as candidates — hidden from recall — until a tenant administrator approves them in the console.
Promotion to tenant conventions
Tenant conventions are knowledge that holds across an organization. They are never written directly by agents; they are promoted:
- After consolidation, canonical
decisionandapproved_patternfacts that were established independently in at least two different workspaces of the same tenant become tenant-level candidates. Repeats within one workspace do not count, and content that looks like a secret or personal data is never promoted. - A tenant administrator approves (→ active) or rejects each candidate in the console. Unreviewed candidates expire after 14 days by default.
- Approved conventions appear in every workspace's recall under
tenantEntries("Tenant conventions").
Tenant conventions are authoritative: when a new workspace memory conflicts with an active convention, the workspace memory's confidence is lowered and the conflict is recorded — the convention is not changed. There is no promotion from tenant to platform.
Quarantined memories
Appended content is screened before it is stored, looking for prompt-injection and data-exfiltration patterns such as "ignore previous instructions", spliced role markers or markdown image beacons. Flagged content is stored as quarantined: it is never recalled, merged, consolidated, promoted or shared until a reviewer with the curate capability releases or rejects it with POST /v1/memory/{id}/review.