Skip to main content

Procedural Memory

Agents often solve the same kind of problem repeatedly — refund a delayed order, onboard a new user, debug a failing deployment. Procedural memory lets agents learn successful tool-call sequences and reuse them when a similar situation arises. Instead of reasoning from scratch every time, the agent can recall a proven procedure and follow it, reducing latency, token usage, and error rates.

How It Works

  1. After a successful run, the memory system analyzes the tool-call sequence
  2. If the sequence is multi-step and coherent, it’s extracted as a procedure
  3. On future runs, buildContext() checks if any stored procedure matches the current query
  4. If a match is found, the procedure is injected into the system prompt as a suggested plan
The agent isn’t forced to follow the procedure — it’s presented as a recommendation. The agent can adapt, skip steps, or ignore it entirely based on the current context.

Quick Start

That’s it. The agent will automatically learn procedures from successful runs and suggest them when relevant.

Scope hierarchy (v2.3+)

Procedures are shareable across users — a workflow like “invoice reconciliation” should be available to every accountant on the team, not just whoever first ran it. Each procedure carries an explicit scope: Reads union all accessible scopes. When alice (working with the invoice-recon agent at tenant acme) calls recall_procedure, the framework searches her personal procedures plus the agent’s shared procedures plus the tenant’s procedures plus global defaults. Writes choose one scope. Auto-extracted procedures always save as "user" — the framework never auto-promotes a personal procedure to a shared scope without an explicit caller choice.
See Multi-User Isolation for the full scope contract.

Configuration

For fine-grained control, pass a configuration object:

Procedure Structure

Each stored procedure contains:

Example Procedure

After the agent successfully processes a refund, this procedure might be extracted:

How Procedures Are Learned

After each run, the memory system evaluates the tool-call sequence:
If a similar sequence is already stored, the existing procedure’s successCount is incremented rather than creating a duplicate.

Procedure Matching with suggestProcedure

Before each run, the memory system checks for matching procedures:
The matching uses semantic similarity between the current input and stored procedure triggers. Only procedures whose required tools are available to the agent are suggested.

The recall_procedure Tool

When procedural memory is enabled, the agent gains access to the recall_procedure tool, which it can call at any time during a run:
This is useful when the automatic suggestion doesn’t fire (e.g., the query doesn’t match the trigger closely enough) but the agent recognizes mid-conversation that a known workflow applies.

Full Example: Learning and Reusing

After multiple successful uses, the procedure’s successCount grows, and the agent can reference its track record when deciding to follow it.

How Procedures Evolve

Procedures aren’t static. Over time:
  • Success reinforcement — each successful use increments successCount
  • Failure tracking — if the agent deviates or the user reports a bad outcome, failureCount increments
  • Eviction — when maxProcedures is reached, procedures with the lowest success-to-failure ratio and oldest lastUsed date are evicted
  • Merging — if two procedures are semantically very similar, they’re merged (steps unified, counts combined)

Cross-References