Domain Packs and Connectors
A domain pack gives the agent a world to work in: the terms of one domain, its rules and playbooks, the tools that reach its systems, and trial suites that check the work. This page shows how to write a…
A domain pack gives the agent a world to work in: the terms of one domain, its rules and playbooks, the tools that reach its systems, and trial suites that check the work. This page shows how to write a pack, connect tools (your own TypeScript connector or an MCP server) and lock the result. It starts where Build an Environment ends.
In a checkout of this repository,
neusymisnode apps/cli/dist/src/index.js(runnpm run buildfirst). In your own project it isnpx neusym, once@neusym/cliis installed; the packages are not on npm yet, andnpm run pack:osswrites installable tarballs.
#Why Packs Live Outside This Repository
The runtime and the kits name no domain; a CI check, scripts/ci/domain-free.mjs, fails the build when product or domain words appear in their source. So each domain lives in its own repository: a workspace.yaml, one or more packs, and the @neusym/* packages it uses. No change to Neusym itself is needed.
An environment is a world, the rules for working in it, and checks that say whether the work was done (What an Environment Is). workspace.yaml holds the rules. A pack holds the rest, and each part is read by one kit:
| What the pack adds | Pack key | Read by |
|---|---|---|
| Terms and their synonyms, added to the agent's context as a glossary | ontologyFiles | ontology |
| Business rules that deny an action or ask a person first | ruleFiles | rules |
| Playbooks, added to the context when a task mentions their trigger words (always, if they list none) | skillFiles | skills |
| Events that start tasks | triggerFiles | intake |
| Event routes | eventRouteFiles | event-router (Enterprise) |
| Tools that reach your systems | connectors | tool-gateway |
| Starting records: agent definitions, spending caps, grants, trial suites | seeds | the kit that owns each record |
A pack never names a kit. It lists the ports it needs (needsPorts); a port is a named interface such as tools@1, and any kit that provides it will do. When the workspace lacks the kit that reads a pack file, plan says so: Declarative domain.ontology is configured, but this workspace does not load kit "ontology".
#Write a Pack
A small bookkeeping pack lives in packs/ledger/ next to workspace.yaml. Its manifest:
# packs/ledger/pack.yaml
id: ledger
version: 0.1.0
minLevel: review # plan refuses a workspace below this level
needsPorts: [tools@1, executor@1] # ports, never kit names
connectors:
ledger: ./connectors/connector-ledger/dist/src/index.js
line: [read, report]
domain:
ontologyFiles: [./domain/ontology.yaml]
ruleFiles: [./domain/rules.yaml]
skillFiles: [./domain/skills/month-end.md]
seeds:
agentDefFiles: [./domain/agents/default.md]
budgetScopeFiles: [./domain/budgets.yaml]
trialSuiteFiles: [./domain/trials/basics.yaml]line is a label for people; the runtime does not read it. pack.json works the same way. Domain file paths are relative to the pack folder and must stay inside it. Domain files are YAML or JSON; playbooks and agent definitions can be Markdown with a YAML header. Each ...Files key has an inline twin (rules, agentDefs), and workspace.yaml may hold a domain section of its own. schemas/pack.schema.json lists every key.
ontology.yaml lists terms (canonical: Account, aliases: [GL account]). The rule and the playbook:
# domain/rules.yaml
id: ledger-controls
domain: bookkeeping
rules:
- id: no-payroll-reads
point: action.authorize # checked before every tool call
decision: deny # or require_approval
code: PAYROLL_OFF_LIMITS
reason: Payroll accounts are not part of this job.
when:
toolName: ledger.get_balance
argIn:
accountId: [payroll]---
id: month-end
workKind: bookkeeping
title: Month-end balance check
triggers: [month-end, balance]
---
1. Read each account with `ledger.get_balance`. Never guess a number.
2. Report balances in dollars, not cents.The workspace loads the pack and the kits that read it:
# workspace.yaml
level: review
profile: test
packs:
- ./packs/ledger/pack.yaml # or an npm package: "@acme/ledger-pack@0.1.0"
kits:
# ...the seven starter kits from Build an Environment, then:
- "@neusym/kit-ontology@0.1.0" # reads the pack's terms
- "@neusym/kit-rules@0.1.0" # reads the pack's rules
- "@neusym/kit-skills@0.1.0" # reads the pack's playbooks
- "@neusym/kit-evals@0.1.0" # keeps the pack's trial suites
grants:
systemStore: [tenancy]Plan it, then run a scripted turn that asks for the payroll balance:
echo '[{"toolCalls":[{"id":"c1","toolName":"ledger.get_balance","args":{"accountId":"payroll"}}]},
{"text":"I could not read the payroll account."}]' > turns.json
neusym plan ./my-env
neusym run ./my-env "What is the balance of the payroll account?" --model-turns turns.jsontask.run task_… completed 29ms
├─ context context.build 1→3 items 4ms
├─ step 0 tool_calls 13ms
│ ├─ guard harness.step allow 1ms
│ ├─ model.call scripted-v1 140 tok $0.0005 tool_calls 3ms
│ ├─ ✗ tool.call ledger.get_balance denied PAYROLL_OFF_LIMITS by rules:action-rules 4msThe context grew from one item to three: the glossary and the playbook (the prompt says "balance"). The rule stopped the call before the connector ran. Plan also checks the pack's needs: Pack "ledger" requires port "grants@1", which has no provider in this workspace. To share a pack, publish it as an npm package that exports ./pack.yaml (or .json, .yml) and list it in packs by name and version.
#Seeds: Records a Pack Starts With
Seeds are records the pack writes into the environment's store at boot, for each tenant (the CLI's --tenant; the server's seed tenants). A seed never overwrites what is there: an agent definition someone promoted stays active, a spending cap keeps what was spent, a revoked grant stays revoked. Four kinds cover most packs:
| Seed | File key | What it is | Needs the kit |
|---|---|---|---|
| Agent definition | agentDefFiles | In Markdown, a header with name and optionally model, maxSteps, temperature and toolAllowlist (the only tools it may call); the body is the instructions. The one named default runs every task that asks for no other. | harness |
| Budget scope | budgetScopeFiles | A spending cap: scopeId plus limits such as maxCostUsd: 5 or maxSteps: 200. Use a goal's id, and every task for that goal draws from it. | budget |
| Grant | grantFiles | An id, tools and effects (read, draft or execute), optionally maxUses. Never commit: that comes only from a person's approval. | action-gate (level execute) |
| Trial suite | trialSuiteFiles | Tasks with a check each (next section). | evals |
If the needed kit is missing, plan refuses: Declarative domain.seeds.trialSuites requires port "evals@1", which has no provider. Names and ids must be unique across all packs. The schema lists the other seed kinds, such as versioned skills, rule tables and model routes for the learning loop. What grants and approvals allow is in Authority and Safety.
#Trial Suites as Files
A trial suite is a list of tasks, each with a check. It is how a pack says what "done right" means:
# domain/trials/basics.yaml
suite: basics
description: Starting cases for the ledger pack
cases:
- name: cash-balance # the case's key in its suite
input:
prompt: What is the balance of the cash account?
check:
expect:
outputIncludes: ["$1,250.00"]input needs a prompt, and may add contextItems, procedureInput, outputSchema or a workerRole. check needs at least one of:
expect: tests the result:status(defaultcompleted),outputIncludes,outputExcludes,maxSteps, or an answer scorer.evidence:pathandequalspairs read from trusted JSON evidence the task saved. Needs theartifactskit (leveldraft).verify: a second task that checks the attempt on its own. The common case applies the attempt's changes to a fresh copy of the world and runs one allowlisted command there:
check:
verify:
procedureInput:
workspace: ledger-small # a named world on the runner driver
command: check-totals # listed in the sandbox kit's allowedVerifyCommands
expectBaseFail: true # the check must fail on the untouched world
archiveArtifactId: { $fromTrial: artifactId, contentType: application/vnd.neusym.tree-delta+json }
evidence:
- path: passed
equals: trueThe verify task runs under the evals kit's verifyRole (default verifier); map that role to sandbox.verify_archive in procedure-executor's tools, and turn on enableArchiveVerify in the sandbox kit.
Seeding keeps stored cases stable, so results stay comparable:
- A case is created once per
nameand never rewritten; to change one, give it a new name. A locked suite takes no new cases, andheldOut: truecounts only when the suite is first created. - One pack owns a suite. The same suite in two packs is refused, and so is a name already used by a replay suite (
EVAL_SUITE_NOT_TRIAL). - Cases hold prompts and expected text, so they are refused when
observe.captureis narrower thancontent(the default).
neusym eval list ./my-env shows the seeded suite; neusym eval trial-start ./my-env basics --max-cost 1 starts a run. Each attempt is a task with the worker role eval, so the tasks kit must allow that role (allowedCreateRoles) and a worker must serve it. Knowledge and Learning covers trial runs and scoring.
#Write a Connector
A connector turns your system's API into tools. It is not a kit: the loader imports it and hands its tools to tool-gateway, so every call passes the same checks as any other tool (the payroll denial above was one). It is a manifest.json and an ES module; all six manifest keys are required (schemas/connector.schema.json):
{
"id": "connector-ledger", "version": "0.1.0",
"requires": ["tools@1"], "optional": [], "network": false,
"configSchema": {
"type": "object", "additionalProperties": false,
"properties": { "maxAgeMs": { "type": "integer", "minimum": 1000, "default": 60000 } }
}
}network tells reviewers whether the connector calls out; nothing enforces it today. The module default-exports a ConnectorDefinition from @neusym/sdk, whose manifest must match the file:
// connectors/connector-ledger/src/index.ts
import type { ToolDefinition } from '@neusym/contract-tools';
import { validateConfig, type ConnectorDefinition, type ConnectorManifest } from '@neusym/sdk';
import manifestJson from '../manifest.json' with { type: 'json' };
const MANIFEST = manifestJson as ConnectorManifest;
const BALANCES: Record<string, number> = { cash: 125_000, payroll: 980_000 };
const ledgerConnector: ConnectorDefinition<ToolDefinition> = {
manifest: MANIFEST,
create(config) {
const checked = validateConfig(MANIFEST.configSchema, config, MANIFEST.id);
if (!checked.ok) throw new Error(`Invalid connector config: ${checked.errors.join('; ')}`);
const getBalance: ToolDefinition = {
name: 'ledger.get_balance',
description: 'Reads the balance of one ledger account, in cents.',
effect: 'read',
inputSchema: {
type: 'object', required: ['accountId'], properties: { accountId: { type: 'string', minLength: 1 } },
},
dataContract: { maxAgeMs: checked.value.maxAgeMs as number, requiredFields: ['accountId', 'balanceCents'] },
execute(args, { ctx }) {
const accountId = String(args.accountId);
const data = { accountId, balanceCents: BALANCES[accountId] ?? 0 };
return { data, fetchedAtMs: ctx.nowMs(), untrusted: false };
},
};
return [getBalance];
},
};
export default ledgerConnector;create gets the settings after the loader checked them against configSchema and filled in defaults, and returns the tools:
effect(read,draft,execute,commit) decides which levels may run the tool and which checks apply.- The gateway checks the agent's arguments against
inputSchemabeforeexecuteruns. dataContract: a result older thanmaxAgeMsis held back (STALE_CONNECTOR_PAYLOAD), and so is one missing arequiredFieldsentry.evidenceFieldsnames fields a later check may use as evidence.untrusted: falsesays the data comes from a system you trust. Leave it out and the result counts as untrusted text, whichinjection-guardkeeps away from writes.
In pack.yaml, point connectors at the built module, not the folder; the loader finds manifest.json in that file's folder or a parent inside the pack. A published connector is named by package name instead and exports . and ./manifest.json, like examples/demo-product/connectors/connector-demo. The key on the left (ledger) is only a label; the id comes from the manifest.
To change a connector's settings for one environment, use connectorConfigs in workspace.yaml, keyed by connector id. Plan checks the values: Invalid config for connector "connector-ledger": connectorConfigs.connector-ledger.maxAgeMs: value 500 is less than minimum 1000.
#Connect an MCP Server
The mcp-bridge kit turns tools of an MCP server into Neusym tools, one by one, each with a pinned schema. It needs the draft level or higher and an mcp-transport@1 driver: driver-mcp-transport-stdio starts the server as a local process, driver-mcp-transport-http talks Streamable HTTP. No profile binds a real transport, so you add the binding. This goes in workspace.yaml, not the pack, since it binds a driver and configures a kit. Add "@neusym/kit-mcp-bridge@0.1.0" to the kits of a draft environment, then:
bindingOverrides:
mcp-transport:
driver: "@neusym/driver-mcp-transport-stdio"
config:
servers:
rates:
command: node
args: [./mcp/rates-server.mjs]
kitConfigs:
mcp-bridge:
tools:
- server: rates # a key under servers
remoteName: get_rate # the tool's name on the MCP server
name: rates.get_rate # the name the agent sees
effect: read
inputSchema: # what the gateway checks the agent's arguments against
type: object
required: [from, to]
properties: { from: { type: string }, to: { type: string } }
schemaSha256: fa76ea16e7b446f5118d5c3fc61a39fb3cd365bab5da1b3407ccaafa88e5bef2The stdio driver starts the server in the folder you run Neusym from (or in cwd, read from that folder), not in the workspace folder, so relative paths in args resolve there; run from the workspace folder or use absolute paths. The server process gets only a few safe variables (PATH, HOME, LANG and the like), plus the names in envAllowlist, the values in staticEnv, and secrets through secretEnv.
For a remote server, use "@neusym/driver-mcp-transport-http" and give each server an https:// url (allowInsecureHttp: true is for local testing). For a bearer token, set authSecret: ratesToken on the server and secrets: { ratesToken: "env:RATES_MCP_TOKEN" } (or vault:KEY) on the binding. Each driver's driver.json under drivers/mcp-transport/ lists its options.
#Pin Each Tool's Schema
schemaSha256 is the SHA-256 of the input schema the server advertises for that tool, with keys sorted. Before every call, mcp-bridge lists the server's tools and hashes the schema again. If the tool is gone or its schema changed, the call is refused before it is sent (MCP_SCHEMA_DRIFT) and an mcp.schema_drift event is published, so a changed tool stops working until someone reviews it and updates the pin. schemaPinCacheMs reuses a check for a while; the default 0 checks every call. Review the server's schema, then hash it with the helper from @neusym/contract-mcp-transport:
node --input-type=module -e "import { computeMcpSchemaSha256 as hash } from '@neusym/contract-mcp-transport';
console.log(hash({ type: 'object', required: ['from', 'to'], properties: { from: { type: 'string' }, to: { type: 'string' } } }));"
# fa76ea16e7b446f5118d5c3fc61a39fb3cd365bab5da1b3407ccaafa88e5bef2When the test server added a date parameter, the next call stopped with ✗ tool.call rates.get_rate error MCP_SCHEMA_DRIFT. A result with isError: true never counts as success either (MCP_TOOL_ERROR), and MCP output is untrusted text by default. More per-tool keys, each allowed only with some effects (mcp-bridge README):
| Key | Effect | What it does |
|---|---|---|
parallelSafe | read | The tool may run at the same time as other parallel-safe reads. |
idempotentByOpKey + opKeyArgName | execute, commit | The server drops a repeated write; Neusym sends the operation key in the named argument. |
isErrorOutcome | any | How a remote error is recorded for a write: unknown (default, a person reconciles it) or rejected. |
targetStateReader | commit | A pinned read tool; a person's approval is tied to what it returned. |
declassifies | read | Lets a schema-checked structured result count as trusted, when tool-gateway's declassificationAllowlist names the tool (Authority and Safety). |
timeoutMs | any | Per-tool timeout; defaultTimeoutMs (30 seconds) otherwise. |
#Lock the Environment
When the environment does what you want, pin every package and pack file:
neusym lock ./my-env --write # without --write it only prints
export NEUSYM_PACKAGE_LOCK=./my-env/neusym.lock.jsonneusym.lock.json has two parts. packages holds every kit, driver, contract, connector and npm-installed pack by name@version, with a SHA-256 over every file in its folder (node_modules and .git skipped, symlinks refused). domainFiles holds each local pack manifest that has a domain section and every file it names.
With NEUSYM_PACKAGE_LOCK set, a package that changed (PACKAGE_DIGEST_MISMATCH) or is missing from the lock (PACKAGE_NOT_IN_LOCK) is refused before its code is imported. Packages are checked as they load at boot (run, work, the server); plan checks the pack files. After one word changed in rules.yaml:
Digest mismatch for domain asset "packs/ledger/domain/rules.yaml": expected "sha256:76167c2c…", got "sha256:85bae0e2…".workspace.yaml is in the lock only when it has its own domain section, so review changes to it as you review code. --sign-key adds an Ed25519 signature; with NEUSYM_TRUSTED_PUBKEYS set, boot refuses an unsigned lock or one signed by an unknown key.
#Next Steps
- See a complete example: examples/demo-product has a pack, a connector package and a workspace.
- Read about one kit: the Kit Catalog links every kit's README.
- Start tasks from events: triggers and intake are in Coordination and Events.