Skip to main content
One call to wrapAgent produces one run in your dashboard. Give it an agent name and an async function; the SDK generates a run_id, opens a tracing context, runs your function, captures every child span, and flushes the result.

Example

import trodo from 'trodo-node';

trodo.init({ siteId: process.env.TRODO_SITE_ID });

const { result, runId } = await trodo.wrapAgent(
  'support-agent',                         // agentName  (required)
  async (run) => {
    run.setInput({ question: 'refund policy?' });
    run.setMetadata({ env: 'prod', version: '1.2.0' });

    try {
      const answer = await askLlm(...);   // spans captured inside the callback
      run.setOutput({ answer });           // run.status becomes 'ok'
      return answer;
    } catch (err) {
      run.setErrorSummary(err.message);   // run.status becomes 'error'
      throw err;
    }
  },
  { distinctId: 'user-42', conversationId: 'thread-abc' },
);

What you set vs what’s rolled up

You set on the RunHandleAuto-rolled from spans
agentName, distinctId, conversationIdduration_ms (callback start → end)
setInput / setOutput / setMetadatatotal_tokens_in, total_tokens_out
setErrorSummarytotal_cost
span_count, tool_count, error_count
status (ok / error / running)
Duration, tokens, cost, and status are computed for you — you never write them. total_tokens_in / total_tokens_out / total_cost are summed across every kind='llm' span inside the run.

Options

Option (Node / Python)Purpose
agentNameRequired. Free-text identifier — "support-bot", "ticket-triage-v2".
distinctId / distinct_idYour user id. Lets you filter runs per user.
conversationId / conversation_idGroups runs from the same chat thread.
parentRunId / parent_run_idMarks this run as a sub-agent. See Recipes → Sub-agents.
metadataFree-form JSON tags. Same as calling setMetadata up-front.

Next