Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tool-Result Clearing

Live curator that drops the body of stale tool results from outgoing LLM requests while keeping the call/result envelope. The model still sees that the tool was invoked; the (often large) body is replaced inline with a <tool_result … cleared="true" …/> marker.

This is the highest-leverage layer in Idea 30’s curation stack — for tool-heavy sessions, 50–80% of context bytes are tool-result bodies, most of which are dead weight by the time the next request fires.

Details

IDnexus.memory.tool_result_clear
Capabilitiesnone
Dependenciesnone

Operates at priority 12 on before:llm.request — after nexus.discovery.progressive (priority 8) has shaped the tool list, then re-shapes the outgoing message slice without touching the upstream history buffer.

Configuration

KeyTypeDefaultDescription
enabledbooltrueToggle the curator.
age_turnsint5Clear tool results older than this many turns when also exceeding size_bytes_threshold.
size_bytes_thresholdint1000Skip clearing for result bodies smaller than this many bytes.
preserve_recent_kinds[]string["error","user_question"]Result kinds never cleared regardless of age.
drop_strategystringreplace_with_envelopereplace_with_envelope keeps the call/result pair with a marker body (default). full_drop removes the message entirely; risks tool_use/tool_result pairing breakage.

Heuristics

A tool result is cleared when any of the following hold:

  • Age + sizenow_turn − call_turn ≥ age_turns AND len(result) ≥ size_bytes_threshold.
  • Subsequent-call — the same tool was invoked later with semantically equivalent arguments (canonical-JSON hash). Earlier results are redundant.
  • Preserved kind exemption — results classified as error (and any kind listed in preserve_recent_kinds) are never cleared.

Once an ID is cleared, it stays cleared for the remainder of the session — subsequent requests re-replace deterministically without re-running the heuristic.

Events

Subscribes To

EventPriorityPurpose
tool.invoke60Track call name, canonical args hash, and turn
tool.result60Record result size and kind classification
agent.turn.end60Increment internal turn counter
before:llm.request12Mutate req.Messages, replace stale tool result bodies

Emits

EventWhen
memory.tool_result_clearedOnce per cleared call (carries tool_call_id, tool, original_size, cleared_at_turn, reason)
memory.curatedEnvelope event with stability descriptor (Layer: "tool_result_clear", CacheInvalidates: false)

Replay Determinism

The clearing decision is heuristic, but every cleared call is recorded as a memory.tool_result_cleared event. The durable journal (Idea 01) captures these events so replay reproduces the same envelope without re-running the heuristic.

Example Configuration

plugins:
  active:
    - nexus.agent.react
    - nexus.memory.tool_result_clear

  nexus.memory.tool_result_clear:
    enabled: true
    age_turns: 4
    size_bytes_threshold: 512
    preserve_recent_kinds: ["error", "user_question"]
    drop_strategy: replace_with_envelope