SDK reference
TypeScript SDK
syntropylabs-evalkit for Node.js: sessions and named agents, the Eval() rows that agent evaluators read, scenario simulation with a live simulated user, and a summary of errors, health, shutdown and serverless flushing.
EvalKit for Node.js is the syntropylabs-evalkit package on npm. Most of this reference is still being written; sessions, agents, the Eval() rows that agent evaluators read and scenario simulation are documented below, with a summary of errors, health and shutdown. Every init() option is on Configuration and privacy.
Sessions and agents
A session is one conversation. Every span started inside withSession(...) belongs to that session. An agent is the name you give your agent in code. After setAgent(...), every trace carries that name, and Traces → Agents shows the agent's sessions, versions and verdicts. You never declare a version: the trace service detects it from the model, system prompt, tools, temperature and top-p.
import { setAgent, startTrace, withSession } from "syntropylabs-evalkit";
setAgent("support-bot"); // every trace after this belongs to support-bot
setAgent(null); // clears
await withSession({ sessionId: "conv_55", userId: "u_8123" }, async () => {
await agent.reply(message);
});
const turn = startTrace("chat-turn", { agentName: "support-bot" }); // this trace only- When
withSessionreturns, the previous session comes back. On Node the scope follows the async context, so concurrent requests never see each other's session. - Spans carry the agent as
evalkit.agent_nameandgen_ai.agent.name. A span started with{ "gen_ai.agent.name": "researcher" }belongs to that sub-agent. - A span that already carries
session.id,conversation.id,gen_ai.conversation.idorevalkit.session_idkeeps its own session. - OpenAI and Anthropic model-call spans record
temperature,top_p, max tokens and the request body (gen_ai.request.body). From 0.3.2, model-call spans also list the tools the request offered ingen_ai.request.tools, for OpenAI, Anthropic, Bedrock, Google, Vertex AI, Cohere, Ollama and LangChain. The trace service reads the tools from that attribute and falls back to the request body, so a tool change gives a new version. - From 0.3.1, a tool call the model only requested is a
gen_ai.tool.callevent on its model-call span. The tool your code runs throughtraceToolis thetool_callspan, so each call is counted once. When the provider runs a tool itself and returns its result, that tool still gets its owntool_callspan.
Eval() rows for agent evaluators
Agent evaluators such as Step Efficiency, Argument Correctness and Role Adherence read the agent's turns and tool calls. A row with only text skips them with the reason "This row has only text. Pass trace_id, session_id or messages to evaluate the agent's turns and tool calls." A row gives them what they read by pointing at a recorded trace or session, or by carrying the conversation:
import evalkit, { Eval, type EvalRow } from "syntropylabs-evalkit";
const rows: EvalRow[] = [
// A session or trace already recorded in the key's project and Environment
{ input: "Refund order 1001", output: reply, sessionId: "conv_55" },
{ input: "Where is order 1002?", output: answer, traceId },
// The conversation itself, in OpenAI chat format
{ input: "Refund order 1001", output: reply,
messages, // user, assistant (with tool_calls) and tool messages
tools, // OpenAI tool definitions with JSON Schema parameters
systemPrompt }, // optional, like tools
];
await evalkit.flush(); // send the recorded spans before the run is scored
await Eval({ name: "agent-regression", data: rows, evaluators: [STEP_EFFICIENCY_ID, ROLE_ADHERENCE_ID] });- From 0.3.3,
traceId,sessionId,messages,toolsandsystemPromptare row keys of their own, as above, and the snake_case spellingstrace_id,session_idandsystem_promptare accepted too. An empty id, ormessagesortoolsthat is not an array, throws naming the row before the run opens. With 0.3.2, put the same keys inmetadatain snake_case, such asmetadata: { session_id: "conv_55" }. The server reads either place, and a top-level key wins over itsmetadatatwin. - From a trace or session, the server builds the turns, the tool calls with their arguments and results, the declared tools and the system prompt. If the trace has not arrived when the run is scored, the agent evaluators skip that row with a reason that says so.
input,outputandexpectedstill feed the row-level evaluators. Turns in the results are numbered from 1. See Runs from code for a whole conversation row.
Scenario simulation
generateScenarios() has the server write scenarios for your agent, simulateUser() plays them against your agent in your own process, and evaluateSimulation() grades the run with an evaluator collection. The server side needs a plan with simulations.
import evalkit from "syntropylabs-evalkit";
const scenarios = await evalkit.generateScenarios({
agentInstructions: "You are a billing support agent.",
tools: ["lookup_order", "issue_refund"],
count: 5,
});
const { results } = await evalkit.simulateUser({
scenarios,
entrypoint: async (ctx) => {
const { text, toolCalls } = await runMyAgent(ctx.sessionId, ctx.message); // one turn of your agent
return { text, toolCalls }; // [{ name, args, result }], or error for a failed call
},
userModel: "sim-user", // the Model the simulated user runs on, by name or id
maxTurns: 8,
});
for (const r of results) console.log(r.name, r.status, r.endedBy);| Option | Default | What it does |
|---|---|---|
maxTurns | 12 | The most user turns one scenario plays. The live user plays at most 50, whatever this says. |
userModel | model | The Model of your organization the simulated user runs on, by its name or id. A live scenario without one fails with "No model is configured for the simulated user". |
liveUser | on for a scenario with a user_goal or conversation_plan and no turns | true plays the live user after the scripted turns of any scenario. false replays the scripted turns only. |
metrics | all | The deterministic metrics each scenario is scored with in your process |
tags, safeMode | none, true | Labels for the run; safeMode is copied into ctx.state.__safe_mode__ for your agent to guard side effects |
- After the scripted turns, or from the opening message when a scenario has none, the platform plays the user from the scenario's persona,
user_goal,hidden_infoand tool answers, reading the conversation so far. It stops once its goal is met ormaxTurnsuser turns were played. - The
toolCallsanAgentTurnResultreports, with theirresultorerror, tell the user what actually happened, such as a refund the agent says it issued that its tool refused. The user reacts only to what the agent says and never quotes them. - Each user turn is a
simulated_userspan markedevalkit.simulation.role: user, inside the scenario's trace. Evaluations never read it as the agent's turn, tool call or output. - A live scenario's result also carries
transcript(the conversation asroleandcontentmessages),endedBy(user,max_turnsorerror) andsimulatedUserUsage(calls,inputTokens,outputTokensandcostUsd, which isnullwhen the Model has no price). - If the user cannot play a turn, the scenario ends with status
ERRORand the platform's reason.
The simulated user runs on your organization's Model, so its calls are billed to your provider account. Their cost is recorded per Environment and shows on Cost as Simulated user. The platform plays at most 50 user turns of one scenario, answers 120 user-turn requests a minute per Environment, and plays 5,000 simulated user turns per organization per UTC day; past that it answers 429 until midnight UTC.
generateScenarios() writes briefs for the live user: each scenario carries its persona, user_goal, hidden_info (facts the user shares only once the agent asks about them), success_criteria and its opening message in starting_prompt, and no later turns. Pass scriptedTurns: true for scenarios with every user turn written out in turns, to replay a conversation word for word.
Errors, health and shutdown
import evalkit from "syntropylabs-evalkit";
evalkit.init({
subscriptionKey: process.env.EVALKIT_SUBSCRIPTION_KEY!,
sampleRate: 0.25, // a quarter of traces; model calls, tool calls and errors are always kept
captureGlobalErrors: true, // also record uncaught exceptions and unhandled rejections
sourceMaps: true, // frames point at your TypeScript sources
});
evalkit.captureException(err); // an error your code handled, on the active span
evalkit.getStats(); // queued, exported and dropped spans, the last error, the circuit's state
await evalkit.flush(2000); // resolves false, never rejects, after 2 seconds at most
export const handler = evalkit.withLambda(myHandler); // AWS Lambda: flush before each invocation returns- From 0.3.6, a failed span records one
exceptionevent with frames, its source line and its causes, andexpressErrorHandler()records the error an Express route passed on; see Errors and stack traces. - Shutdown, serverless and edge: spans are sent on
beforeExit,SIGTERMandSIGINT(exitHooks);withLambdaandflushAfterflush per invocation, and edge runtimes import a stub; see Workers and shutdown and Serverless and edge runtimes. - Console capture, limits, the circuit breaker and
getStats(): Logs and console output, Limits and memory and Export failures and health.EVALKIT_DISABLED=trueturns the SDK off. - What changes for an upgrade: Upgrading to 0.3.7 and Upgrading to 0.3.6.