SynaptraDocs

    Concepts

    Run traces and failures

    A trace is the step-by-step record of what your agent did on one run. Send it with the run, and you can open any failed run and see why it failed. Synaptra sorts failures into classes, so you can see where a variant goes wrong.

    #

    What a trace is

    A trace travels in the run's row, in an optional trace field. It holds the steps the agent took (messages, tool calls, commands, checks), the error if one was thrown, the tail of its logs, and what it claimed at the end.

    • Open any failed run in the app or with GET /api/runs/{run_id}/trace and read what happened, step by step.
    • See why runs fail, per variant. Every failed or invalid run gets a failure class: yours, if you give one, or one Synaptra infers from the trace, the error and the run's status.
    • Compare failure patterns between an incumbent and a challenger: a change that fixes wrong answers but adds timeouts shows up at once.
    • Synaptra learns from them. Failure classes are counted like other results, so recommendations can aim at what actually goes wrong.
    #

    The trace field

    one row
    {
      "task": "t-118", "metrics": {"accuracy": 0},
      "trace": {
        "steps": [
          {"kind": "message", "name": "user", "input": "Where is my refund?"},
          {"kind": "tool", "name": "kb_search", "input": {"query": "refund"}, "output": ["a-12", "a-40"],
           "ok": true, "ms": 312, "at": "2026-11-29T10:04:11.502Z"},
          {"kind": "message", "name": "assistant", "output": "Refunds take 5 to 7 days."}
        ],
        "outcome": "Refunds take 5 to 7 days.",
        "logs": "...the tail of stdout and stderr...",
        "error": {"type": "TimeoutError", "message": "kb_search took 30 s", "stack": "..."},
        "failure": {"class": "wrong_answer", "detail": "cited the old refund policy"}
      }
    }
    FieldMeaning
    stepsWhat the agent did, in order. Each step: kind (message, tool, command, check, error, log or note), and optionally name, input, output, ok, ms and at (ISO time).
    error{type, message, stack} of an error the run threw.
    logsThe tail of stdout and stderr.
    outcomeWhat the agent claimed at the end, for example its final answer or "all tests pass".
    failure{class, detail}: your own classification. Leave it out and Synaptra infers one for a failed or invalid run.

    Every field is optional. Use check for steps that verify the work (running tests, validating output), so a claim of success with no check before it can be told apart from a wrong answer that was checked.

    #

    Failure classes

    ClassLabelMeans
    authAuthentication failedA key or token was refused, by your model provider or a service the agent called.
    rate_limitRate limitedA provider said too many requests, overloaded, or over quota.
    timeoutTimed outThe run or one of its steps hit a time limit.
    infraHarness or environment brokeThe container, network or harness failed: not the agent's fault. Invalid runs get this unless something more specific fits.
    crashAgent crashedThe agent's own code threw before it finished.
    budgetRan out of budgetA turn, step, token, context or spending limit stopped it.
    unverified_claimClaimed done without checkingIt said it was done, but ran no check after its last change.
    wrong_answerChecked, still wrongIt checked its work, and the result was still wrong.
    gave_upGave upIt said it couldn't do the task.
    unclassifiedNo reason knownNothing in the run says why.

    A run fails when its metric misses the tier's bar, or when its status is invalid. Passing runs get no class. The class you give wins over the inferred one; the run's trace says which it was (source: reported or inferred).

    #

    Recording a trace

    Both SDKs have a Trace that records steps as the agent works and goes into the row as trace. Here it wraps an agent loop, records each tool call with its timing, and reports:

    eval.py
    from synaptra_sdk import Harness, Trace
    
    h = Harness.connect("support-bot")
    
    def run_task(task):
        t = Trace()
        score = 0.0
        try:
            with t:                                        # an unhandled exception becomes the trace's error
                t.step("message", "user", input=task.prompt)
                for turn in range(20):
                    reply = model.respond(history)
                    t.step("message", "assistant", output=reply.text)
                    if not reply.tool_calls:
                        break
                    for call in reply.tool_calls:
                        with t.timed("tool", call.name, input=call.args) as s:
                            s["output"] = tools[call.name](**call.args)   # ms and ok are filled in
                t.outcome(reply.text)                      # what the agent claimed at the end
                score = grade(task, reply.text)
        except Exception:
            pass                                           # recorded in the trace; the run scores 0
        return {"task": task.id, "metrics": {"accuracy": score}, "trace": t}
    
    out = h.report([run_task(task) for task in tasks], experiment_id=42, variant="prompt-v2", tier="T1")
    print(out["traces"], out["failures"])                  # 20 {'wrong_answer': 3, 'gave_up': 1}
    eval.ts
    import { Harness, Trace } from "synaptra-sdk";
    
    const h = await Harness.connect("support-bot");
    
    async function runTask(task: Task) {
      const t = new Trace();
      let score = 0;
      try {
        await t.run(async () => {                          // an unhandled error becomes the trace's error
          t.step({ kind: "message", name: "user", input: task.prompt });
          let reply = await model.respond(history);
          for (let turn = 0; turn < 20; turn++) {
            t.step({ kind: "message", name: "assistant", output: reply.text });
            if (!reply.toolCalls.length) break;
            for (const call of reply.toolCalls)            // ms, ok and the result as output
              await t.timed("tool", call.name, () => tools[call.name](call.args), { input: call.args });
            reply = await model.respond(history);
          }
          t.outcome(reply.text);                           // what the agent claimed at the end
          score = await grade(task, reply.text);
        });
      } catch {
        // recorded in the trace; the run scores 0
      }
      return { task: task.id, metrics: { accuracy: score }, trace: t };
    }
    
    const rows = await Promise.all(tasks.map(runTask));
    const out = await h.report(rows, { experimentId: 42, variant: "prompt-v2", tier: "T1" });
    console.log(out.traces, out.failures);                 // 20 { wrong_answer: 3, gave_up: 1 }

    Commands, checks and logs:

    Python
    t.step("command", "bash", input="pytest -x", output=proc.stdout[-2000:], ok=proc.returncode == 0)
    t.step("check", "pytest", output="2 failed, 41 passed", ok=False)
    t.log(proc.stdout)                                     # only the last 16,000 characters are kept
    t.fail("budget", "stopped at the 50-turn limit")       # optional: your own class
    TypeScript
    t.step({ kind: "command", name: "bash", input: "pytest -x", output: stdout.slice(-2000), ok: code === 0 });
    t.step({ kind: "check", name: "pytest", output: "2 failed, 41 passed", ok: false });
    t.log(stdout);                                         // only the last 16,000 characters are kept
    t.fail("budget", "stopped at the 50-turn limit");      // optional: your own class
    PythonTypeScriptDoes
    t.step(kind, name, input, output, ok, ms)t.step({ kind, name?, input?, output?, ok?, ms? })Records one step. at is set to now.
    with t.timed(kind, name, input) as s:await t.timed(kind, name, fn, { input? })Records a step around a block with its ms. If it throws: ok false, the error as output, the trace's error set, and the error thrown on. In TypeScript the result becomes the output.
    t.error(exc)t.error(e)Records the run's error: type, message and stack, or a message.
    t.log(text)t.log(text)Appends to the logs. Only the tail is kept.
    t.outcome(text)t.outcome(text)What the agent claimed at the end.
    t.fail(cls, detail=None)t.fail(cls, detail?)Your own failure class; an unknown class is refused.
    with Trace() as t:await t.run(fn)Records an unhandled error, then raises it again.
    t.to_dict()t.toJSON()The trace as sent: capped and scrubbed.

    A plain dict or object with the same fields works in place of a Trace; it is capped and scrubbed the same way. The answer to the report counts the traces stored (traces) and the failures per class (failures).

    #

    Reading traces and failures

    MethodPathReturns
    GET/api/runs/{run_id}/trace{run_id, task, variant, tier, status, experiment_id, failure, trace, truncated, pruned, bytes, created_at}. failure is {class, label, detail, source} or null; trace is null when none was sent or it was pruned. 404 NOT_FOUND for an unknown run
    GET/api/harnesses/{id}/failures?experiment_id=&variant=&tier={harness_id, total_runs, failed, classes: [{class, label, n, share, run_ids}], by_variant: [{variant, runs, failed, classes}]}. Most common class first; run_ids are a few recent examples
    curl
    curl https://synaptra.my/api/runs/5120/trace \
      -H "Authorization: Bearer $SYNAPTRA_TOKEN"
    
    curl "https://synaptra.my/api/harnesses/support-bot/failures?experiment_id=42&tier=T1" \
      -H "Authorization: Bearer $SYNAPTRA_TOKEN"
    Python
    run = h.run_trace(5120)
    print(run["failure"])        # {'class': 'wrong_answer', 'label': 'Checked, still wrong', 'detail': ..., 'source': 'inferred'}
    
    f = h.failures(experiment_id=42, tier="T1")
    for c in f["classes"]:
        print(c["label"], c["n"], c["run_ids"])
    TypeScript
    const run = await h.runTrace(5120);
    console.log(run.failure);    // { class: "wrong_answer", label: "Checked, still wrong", detail: ..., source: "inferred" }
    
    const f = await h.failures({ experimentId: 42, tier: "T1" });
    for (const c of f.classes) console.log(c.label, c.n, c.run_ids);
    failures
    {
      "harness_id": "support-bot", "total_runs": 40, "failed": 9,
      "classes": [
        {"class": "wrong_answer", "label": "Checked, still wrong", "n": 5, "share": 0.556, "run_ids": [5120, 5114, 5101]},
        {"class": "timeout", "label": "Timed out", "n": 3, "share": 0.333, "run_ids": [5117, 5109, 5098]},
        {"class": "gave_up", "label": "Gave up", "n": 1, "share": 0.111, "run_ids": [5093]}
      ],
      "by_variant": [
        {"variant": "baseline", "runs": 20, "failed": 6, "classes": {"wrong_answer": 4, "timeout": 1, "gave_up": 1}},
        {"variant": "prompt-v2", "runs": 20, "failed": 3, "classes": {"wrong_answer": 1, "timeout": 2}}
      ]
    }

    The runs listing (GET /api/harnesses/{id}/runs) also says, per run, failure_class and whether it has_trace.

    #

    Limits and secrets

    • Steps. At most 300 are kept: the first 100 and the last 200, with a note between saying how many were left out.
    • Fields. Strings are cut to 4,000 characters; a step's input to 2,000. Inputs and outputs that aren't strings stay as JSON while short, else become their JSON text, cut.
    • Logs and stacks. logs keeps its last 16,000 characters; stack its last 4,000.
    • Size. A trace is at most 128 kB. Past that, step payloads are dropped from the middle first, so the start and the end stay readable.
    • Batches. The SDKs send at most 4 MB of rows per request, so reports with large traces go in more batches.

    Obvious secrets are replaced with [secret] before anything is stored: API keys and tokens (Anthropic, OpenAI, GitHub, AWS, Slack, Synaptra), Bearer headers, api_key=...-style values and private keys. The SDKs scrub them before sending too. Don't rely on it for everything: keep credentials out of what your agent prints.

    Something unclear or missing? Email support@synaptra.my.