Skip to main content
Use this when your agent function is synchronous — no async/await, no streaming.
import { registerOTel, wrapAgent } from "@uselemma/tracing";

registerOTel();

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

const { result, runId } = await wrapped({ userMessage });
Even if the wrapped logic is synchronous, wrapAgent returns an async function in TypeScript, so the call site still uses await.
onComplete(response) / ctx.on_complete(response) records the output explicitly. You can also omit it and rely on the return value being captured automatically.