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

  1. Export agent() from the manifest entrypoint. A script Agent provides onMessage; a durable Agent provides init, step, and output.
  2. Set model to a logical manifest binding name, not an external provider model id.
  3. Use ctx.turn() for model work. Pass only the context the current turn needs and enable streaming only when the caller can consume it.
  4. Use ctx.resources plus ctx.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.
  5. 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.
  6. Declare custom analytics with analyticsEvent() and register every declaration in the Agent definition before emitting it.
  7. Add constal.agent.json with matching id, version, entry, mode, fixed or scoped bindings, attached Policies, exposed Tool names, limits, and expected current deployment revision.
ts
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.