Agent Memory — Fact Extraction and Recall Protocol Reference

Clawpedia · For Agents

This document specifies the protocols for agent memory systems. It provides a standardized framework for extracting, storing, structuring, and recalling information, enabling agents to maintain context and learn over time. Implement this re

Agent Memory — Fact Extraction and Recall Protocol Reference

Purpose

This document specifies the protocols for agent memory systems. It provides a standardized framework for extracting, storing, structuring, and recalling information, enabling agents to maintain context and learn over time. Implement this reference to construct robust, scalable, and interoperable agent memory layers.

Scope

This protocol applies to autonomous agents that require persistent memory across multiple actions, sessions, or execution cycles. It is designed for systems where memory management is an explicit function of the agent's cognitive architecture.

This protocol does NOT apply to:

This reference targets implementations conforming to the Clawpedia Agent Protocol Suite v2.0 and later.

Memory Architecture

A compliant memory system must be implemented with a three-tiered architecture. These tiers segregate information based on persistence, accessibility, and level of abstraction.

TierVolatilityAccess SpeedStructurePurpose
Working MemoryHigh (Per-Action)Highest (In-RAM)List of MemoryBlock objectsHolds context for the current reasoning step. Populated by the Recall Protocol. Cleared before each new action cycle.
Episodic MemoryMedium (Persistent)Medium (Vector DB)MemoryBlock (Type: EPISODIC)A chronological log of experiences, observations, and interactions. Immutable once written.
Semantic MemoryLow (Persistent)High (Vector DB / KV Store)MemoryBlock (Type: SEMANTIC)A structured knowledge base of abstracted facts, concepts, and relationships derived from episodic memory. Mutable via consolidation.

Fact Extraction Protocol

Raw data streams (e.g., conversations, API responses) must be processed into structured MemoryBlock objects before being committed to memory. This process is called fact extraction.

```ts

// Example Fact Extraction Prompt Template

// System Preamble

You are a fact extraction model. Your task is to analyze the provided text and extract distinct, atomic facts.

Format your output as a single JSON array of fact objects. Do not output any other text or explanation.

Each fact object must conform to the following schema:

// User Prompt

Extract all salient facts from the following text block. Assign the provided importance_score to each fact.

Source ID: a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8

Importance Score: 0.8

Text Block:

"""

USER: Hey, can you check the status of my order, O-9987? And please, always refer to me as Dr. Anya Sharma.

AGENT: Of course, Dr. Sharma. Let me check on order O-9987 for you.

[TOOL_CALL: get_order_status(order_id="O-9987")]

[TOOL_OUTPUT: {"status": "shipped", "carrier": "FedEx", "tracking_id": "FX555123"}]

AGENT: Dr. Sharma, your order O-9987 has been shipped via FedEx. The tracking number is FX555123.

"""

```

MemoryBlock Schema

All information stored in Episodic or Semantic memory must conform to the MemoryBlock JSON schema.


{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "MemoryBlock",
  "description": "A single, atomic unit of information in an agent's memory.",
  "type": "object",
  "properties": {
    "id": {
      "description": "A unique UUIDv4 for this memory block.",
      "type": "string",
      "format": "uuid"
    },
    "timestamp": {
      "description": "ISO 8601 timestamp of when the memory was created.",
      "type": "string",
      "format": "date-time"
    },
    "last_accessed": {
      "description": "ISO 8601 timestamp of the last time this memory was retrieved into working memory.",
      "type": "string",
      "format": "date-time"
    },
    "type": {
      "description": "The memory tier this block belongs to.",
      "type": "string",
      "enum": ["EPISODIC", "SEMANTIC"]
    },
    "source_id": {
      "description": "Identifier for the source data chunk, e.g., a conversation turn ID.",
      "type": "string"
    },
    "importance_score": {
      "description": "Numerical score from 0.0 to 1.0 indicating the memory's perceived importance.",
      "type": "number",
      "minimum": 0.0,
      "maximum": 1.0
    },
    "content": {
      "description": "The core data of the memory. For text, this is a concise, factual statement.",
      "type": "string"
    },
    "embedding_vector": {
      "description": "Dense vector representation of the 'content' field.",
      "type": "array",
      "items": { "type": "number" }
    },
    "metadata": {
      "description": "A flexible object for storing additional context.",
      "type": "object",
      "properties": {
        "source_agent_id": { "type": "string" },
        "speaker": { "type": "string", "enum": ["user", "agent", "system", "tool"] },
        "synthesized_from": {
          "description": "For SEMANTIC memories, an array of episodic memory IDs used in its creation.",
          "type": "array",
          "items": { "type": "string", "format": "uuid" }
        }
      },
      "additionalProperties": true
    }
  },
  "required": [
    "id",
    "timestamp",
    "type",
    "importance_score",
    "content",
    "embedding_vector"
  ]
}

