Context
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>)
- If
cache: false, there's no history at all
CacheEntry stores { prompt: String, prediction: Prediction } — minimal info
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
- Rich entries: messages sent, LM params, raw response, parsed output, usage, timestamp
Per-LM history
lm.history: Vec<HistoryEntry> with configurable max size
lm.inspect_history(n) returns last n entries
Per-module history
- When a module calls an LM, the entry is also appended to
module.history
- Requires knowing which module is the caller (DSPy uses
settings.caller_modules stack)
Global history
dspy_rs::inspect_history(n) for all LM calls across the process
Modernize trace/ module
Related
Context
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 fromResponseCache.history_window(a fixed-sizeVec<CacheEntry>)cache: false, there's no history at allCacheEntrystores{ prompt: String, prediction: Prediction }— minimal infoMeanwhile, the
trace/module (task-local DAG recorder) was an earlier attempt at runtime execution recording, but it usesPrediction/Exampletypes and is currently unwired (see #68).What's needed
Separate history from cache
Per-LM history
lm.history: Vec<HistoryEntry>with configurable max sizelm.inspect_history(n)returns last n entriesPer-module history
module.historysettings.caller_modulesstack)Global history
dspy_rs::inspect_history(n)for all LM calls across the processModernize trace/ module
CURRENT_TRACEpattern intrace/context.rsis the right shapePrediction/ExampletoBamlValue/typed valuesProgramGraph(make sure program graph has the same semantics as old trace/ module #68)Related