SynaptraDocs

    Examples

    Example: support and triage agent

    An LLM agent that answers customer tickets, using a help-centre search and a ticket tool, judged on whether its first reply resolves the ticket.

    #

    What it registers

    KindNameWhat
    actionkb_searchSearch the help centre: query, k.
    actionset_categoryTriage: one of billing, bug, how-to, account.
    actionescalateHand over to a person, with a reason.
    scorerresolved1 if a rubric judge says the reply resolves the ticket, else 0; plus category_ok.
    datasettickets-2026q3600 past tickets with resolutions, in your bucket. Fingerprint only.
    runnerrunnerpython run_agent.py --variant {variant} --tier {tier} --seed {seed}
    #

    How it's scored

    The metric is resolved (first-reply resolution, higher is better, bar 0.70). A model judge applies a written rubric to each reply against the known resolution; category_ok is exact match on the triage label. Because the same ticket can get different replies, each task runs with two seeds on the dev set.

    #

    The code

    support_harness.py
    import os
    from synaptra_sdk import Harness
    
    h = Harness.create("Support agent", objective="Resolve tickets on the first reply",
                       metric="resolved", direction="max", bar=0.70, template="llm_agent",
                       url="https://synaptra.my", token=os.environ["SYNAPTRA_TOKEN"])
    
    @h.tool
    def kb_search(query: str, k: int = 5) -> list:
        """Search the help centre and return the top k articles."""
    
    @h.tool
    def set_category(category: str) -> None:
        """Triage the ticket: billing, bug, how-to or account."""
    
    @h.tool
    def escalate(reason: str) -> None:
        """Hand the ticket to a person."""
    
    @h.scorer
    def resolved(reply: str, ticket: dict) -> float:
        """Rubric judge: does the reply resolve the ticket? 1 or 0."""
        return judge(RUBRIC, reply=reply, resolution=ticket["resolution"])
    
    h.dataset("tickets-2026q3", path="s3://support-evals/tickets-2026q3.jsonl", size=600)
    h.runner("python run_agent.py --variant {variant} --tier {tier} --seed {seed}")
    support_harness.ts
    import { Harness } from "synaptra-sdk";
    
    const h = await Harness.create({
      name: "Support agent", objective: "Resolve tickets on the first reply",
      metric: "resolved", direction: "max", bar: 0.7, template: "llm_agent",
      url: "https://synaptra.my", token: process.env.SYNAPTRA_TOKEN,
    });
    
    await h.tool({ name: "kb_search", description: "Search the help centre and return the top k articles.",
      schema: { type: "object", properties: { query: { type: "string" }, k: { type: "integer", default: 5 } },
                required: ["query"] } }, kbSearch);
    await h.tool({ name: "set_category", description: "Triage the ticket: billing, bug, how-to or account.",
      schema: { type: "object", properties: { category: { enum: ["billing", "bug", "how-to", "account"] } },
                required: ["category"] } }, setCategory);
    await h.tool({ name: "escalate", description: "Hand the ticket to a person.",
      schema: { type: "object", properties: { reason: { type: "string" } }, required: ["reason"] } }, escalate);
    
    await h.scorer({ name: "resolved", description: "Rubric judge: does the reply resolve the ticket? 1 or 0." },
      ({ reply, ticket }) => judge(RUBRIC, { reply, resolution: ticket.resolution }));
    
    await h.dataset("tickets-2026q3", { path: "s3://support-evals/tickets-2026q3.jsonl", size: 600 });
    await h.runner("node run_agent.js --variant {variant} --tier {tier} --seed {seed}");
    run_agent.py
    # run_agent.py (abridged): runs one variant on one tier and reports the rows
    rows = []
    for seed in SEEDS[tier]:
        for t in tickets_for(tier):
            reply, usage = agent(variant, t, seed=seed)
            rows.append({"task": t["id"], "variant": variant, "tier": tier,
                         "metrics": {"resolved": resolved(reply, t),
                                     "category_ok": float(predicted_category == t["category"])},
                         "cost_usd": price(usage), "meta": {"axes": {"seed": seed}}})
    h.report(rows, experiment_id=args.experiment)
    run_agent.ts
    // run_agent.ts (abridged): runs one variant on one tier and reports the rows
    const rows = [];
    for (const seed of SEEDS[tier]) {
      for (const t of ticketsFor(tier)) {
        const { reply, category, usage } = await agent(variant, t, { seed });
        rows.push({ task: t.id, variant, tier,
                    metrics: { resolved: await resolved({ reply, ticket: t }), category_ok: Number(category === t.category) },
                    cost_usd: price(usage), meta: { axes: { seed } } });
      }
    }
    await h.report(rows, { experimentId: args.experiment });
    #

    A first experiment

    Python
    e = h.propose(
        "Search before answering", "search-first",
        {"T0": {"pass_rate": 1}, "T1": {"mean_resolved": 0.74, "cost_usd": 3.5}},
        hypothesis="Replies miss policy details the help centre has",
        treatment_axes=["prompt"],
    )
    TypeScript
    const e = await h.propose({
      title: "Search before answering",
      variant: "search-first",
      hypothesis: "Replies miss policy details the help centre has",
      predictions: { T0: { pass_rate: 1 }, T1: { mean_resolved: 0.74, cost_usd: 3.5 } },
      treatmentAxes: ["prompt"],
    });
    POST /api/harnesses/support-agent/experiments
    {"title": "Search before answering", "variant": "search-first",
     "hypothesis": "Replies miss policy details the help centre has",
     "treatment_axes": ["prompt"],
     "predictions": {"T0": {"pass_rate": 1}, "T1": {"mean_resolved": 0.74, "cost_usd": 3.5}}}
    #

    What this won't tell you

    • Whether customers are happier: the judge reads replies, not satisfaction.
    • Whether a win holds on new kinds of tickets. Refresh the test set when your product changes (its new fingerprint will show).
    • Anything about a model or prompt you didn't try.

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