Build Agents with the SDK
Navigate the SDK contracts used to author Agent behavior, durable execution, Tools, Resources, and analytics.
Use @constal/sdk inside the immutable Agent package. The smallest useful Agent reads accepted history, makes one model turn, and returns a result that the runtime records durably:
Minimal Agent
ts
import { agent, type HistoryView } from "@constal/sdk";
export default agent({
id: "support", version: "1.0.0", model: "model",
async onMessage(message, ctx) {
const history = await ctx.ledger.view<HistoryView>("history");
const turn = await ctx.turn({
system: "Resolve the request accurately.",
objective: message,
context: { priorFacts: history.facts },
});
return { answer: turn.message.content };
},
});model is a logical Resource binding, not caller-selected provider input. ctx.resources contains only accepted CRNs, and Credential bytes never enter Agent code.
Add a durable boundary
ts
async onMessage(message, ctx) {
if (message.kind === "checkpoint") {
return ctx.commit({ kind: "checkpoint", payload: message.payload });
}
return { accepted: true };
}Use Durable Agent patterns for waits and subtasks, Resources SDK guide for effects, and Analytics SDK guide for typed events. Deployment remains a Console, CLI, or Platform API operation; it is intentionally absent from Ctx.