Skip to main content
This page starts from an untraced support agent and adds Lemma software development kit (SDK) calls one piece at a time. Complete the Quickstart first so the SDK is installed and a Lemma client can read your credentials. The per-primitive pages go deeper on each piece: Agent traces, Generations, Tool calls, Spans, and Threads and context. One agent execution is one lemma.trace() call. Record model calls, tool calls, and app work inside that trace. If that execution spans a host and a sandbox, follow Cross-process turns instead of starting a second root.

What you will build

Before you start

The examples assume you already have an agent shaped like this:

Steps

1

Wrap the whole agent run in a trace

Start with the root boundary. The returned value becomes the trace output.
2

Add a span around retrieval work

Use a span for app work that is not itself a model call or tool call.
Pass durationMs / duration_ms when you already measured the retrieval time. If you omit it, the SDK records timestamps and Lemma can allocate missing child durations from the parent.
3

Record each tool call

Record tools after they return so you can include both arguments and results.
Use stable, boring names like search_docs, lookup_order, and rerank_results. They make traces easier to scan.
4

Record the model call as a generation

Generations are for LLM calls. Include the model, prompt/input, output, and timing when available.
5

Record root trace duration when the run is done

Callback traces are measured automatically when the callback returns. For trace handles, record root duration when you call trace.end(...).
For open handles, leave duration blank until the work is actually finished. The SDK cannot know the final elapsed time until span.end(...), trace.end(...), or the callback returns.
6

Mark failures where you catch them

lemma.trace() records uncaught errors on the root trace. If you catch a tool or model error before re-raising, record that child failure too.

Go deeper

Use these pages for field-level detail and framework-specific tracing.

Trace contract

The exact fields and native SDK props Lemma reads.

Runnable examples

The same docs chat agent, instrumented once per stack.

Vercel AI SDK

Record AI SDK model calls and tool executions automatically.

Troubleshooting

Fix missing traces, empty outputs, and shape issues.