Module authoring overview
A module is a repository of its own. It talks to the host only through a single typed object, ctx, and never imports Knetik’s server internals. You write TypeScript, and the host runs it.
Repository layout
Section titled “Repository layout”knetik.module.ts default export of defineModule(...)agents/ greeter.ts one agent per filemodule.test.ts tests, run by `knetik test`fixtures/ dev-model.ts what the scripted model answers (knetik dev) dev-connectors.ts mock connectors (knetik dev) dev-config.json per-deployment config values (knetik dev) inputs/*.json sample inputs, validated by `knetik check`package.jsonOnly knetik.module.ts and the agents are required. A module repo needs just three Knetik packages as dev dependencies: @knetikdotdev/sdk, @knetikdotdev/testing and @knetikdotdev/cli. Until the packages are published, they are referenced by file: path, as the hello module does:
{ "name": "knetik-module-hello", "type": "module", "devDependencies": { "@knetikdotdev/sdk": "file:../knetik/packages/sdk", "@knetikdotdev/testing": "file:../knetik/packages/testing", "@knetikdotdev/cli": "file:../knetik/packages/cli" }, "scripts": { "check": "knetik check", "test": "knetik test", "dev": "knetik dev --host ../knetik" }}The smallest module
Section titled “The smallest module”import { agentStage, codeStage, defineModule, gateStage, v } from '@knetikdotdev/sdk';
export default defineModule({ id: 'hello', version: '0.1.0', title: 'Hello module', input: v.object({ name: v.string() }), stages: [ agentStage('draft', { agent: 'greeter', prompt: ({ input }) => `...`, parse: JSON.parse }), gateStage('choose', { type: 'pick', title: 'Pick one', options: ({ outputs }) => [/* ... */] }), codeStage('assemble', async (ctx) => { await ctx.artifacts.put('out.html', html, 'text/html'); }), ],});The repository’s own hello module, at hello-module, is the working reference. It has one agent, one pick gate, one code stage that writes HTML and Markdown, and an optional Slack notification.
Rules that bite
Section titled “Rules that bite”- An agent file starts with
'use agent', exports one capitalized function, and setsFn.agentName = '<module-id>-<name>'. Names use dashes only, because the agent framework forbids dots and requires unique identities across the whole host. - Agent turns are at-least-once. After a crash a stage may run again. Make external effects idempotent.
ctx.artifacts.putalready is: the same name replaces. - Gates are rows in the database, not waiting processes. A run waits for a human across restarts.
- Erasable TypeScript only. No enums or parameter properties, so the code also runs under plain Node type stripping.
- One copy of the framework. A module must not install its own copy of Flue. The CLI pins
@flue/runtime,@knetikdotdev/*,valibot,hono,pgand the model library to its own copy, so a bare checkout with nonode_modulesstill passescheckandtest.
The development loop
Section titled “The development loop”npm run check # is the module well formed?npm run test # headless tests with a scripted modelnpm run dev # the module in a running host with hot reloadSee The knetik CLI and Testing. When the module is ready, install it into a host with knetik add (also in the CLI page).
defineModule describes every field of the definition.