Documentation

tracellm trace

Trace prompts, tool calls, retries, and model responses.

Overview

The tracellm trace command sends a prompt to your configured LLM provider and captures the full execution as a trace. It simulates a production RAG + agent workflow — embedding, vector search, reranking, planning, tool chaining, and generation — and records every span with timing and metadata.

Syntax

terminalCopy
bash
tracellm trace [OPTIONS] PROMPT
ArgumentTypeRequiredDescription
PROMPTstringYesThe prompt text to trace (positional)
OptionTypeDefaultDescription
--modelstrgpt-4.1-miniModel name label for the trace
--projectstrdefaultProject identifier or display name
--environmentstrdevelopmentEnvironment label
--api-keystrNoneTraceLLM API key for project resolution

What Happens Internally

  1. Context resolution — If --api-key is provided, the project ID, name, and environment are looked up from MongoDB. Otherwise the provided flags are used directly.
  2. Event stream starts — A rich live trace stream displays timestamped events as they occur: query embedding, vector search, context reranking, agent planning, context allocation, tool chaining, and LLM generation.
  3. Simulation runs — The internal simulation executes a multi-step agentic workflow with random delays, retries, and embedding dimensions to produce realistic trace data.
  4. Trace finalized — Latency, token counts, status, and all step data are assembled into a trace payload.
  5. Persistence — The trace is saved to MongoDB via save_trace_payload.
  6. Summary rendered — A trace report card is printed showing model, latency, tokens, retries, status, timestamp, and trace ID.

Example Output

Terminal outputCopy
text
  Tracing request...

  query.embed        Embedding prompt
  vector.search      Searching vector index
  context.rerank     Reranking context
  agent.plan         Planning tool execution
  context.allocate   Allocating context window
  tool.chain         Running tool chain
  llm.generate       Generating answer

  ╭── Trace Summary ─────────────────────────────────────────╮
  │                                                          │
  │  Model       gpt-4.1-mini                                │
  │  Latency     3,420 ms                                    │
  │  Tokens      1,247                                       │
  │  Retries     1                                           │
  │  Status      SUCCESS                                     │
  │  Timestamp   2026-05-31T14:22:10Z                        │
  │  Trace ID    tr_2kf9q3m1                                 │
  │                                                          │
  ╰──────────────────────────────────────────────────────────╯

  Trace complete

Common Errors

ErrorCauseFix
Prompt is requiredNo prompt argument providedAdd a prompt string: tracellm trace "your prompt"
Trace persistence failedMongoDB is unavailableStart MongoDB or check your MONGO_URL
Simulation errorInternal trace step failedCheck the error output — it is captured in the trace

Troubleshooting

Warning

The trace command simulates an LLM workflow end-to-end, including random retries. If you see a yellow warning about retries, this is expected behavior — the workflow automatically retries failed tool calls.