Skip to content

History: decouple from cache, add per-module + per-LM tracking #70

@darinkishore

Description

@darinkishore

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions