Skip to main content
Set trace-level context when you open the trace.

Threads

When one user has a back-and-forth with your agent, each turn is its own trace. Give related turns the same threadId so Lemma groups them into one conversation.
await lemma.trace(
  {
    name: "support-agent",
    input: userMessage,
    threadId: conversationId,
  },
  async (trace) => {
    return runAgent(userMessage, trace);
  },
);

Users

await lemma.trace(
  {
    name: "support-agent",
    input: userMessage,
    threadId: conversationId,
    userId: user.id,
  },
  async (trace) => {
    return runAgent(userMessage, trace);
  },
);

Reference

ContextSDK optionAttribute keys
Agent namenamegen_ai.agent.name, ai.agent.name
Thread / conversationthreadIdlemma.thread_id
UseruserIduser.id, enduser.id
See the trace contract for how each field is read.

Next steps

Trace contract

The exact shape Lemma reads.

Good trace vs bad trace

Conformant vs malformed traces.