agentsentriopen-source LLM observabilityDashboard

guide

TypeScript SDK

@agentsentri/sdk gives Node/TS apps the same surface as the Python SDK: batch tracing handles, automatic nesting via wrap(), and typed clients for every public API. Zero runtime dependencies; observability never crashes or blocks your app.

The walkthrough

  1. 1.Install the SDK

    Add the package from npm (Node 18+). Until the first sdk-v* release is published, develop against the monorepo workspace package instead.

    pnpm add @agentsentri/sdk
    # or: npm i @agentsentri/sdk
  2. 2.Create a client

    Zero runtime dependencies. Config falls back to AGENTSENTRI_SECRET_KEY and AGENTSENTRI_BASE_URL (then AGENTSENTRI_HOST, shared with the Python SDK).

    import { AgentSentri } from "@agentsentri/sdk";
    
    const sentri = new AgentSentri({
      secretKey: "sk-as-...",           // or AGENTSENTRI_SECRET_KEY
      baseUrl: "http://localhost:3000", // or AGENTSENTRI_BASE_URL
    });
  3. 3.Trace with explicit handles

    A trace is one end-to-end run; spans, generations, and events nest under it. Generations carry model + usage so cost is computed server-side. Events buffer and send in batches — flush() drains explicitly, shutdown() drains before exit.

    const trace = sentri.trace("answer-question", { userId: "user-1" });
    const gen = trace.generation("llm-call", { model: "claude-sonnet-5" });
    gen.setInput({ prompt: "What is observability?" });
    // ... call your LLM however you like ...
    gen.setOutput({ answer: "..." });
    gen.setUsage({ inputTokens: 42, outputTokens: 100 });
    gen.end();
    await sentri.flush();
  4. 4.Or wrap() functions — nesting is automatic

    wrap() instruments an async function: each call becomes a trace, and any wrapped function called inside it becomes a correctly-parented child observation (AsyncLocalStorage tracks the context). Errors mark the observation and re-throw.

    import { wrap } from "@agentsentri/sdk";
    
    const answer = wrap(sentri, async (q: string) => {
      return retrieve(q).then(generate);   // wrapped fns nest automatically
    }, { name: "answer", asType: "GENERATION" });
    
    await answer("What is observability?");
  5. 5.Use the typed resource APIs

    Every public route has a typed method: scores, datasets & items, experiments & results, prompts + versions + render, evaluators, eval runs & schedules, metrics, and the LLM connection. Non-2xx responses throw a typed ApiError carrying status and the parsed body.

    await sentri.createScore({ name: "quality", traceId: trace.id, value: 0.9 });
    const ds = await sentri.createDataset({ name: "support-eval" });
    await sentri.createEvalSchedule({ evaluatorId, cadence: "hourly" });
    const metrics = await sentri.getMetrics({ days: 7 });

Parity notes vs the Python SDK

The two SDKs mirror each other; these divergences are intentional and documented:

baseUrl vs hostThe constructor option is baseUrl (idiomatic TS); env fallbacks are AGENTSENTRI_BASE_URL, then AGENTSENTRI_HOST — shared with Python.
Bounded retry on ingestFailed batches get max 2 retries with capped jittered backoff, then drop + onError (default console.warn). Python drops-and-warns without retrying; both never crash or block the host app.
wrap() instead of a decoratorPython's @observe maps to the wrap() higher-order function; nesting uses AsyncLocalStorage instead of contextvars.