You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
History: decouple from cache, add per-module + per-LM tracking #70
DSPy Python has 3-level history tracking (global, per-LM, per-module), fully independent of caching. Each history entry includes: messages, kwargs, response, outputs, usage, cost, timestamp, uuid, model. inspect_history(n) works at all three levels.
dspy-rs currently couples history entirely to the cache layer:
inspect_history(n) reads from ResponseCache.history_window (a fixed-size Vec<CacheEntry>)
Meanwhile, the trace/ module (task-local DAG recorder) was an earlier attempt at runtime execution recording, but it uses Prediction/Example types and is currently unwired (see #68).
What's needed
Separate history from cache
History should record every LM call regardless of cache settings
LM::call() → sends CacheEntry to ResponseCache via mpsc channel
ResponseCache::insert() → stores in foyer + appends to history_window (Vec<CacheEntry>, max 100)
LM::inspect_history(n) → reads from cache_handler.lock().get_history(n)
If cache: false on LM → cache_handler is still created (it's always Some), but the semantics are confusing. History is an accident of caching, not a deliberate feature.
What DSPy Python does:
lm.history — list of dict with messages, response, usage, cost, timestamp, uuid, model
dspy.inspect_history(n) — global, reads from all LMs
History is independent of caching — every call is recorded regardless
Per-module: settings.caller_modules stack tracks which module triggered which LM call
pubstructHistoryEntry{pubid:Uuid,pubtimestamp:DateTime<Utc>,pubmodel:String,pubmessages:Vec<Message>,// what was sentpubraw_response:String,pubparsed_output:Option<BamlValue>,pubusage:LmUsage,publatency_ms:u64,pubmodule_path:Option<String>,// which Predict/module triggered thispuberror:Option<String>,// if the call failed}
Storage:Vec<HistoryEntry> with configurable max size per-LM instance. Global history = aggregation across all LM instances. Per-module = filtered by module_path.
Activity
darinkishore commentedon Feb 12, 2026
Codebase audit — current history coupling
How history works today:
If
cache: falseon LM →cache_handleris still created (it's alwaysSome), but the semantics are confusing. History is an accident of caching, not a deliberate feature.What DSPy Python does:
lm.history— list ofdictwith messages, response, usage, cost, timestamp, uuid, modeldspy.inspect_history(n)— global, reads from all LMssettings.caller_modulesstack tracks which module triggered which LM callDependency chain:
LanguageModeltrait, so history can be trait-levelHistoryEntryshould use typed errors, not just success casesCacheEntryno longer serves double dutyProposed
HistoryEntry:Storage:
Vec<HistoryEntry>with configurable max size per-LM instance. Global history = aggregation across all LM instances. Per-module = filtered bymodule_path.