Skip to main content
Use this for the standard case: an async agent function that awaits an LLM call and returns a single response.
import { registerOTel, wrapAgent } from "@uselemma/tracing";

registerOTel();

const wrapped = wrapAgent("my-agent", async ({ onComplete }, input: { userMessage: string }) => {
  const response = await callLLM(input.userMessage);
  onComplete(response);
  return response;
});

const { result, runId } = await wrapped({ userMessage });
onComplete(response) records the output explicitly. You can also omit it and rely on the return value being captured automatically:
const wrapped = wrapAgent("my-agent", async (_ctx, input: { userMessage: string }) => {
  return await callLLM(input.userMessage);
});
To add per-call LLM visibility (prompt, response, tokens), register the matching OpenInference instrumentor for your provider at startup. Details: Provider instrumentation.