agentwatch-sdk
v0.1.9
Published
TypeScript SDK for AgentWatch — observability for multi-agent AI systems
Downloads
26
Maintainers
Readme
AgentWatch TypeScript SDK
TypeScript/JavaScript SDK for AgentWatch — observability for multi-agent AI systems.
Zero runtime dependencies. Works with Node.js 18+ using native fetch.
Installation
npm install agentwatch-sdk
# or
pnpm add agentwatch-sdk
# or
yarn add agentwatch-sdkQuick Start
import {
init,
recordTrace,
shutdown,
createInteractionTrace,
createSpanRecord,
createAgentNode,
SpanKind,
} from "agentwatch-sdk";
// Initialize the SDK
init({
publicKey: "aw_pub_...",
secretKey: "aw_sec_...",
endpoint: "http://localhost:8080",
});
// Record a trace
recordTrace(
createInteractionTrace({
framework: "custom",
agents: [
createAgentNode({ name: "planner", framework: "custom" }),
createAgentNode({ name: "executor", framework: "custom" }),
],
spans: [
createSpanRecord({
name: "agent.planner",
kind: SpanKind.AGENT,
inputData: "Plan a trip to Paris",
outputData: "Here is the itinerary...",
}),
createSpanRecord({
name: "llm.gpt-4o",
kind: SpanKind.LLM,
inputData: "System: You are a travel planner...",
outputData: "I recommend visiting...",
}),
],
}),
);
// Flush and shut down before process exit
await shutdown();Configuration
| Option | Env Variable | Default | Description |
|--------|-------------|---------|-------------|
| publicKey | AGENTWATCH_PUBLIC_KEY | "" | AgentWatch public key |
| secretKey | AGENTWATCH_SECRET_KEY | "" | AgentWatch secret key |
| endpoint | AGENTWATCH_ENDPOINT | http://localhost:8080 | Backend URL |
| flushIntervalMs | — | 500 | Flush interval (ms) |
| flushBatchSize | — | 100 | Max traces per flush |
| redactionPatterns | — | [] | Regex patterns for PII redaction |
Payload Redaction
Redact sensitive data before it leaves your process:
import { init, REDACT_EMAIL, REDACT_SSN, REDACT_API_KEY } from "agentwatch-sdk";
init({
redactionPatterns: [REDACT_EMAIL, REDACT_SSN, REDACT_API_KEY],
});Matching text in span input/output is replaced with [REDACTED] before export.
API Reference
Top-level Functions
init(options?)— Initialize the SDK and start the flush loopshutdown()— Async. Flush remaining data and stop the enginerecordTrace(trace)— Enqueue a trace for exportgetEngine()— Get the active engine instance (ornull)
Factory Functions
createInteractionTrace(overrides?)— Create a trace with defaultscreateSpanRecord(overrides?)— Create a span with defaultscreateAgentNode({ name, framework, ...overrides })— Create an agent nodecreateAgentInteraction({ traceId, fromAgent, toAgent, interactionType, ...overrides })— Create an interaction
Enums
SpanKind—AGENT,LLM,TOOL,HANDOFF,GUARDRAILInteractionType—HANDOFF,STATE_TRANSFER,DELEGATION
Helpers
getAgentCount(trace)— Number of agents in a tracehasError(trace)— Whether any span has error statusgetDurationMs(trace)— Trace duration in ms (ornull)truncatePayload(text)— Truncate to 10,000 chars with suffix
Classes
AgentWatchEngine— Core engine (buffer + flush + retry)AgentWatchExporter— OTLP JSON builder + HTTP exporterRedactionConfig— Regex-based payload redaction
License
Apache-2.0
