Writing · Protocols

By Younes Abouelnagah · Published March 25, 2026

Context engineering protocols

Three pieces of research (SECOM, ACE, and RLM) turned into composable lifecycle hooks for agent memory. Extractive compression, playbook-driven reranking, and MapReduce orchestration: where to plug them in and what they do for you in production.

Younes Abouelnagah

Written by Younes Abouelnagah, founder of Machine Wisdom AI

This protocol guide is part of the Machine Wisdom AI record on context engineering for long-running agents: compression, reranking, orchestration, lifecycle hooks, and production verification.

Most agent memory implementations get the basics wrong before they fail at the interesting parts. The basics are: when do you compress, when do you rerank, and how do you validate fan-out before you start trusting the results.

Three pieces of academic research from the last year give clean answers to those questions: SECOM (Tsinghua University and Microsoft, ICLR 2025) for extractive compression, ACE (Stanford / UC Berkeley / SambaNova) for playbook-driven reranking, and RLM (MIT) for MapReduce orchestration. We turned each into a composable lifecycle hook inside FAVA Trails, the open-source agent memory layer we maintain.

FAVA Trails exposes lifecycle hooks at key moments: before_save, on_recall, before_propose, and others. Protocols are pre-built hook implementations that plug into these points. Each is independent; enable any combination.

SECOM: extractive compression

Adapted from SECOM (Tsinghua University and Microsoft, ICLR 2025), which applies LLMLingua-2 extractive compression to conversational memory retrieval. Compresses thoughts at promote time via token-level extraction, keeping the semantic core while dramatically reducing storage.

Hook points: before_propose, before_save, on_recall. Requires the secom extra; first use downloads a ~700 MB BERT model from HuggingFace (warm it ahead of time with fava-trails secom warmup).

# Install + setup
pip install 'fava-trails[secom]'
fava-trails secom setup --write

# Or add manually in your config.yaml
hooks:
  - module: fava_trails.protocols.secom
    points: [before_propose, before_save, on_recall]
    order: 20
    fail_mode: open
    config:
      compression_threshold_chars: 500
      verbosity_warn_chars: 1000
      target_compress_rate: 0.6
      compression_engine:
        type: llmlingua
        model_name: microsoft/llmlingua-2-bert-base-multilingual-cased-meetingbank
        device_map: cpu

Known limitation. SECOM destroys structured data: JSON, YAML, code blocks, and tables lose their formatting after extraction. Tag thoughts with secom-skip to opt out of compression for structured content.

ACE: agentic context engineering

Based on Stanford, UC Berkeley, and SambaNova ACE. Applies playbook-driven reranking and anti-pattern detection to recalled thoughts, surfacing what matters and flagging what's stale or contradictory.

Hook points: on_startup, on_recall, on_recall_mix, before_save, after_save, after_propose, after_supersede. Included in the base install, no extras needed.

fava-trails ace setup --write

# Or add manually
hooks:
  - module: fava_trails.protocols.ace
    points: [on_startup, on_recall, on_recall_mix, before_save, after_save, after_propose, after_supersede]
    order: 10
    fail_mode: open
    config:
      playbook_namespace: preferences
      telemetry_max_per_scope: 10000

How it works. ACE stores playbook rules as thoughts in the preferences/ namespace. When you recall, ACE reranks results by applying matching rules multiplicatively. Anti-pattern rules signal during before_save, while active playbook rules can boost or deprioritize recalled thoughts. Rules are themselves thoughts, so they participate in supersession and versioning.

RLM: MapReduce orchestration

Based on MIT RLM. Validates mapper outputs, tracks batch progress, and sorts results for reducer consumption, essential for multi-agent workflows that fan out and collect.

Hook points: before_save, after_save, on_recall, on_recall_mix. Included in the base install.

fava-trails rlm setup --write

# Or add manually
hooks:
  - module: fava_trails.protocols.rlm
    points: [before_save, after_save, on_recall, on_recall_mix]
    order: 15
    fail_mode: closed
    config:
      expected_mappers: 5
      min_mapper_output_chars: 20

How it works. When a mapper agent calls save_thought with the rlm-mapper tag, RLM requires metadata.extra.mapper_id, warns when batch_id is missing, and rejects mapper outputs below min_mapper_output_chars. On recall, RLM sorts mapper results by mapper_id and creation time so the reducer receives them in deterministic order. expected_mappers controls when the hook emits a reduce-ready advisory.

Combining protocols

Protocols are composable. A common production stack:

hooks:
  - module: fava_trails.protocols.rlm
    points: [before_save, after_save, on_recall, on_recall_mix]
    order: 5                # validate mapper outputs first
    fail_mode: closed
    config:
      expected_mappers: 5
      min_mapper_output_chars: 20
  - module: fava_trails.protocols.ace
    points: [on_startup, on_recall, on_recall_mix, before_save, after_save, after_propose, after_supersede]
    order: 10               # apply playbook rules and anti-pattern advice
    fail_mode: open
    config:
      playbook_namespace: preferences
  - module: fava_trails.protocols.secom
    points: [before_propose, before_save, on_recall]
    order: 20               # compress before promoting to truth
    fail_mode: open
    config:
      target_compress_rate: 0.6
      compression_engine:
        type: llmlingua

Hooks execute by ascending order within each lifecycle point. If a closed-mode hook rejects an operation, later hooks for that operation are skipped.

Further reading

  • The agent memory landscape, compared: where vector search, knowledge graphs, and task trackers fall short, and why governed memory is the alternative.
  • FAVA Trails README: full install and MCP setup.
  • SECOM paper: extractive compression for conversational memory (Tsinghua / Microsoft, ICLR 2025).
  • LLMLingua-2 paper: token-level extraction underlying SECOM.
  • ACE paper: playbook-driven context engineering (Stanford / UC Berkeley / SambaNova).
  • RLM paper: MapReduce for language model orchestration (MIT).

Pick the right protocols for your stack

Compress, rerank, orchestrate: the order and the configuration are the difference between memory that compounds and memory that erodes. Picking which lifecycle protocols to enable and where in the pipeline is the kind of context-engineering call I help teams get right before they ship: which research to import, what to leave out, and what to verify with real traffic.

Stay Updated

Subscribe for frameworks and engagement briefs on production AI, agents, and governed autonomy.