Skip to main content

Module dag

Module dag 

Source
Expand description

DAG-based state management for episode context (WG-134).

Inspired by arXiv:2602.22398: DAG-based state management achieves 86% token reduction by deduplicating shared context between episodes.

§Key Concepts

Instead of storing full context for each episode, we:

  1. Create DAG nodes for shared context attributes (language, domain, task_type)
  2. Episodes reference nodes by ID instead of storing full context strings
  3. Context assembly traverses DAG to deduplicate shared attributes

§Architecture

Episodes ──► StateDag ──► Deduplicated Context
   │           │              │
   │           │              │
   └──► StateNode (shared) ──► Shared attribute once
   │   - language="rust"
   │   - domain="web-api"
   │   - task_type="Debugging"
   │
   └──► Episode-unique state stored separately

§Token Reduction

For N episodes sharing the same language/domain/task_type:

  • Old: N × (language + domain + task_type) tokens
  • New: 1 × (language + domain + task_type) + N × node_id refs
  • Reduction: ~86% when N > 5 and shared context is large

Re-exports§

pub use assembler::AssembledContext;
pub use assembler::DagAssemblyConfig;
pub use assembler::DagContextAssembler;
pub use edge::EdgeMetadata;
pub use edge::EdgeType;
pub use edge::StateEdge;
pub use node::NodeId;
pub use node::StateNode;
pub use node::StateNodeType;
pub use state::DagStats;
pub use state::StateDag;

Modules§

assembler
DAG-based context assembler (WG-134) — assembles episode context by traversing StateDag to deduplicate shared attributes (~86% token reduction).
edge
State edges for DAG-based context management (WG-134).
format
Output formatting for DAG context assembly (WG-134).
node
State nodes for DAG-based context management (WG-134).
state
State DAG structure for context management (WG-134).