inspect_history() returns the most recent model calls of the session as
a tibble, across all modules, like DSPy's dspy.inspect_history(). It can
also write them to a plain-text transcript.
Value
A tibble with one row per call and columns timestamp, source
(the module class that made the call), model, tokens_in,
tokens_out, cost (in US dollars, when known), duration_s,
program_artifact_id, trace_context, and prompt and response
when requested. With no recorded calls, an empty tibble and a message.
Details
The history is kept in memory for the session and holds the most recent
100 calls by default (options(dsprrr.prompt_history_max = )). Prediction
modules (module(), chain_of_thought()) and rag_module(), react(),
rlm_module() and flex() modules add their calls to it; calls made
inside wrappers and pipelines, and by run_async() or run_stream(), are
not recorded. clear_prompt_history() empties it.
See also
Other inspection:
accessors,
clear_prompt_history(),
clear_traces(),
export_traces(),
get_last_prompt(),
session_cost(),
summarize_traces()
Examples
# Empty until a module has called a model
inspect_history(n = 5)
#> No LLM calls recorded yet
#> # A tibble: 0 × 0
if (FALSE) { # \dontrun{
qa <- module(signature("question -> answer"))
run(qa, question = "What is 2 + 2?", .llm = ellmer::chat_openai(model = "gpt-6-luna"))
history <- inspect_history(n = 20)
sum(history$cost, na.rm = TRUE)
# A plain-text transcript for sharing
inspect_history(n = 20, file = tempfile(fileext = ".txt"))
} # }