# 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 {#complete-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 };
  },
});
```

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 {#seven-primitives}

```ts
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 {#product-sdk-guides}

| Building | Focused guide |
| --- | --- |
| Agent behavior and Resources | [Agents SDK guide](/docs/agents/sdk.md) |
| Durable work inside a Run | [Runs SDK guide](/docs/runs/sdk.md) |
| Resources and Tools | [Resources SDK guide](/docs/resources/sdk.md) |
| Memory operations | [Memory SDK guide](/docs/memory/sdk.md) |
| Channels and Auth Providers | [Channels SDK guide](/docs/channels/sdk.md) |
| Executable Policy | [Policies SDK guide](/docs/policies/sdk.md) |
| Custom analytics | [Analytics SDK guide](/docs/analytics/sdk.md) |
| Credential Provider lifecycle | [Credentials SDK guide](/docs/credentials/sdk) |

Start with [Set up an SDK project](/docs/sdk/project.md), then choose [Agents](/docs/sdk/agents.md), [Resources and Tools](/docs/sdk/resources-and-tools.md), [Channels and Auth Providers](/docs/sdk/channels-and-auth.md), [Policies and analytics](/docs/sdk/policies-and-analytics.md), or [Credential Providers](/docs/sdk/credential-providers.md). Read [The seven Agent primitives](/docs/foundations/seven-primitives.md) for the runtime contract behind the examples.
