- TypeScript
- Python
onComplete(response) records the output explicitly. You can also omit it and rely on the return value being captured automatically:Trace an async, non-streaming agent function
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);
});
from uselemma_tracing import register_otel, TraceContext, wrap_agent
register_otel()
async def run_agent(ctx: TraceContext, user_message: str) -> str:
response = await call_llm(user_message)
ctx.on_complete(response)
return response
wrapped = wrap_agent("my-agent", run_agent)
result, run_id, _ = await wrapped(user_message)
ctx.on_complete(response) records the output explicitly. You can also omit it and rely on the return value being captured automatically:async def run_agent(ctx: TraceContext, user_message: str) -> str:
return await call_llm(user_message) # return value captured automatically as output