Constal SDK
Author executable Agent, Channel, Auth Provider, Policy, Credential Provider, Tool, and runtime integration contracts in TypeScript.
@constal/sdk defines code that Constal builds and executes. It is not a tenant-administration client: deployment, configuration, Run control, and inspection belong to the Console, CLI, or Platform API.
A complete native Agent
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 };
},
});The returned value becomes durable Run output. model is a logical Resource binding accepted at deployment, not a provider name supplied by the caller.
The seven primitives in code
const turn = await ctx.turn({ system: "Decide.", objective: input });
const history = await ctx.ledger.view("history");
const fact = await ctx.commit({ decision: turn.message.content });
const answer = await ctx.await("approval", { timeout: 86_400_000, onTimeout: { approved: false } });
const child = await ctx.spawn(registeredTask, input, { retries: 2 });
const mapped = await ctx.map(registeredPartitionFn, rows, { partition: { rows: 100 } });
const reduced = await ctx.reduce(registeredFoldFn, mapped, { scope: "global" });Resources, Tools, Policy, Channels, and Credentials support this language without adding more primitives. Each focused guide below supplies a complete definition rather than a prose-only contract.
Product SDK guides
| Building | Focused guide |
|---|---|
| Agent behavior and Resources | Agents SDK guide |
| Durable work inside a Run | Runs SDK guide |
| Resources and Tools | Resources SDK guide |
| Memory operations | Memory SDK guide |
| Channels and Auth Providers | Channels SDK guide |
| Executable Policy | Policies SDK guide |
| Custom analytics | Analytics SDK guide |
| Credential Provider lifecycle | Credentials SDK guide |
Start with Set up an SDK project, then choose Agents, Resources and Tools, Channels and Auth Providers, Policies and analytics, or Credential Providers. Read The seven Agent primitives for the runtime contract behind the examples.