Skip to content

Hello Agent

Install the SDK, SQLite store, model adapter, and schema library:

bash
npm install @invariant-tech/sdk@beta @invariant-tech/sqlite@beta @invariant-tech/anthropic@beta zod
ts
import { invariant } from "@invariant-tech/sdk";
import { sqlite } from "@invariant-tech/sqlite";
import { anthropic, ANTHROPIC_MODELS } from "@invariant-tech/anthropic";
import { z } from "zod";

type GreetingOutput = { greeting: string };

const app = invariant({
  storage: sqlite("./data/hello-agent.db"),
  models: {
    default: anthropic({
      apiKey: process.env.ANTHROPIC_API_KEY,
      defaultModel: ANTHROPIC_MODELS.CLAUDE_SONNET_5,
    }),
  },
});

const greetingWorkflow = app
  .workflow("generate-greeting", {
    description: "Generate a structured greeting for a named person",
    inputSchema: z.object({ name: z.string() }),
  })
  .reason<GreetingOutput>("write-greeting", {
    instruction: "Write a concise greeting for the named person in execution context.",
    schema: {
      type: "object",
      properties: { greeting: { type: "string" } },
      required: ["greeting"],
      additionalProperties: false,
    },
  });

const helloAgent = app.agent("hello-agent", {
  instructions: "Help the user create a greeting. Use the registered workflow when a name is supplied.",
  workflows: [greetingWorkflow],
  projection: () => ({}),
  model: "default",
});

const session = await app.sessions.loadOrCreateSession("sess_hello", "usr_hello");
const result = await helloAgent.run({
  session,
  message: "Say hello to Ada",
});

if (result.outputDisposition === "present" && result.output !== undefined) {
  console.log(result.output);
}

The Agent interprets intent and proposes an allowed action. The workflow owns structured reasoning and execution state.

Next Steps

Invariant Durable Execution Engine.