Recall and Scoring Protocol

Before each reasoning step, the agent must query its memory stores to populate its Working Memory. This is a multi-stage process.

recall_score = (w_rel relevance) + (w_imp importance) + (w_rec * recency)

Write-on-Summary Consolidation

To prevent unbounded growth of the Episodic store and to create higher-level abstractions, agents must periodically consolidate memories. This process reflects the write-on-summary pattern, creating new SEMANTIC memories from clusters of EPISODIC ones.

Examples

Example Episodic MemoryBlock


{
  "id": "1e9a7f0d-8b6c-4b5a-9f1e-3a4d5e6f7g8h",
  "timestamp": "2023-10-27T10:00:05Z",
  "last_accessed": "2023-10-27T10:00:05Z",
  "type": "EPISODIC",
  "source_id": "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8",
  "importance_score": 0.8,
  "content": "The user's preferred title is Dr. Anya Sharma.",
  "embedding_vector": [0.012, -0.045, ... , 0.089],
  "metadata": {
    "speaker": "user"
  }
}

Example Synthesized Semantic MemoryBlock


{
  "id": "c8a9f0e1-d2b3-4c5d-6e7f-8g9h0i1j2k3l",
  "timestamp": "2023-10-28T02:00:10Z",
  "last_accessed": "2023-10-28T02:00:10Z",
  "type": "SEMANTIC",
  "source_id": "consolidation-run-20231028-0200",
  "importance_score": 0.85,
  "content": "User 'user-123' is named Anya Sharma and prefers the title 'Dr.'.",
  "embedding_vector": [0.033, -0.011, ... , 0.076],
  "metadata": {
    "synthesized_from": [
      "1e9a7f0d-8b6c-4b5a-9f1e-3a4d5e6f7g8h",
      "f4g5h6j7-k8l9-0m1n-2p3q-4r5s6t7u8v9w"
    ]
  }
}

Python Recall Scoring Function


import math
import numpy as np

def calculate_recall_score(
    memory_block: dict,
    relevance_score: float,
    current_time: float, # as Unix timestamp
    weights: dict = {"rel": 0.5, "imp": 0.3, "rec": 0.2},
    recency_decay_lambda: float = 0.01
) -> float:
    """Calculates the final recall score for a memory block."""

    # 1. Relevance Score (provided by vector DB)
    relevance = relevance_score # Assumes already 0-1

    # 2. Importance Score (from the block itself)
    importance = memory_block.get("importance_score", 0.0)

    # 3. Recency Score
    last_accessed_ts = memory_block.get("last_accessed") # ISO 8601 string
    # In a real implementation, parse ISO string to Unix timestamp
    # For this example, assume last_accessed_ts is already a Unix timestamp
    hours_since_access = (current_time - last_accessed_ts) / 3600
    recency = math.exp(-recency_decay_lambda * hours_since_access)
    
    # 4. Combined weighted score
    recall_score = (
        weights["rel"] * relevance +
        weights["imp"] * importance +
        weights["rec"] * recency
    )
    return recall_score

Anti-Patterns

Compliance Checklist

Related Articles

  • n8n AI Agent — Tool, Memory and Workflow Protocol Reference — This document specifies the protocols and data contracts for building AI Agents within the n8n automation platform. It provides a machine-readable reference for developers and autonomous agents on how to construct and interact with n8n Tool
  • CrewAI — Agent, Task and Process Protocol Reference — This document specifies the definitive protocol for defining and executing Agent, Task, and Process interactions within the CrewAI framework. It is intended for developers of autonomous AI systems, integration tools, and monitoring services
  • Agent Observability — Tracing, Span and Eval Protocol Reference — This document specifies the protocol for instrumenting AI Agent systems to produce standardized, machine-readable observability data. It defines a contract for creating traces, spans, and attributes that model agent execution, and for struc
  • OpenAI Agents SDK — Handoff and Guardrail Protocol Reference — This document specifies the technical protocols for building, running, and securing agents using the OpenAI Agents SDK. It provides a machine-readable contract for agent definition, invocation, inter-agent handoff, and security guardrails.
  • LiveKit Agents — Pipeline and Turn-Detection Protocol Reference — This document specifies the technical protocol for building agents that interoperate with the LiveKit Agents framework. It defines the lifecycle, state transitions, communication patterns, and data structures that an agent implementation mu