// typescript sdk

TypeScript SDK

Wrap any async agent function to capture the full run, enable fork & replay, tag multi-agent work, and enforce per-run ceilings — ESM and fully typed.

Start freeRead the docs →

Wrap a function

Pass your async agent to trace() and the entire run is recorded — your code stays exactly the same.

Automatic capture

Calls to the major model providers are instrumented for you with prompts, responses, tokens, and cost.

Replay-ready

Set resumable: true to unlock cascade fork & replay later.

Multi-agent tagging

withAgent({ id, role }) scopes spans to an agent across async work — even with concurrent agents in one process.

Safe by default

Privacy redaction, an offline buffer with automatic transport fallback, and typed errors that never crash your agent.

Built-in enforcement & cassettes

Local per-run ceilings raise a typed RetraceEnforcementError, and writeGoldenCassette records a run as a CI fixture.

shell
npm i retrace-sdk

Install from npm (ESM).

agent.ts
import { configure, trace } from "retrace-sdk";

configure({ apiKey: "rt_..." });

const runAgent = trace(
  async (prompt: string) => agent.invoke(prompt),
  { name: "support-agent", resumable: true },
);

Configure once, then wrap any async function.

multi_agent.ts
import { withAgent } from "retrace-sdk";

withAgent({ id: "planner", role: "Planner" }, () => {
  return planAgent.run(task);
});

withAgent scopes spans to an agent.

More for developers