Skip to main content

Module reasoning

Module reasoning 

Source
Expand description

ReasoningBank: distilled reasoning strategy memory (#3342).

After each completed agent turn a three-stage async pipeline runs off the hot path:

  1. Self-judge (run_self_judge) — a fast LLM evaluates success/failure and extracts the key reasoning steps.
  2. Distillation (distill_strategy) — a strategy summary (≤ 3 sentences) is generated from the reasoning chain, capturing the transferable principle.
  3. Storage (ReasoningMemory::insert) — the summary is written to SQLite and, when Qdrant is available, embedded and indexed for vector retrieval.

At context-build time ReasoningMemory::retrieve_by_embedding fetches top-k strategies by embedding similarity. The caller (in zeph-context) calls ReasoningMemory::mark_used only for strategies actually injected into the prompt, after budget truncation (C4 split from architect plan).

§LRU eviction

ReasoningMemory::evict_lru protects rows with use_count > HOT_STRATEGY_USE_COUNT (default 10) from normal eviction. When all rows are hot and the table exceeds 2 × store_limit, a forced eviction pass deletes the oldest rows unconditionally and emits a warn! so operators can tune store_limit upward.

§LRU eviction race note

Two concurrent turns may race on the count check in evict_lru. Either both evict (over-eviction by at most top_k rows) or neither. This is acceptable for MVP — the table remains bounded.

Structs§

OutcomeParseError
Error returned when parsing an Outcome from a string fails.
ProcessTurnConfig
Configuration for the process_turn extraction pipeline.
ReasoningMemory
SQLite-backed store for distilled reasoning strategies.
ReasoningStrategy
A distilled reasoning strategy row from the reasoning_strategies table.
SelfJudgeOutcome
Parsed response from the self-judge LLM call.

Enums§

Outcome
Outcome of a reasoning strategy: whether the agent succeeded or failed.

Constants§

REASONING_COLLECTION
Qdrant collection name used for reasoning-strategy embeddings.

Functions§

distill_strategy
Run the distillation step.
process_turn
Run the full extraction pipeline for a single turn.
run_self_judge
Run the self-judge step against a turn’s message tail.