Cortex · guides
How to do things with Cortex.
Each guide is a file you can run. These ask a model, so this site checks their types and does not run them, and each page says what comes back.
First steps.
An agent with one tool, which knows how many seats are left, is asked about Saturday, and the file prints its typed answer.
pnpm add @niscorp/cortex @niscorp/signal zod openaiGROQ_API_KEY=your-key npx tsx first.mtsimport { z } from 'zod';
import { createSignal } from '@niscorp/signal';
import { defineAgent, defineTool } from '@niscorp/cortex';
const seatsLeft = defineTool({
id: 'seatsLeft',
name: 'seatsLeft',
description: 'How many of the 120 seats are left on a night',
input: z.object({ night: z.string().describe('The night, as YYYY-MM-DD') }),
execute: ({ night }) => ({ night, left: night === '2026-10-24' ? 113 : 120 }),
});
const boxOffice = defineAgent({
id: 'box-office',
instructions: 'Look the night up with the seatsLeft tool, then give the answer.',
tools: [seatsLeft],
output: { schema: z.object({ left: z.number() }) },
});
const llm = createSignal('groq');
const result = await boxOffice.run('How many seats are left for The Tempest on 2026-10-24?', { llm }).result;
console.log(result.ok ? result.output.data : result.error.message);This one needs a model: it asks Groq through Signal, with the key it reads from GROQ_API_KEY. No page on this site calls a model, so nothing is printed here. The agent calls the tool, reads what it returns, and answers with an object of its output schema. If the run fails, the file prints why.
Then, one at a time.
Each is a file of its own and adds one thing. Read them in order, or go to the one you need.