Author an Agent
Build a typed Agent package with model calls, durable state, Tools, Resources, analytics, and explicit limits.
Before you begin
Choose a stable Agent id and semantic version. Configure a logical Model Resource, list every external capability the Agent needs, and identify the Policy boundaries and budget appropriate for its work. Run npm install @constal/sdk in an ESM package.
Steps
- Export
agent()from the manifest entrypoint. A script Agent providesonMessage; a durable Agent providesinit,step, andoutput. - Set
modelto a logical manifest binding name, not an external provider model id. - Use
ctx.turn()for model work. Pass only the context the current turn needs and enable streaming only when the caller can consume it. - Use
ctx.resourcesplusctx.invoke()or a declared Tool for external operations. Never use arbitrary CRNs from message input and never put Credential material in code, prompts, or manifests. - Use
ctx.commit(),ctx.await(),ctx.spawn(),ctx.step(), and ledger operations for durable workflow behavior. Every external effect belongs behind a governed Resource operation with a truthful effect and recovery contract. - Declare custom analytics with
analyticsEvent()and register every declaration in the Agent definition before emitting it. - Add
constal.agent.jsonwith matching id, version, entry, mode, fixed or scoped bindings, attached Policies, exposed Tool names, limits, and expected current deployment revision.
import { agent } from "@constal/sdk";
export default agent({
id: "triage", version: "1.0.0", model: "model",
async onMessage(message, ctx) {
const turn = await ctx.turn({
system: "Classify and resolve the request using only offered capabilities.",
objective: message,
tools: ["lookup_ticket"],
});
return turn.message.content;
},
});Verify
Type-check the project, deploy it, and start a controlled Run. Confirm the detail page shows the intended version, mode, logical bindings, Policies, Tools, and limits. Inspect the Run journal to verify every model and Resource operation is pinned and accounted.
Next steps
Choose a proven composition from the Agent patterns catalog, then read Durable Agent patterns, Deploy an Agent, and Resources and Tools.