Skip to main content
Use Lemma’s OpenAI Agents integration when your app uses the OpenAI Agents SDK trace processor system. The integration creates one Lemma trace for each OpenAI Agents trace, maps model calls to generations, maps function calls to tools, and preserves parent IDs so child spans stay nested correctly. You do not need to wrap agent runs in lemma.trace(). Register the processor once, then run OpenAI Agents normally.

TypeScript

Install both packages:
Register the Lemma processor before running agents. By default, credentials are read from LEMMA_API_KEY and LEMMA_PROJECT_ID:
You can also pass credentials and identity options directly:
Then run your agent normally:

Python

Install the Python extra:
Register the Lemma processor before running agents. By default, credentials are read from LEMMA_API_KEY and LEMMA_PROJECT_ID:
You can also pass credentials and identity options directly:
Then run your agent normally:

Root input, output, user, and thread

Both TypeScript and Python processors promote the same root fields on the Lemma trace: Soft tool failures (isError / is_error / Mastra error: true) mark the tool span as ERROR without failing the root when a later generation succeeds.

Flush and shutdown

Call forceFlush() / force_flush() (or shutdown()) to send any still-open traces exactly once. A later onTraceEnd / on_trace_end for a flushed trace is a no-op, so spans are never duplicated in the append-only ingest store.

What Lemma records

OpenAI Agents trace group_id is recorded as the Lemma thread id, so runs in the same conversation stay grouped.

Privacy

The integration always records prompts, tool inputs, tool outputs, model output, and error messages — a trace cannot show what a run produced or why it failed without them. Redact secrets and sensitive user data before they reach the agent.

Debugging

Use debug mode to confirm spans are arriving live and nested under the expected parent:
Look for span started and span ended logs. Tool/function spans should include the generation or agent span ID as parentId in TypeScript or parent_id in Python.