TechFabricTechFabricHarness
Building Agents

Agent registry and governance

Register immutable agent versions, bound authority, budgets, and external identities.

@fabric-harness/agent-registry provides runtime-neutral governance contracts for agent catalogs. It doesn't execute agents or replace Platform actions. It validates definitions, immutable versions, tenant registrations, capability grants, autonomy ceilings, enrollment, external identities, and privacy-safe evidence while keeping vertical-specific scope in the owning application.

The registry and agent-boundary packages require Zod 4.6.6 or newer within 4.x. Refresh application lockfiles to pick up the constrained-collection validation security fix; do not replace a vendor's Zod 3 dependency with an untested major override.

pnpm add @fabric-harness/agent-registry zod
import {
  agentCapabilityGrantBaseSchema,
  agentDefinitionSchema,
  clampRoute,
  isActionAllowedByScopes,
} from '@fabric-harness/agent-registry';

const definition = agentDefinitionSchema.parse({
  agentDefinitionId: 'reviewer',
  name: 'reviewer',
  displayName: 'Governed reviewer',
  description: 'Reviews a bounded subject and proposes governed actions.',
  inputKinds: ['review.request'],
  outputKinds: ['review.result'],
  createdAt: new Date().toISOString(),
});

const grant = agentCapabilityGrantBaseSchema.parse({
  grantId: 'reviewer-grant',
  readTools: ['read-subject'],
  proposalActions: ['propose-review'],
  executionActions: [],
});

// Scope patterns: '*' matches every action, 'review.*' a whole namespace.
const mayPropose = isActionAllowedByScopes(['review.*'], 'review.propose'); // true

const route = clampRoute('approval-required', {
  status: 'auto-executed',
  actionInvocationId: 'candidate-invocation',
});

The registry deliberately separates read, propose, and execute authority. A registration's autonomy is a ceiling: policy may narrow it but cannot widen it. Persist only validated, hash-pinned versions; mint short-lived execution principals per run; and route mutations through governed TechFabric Platform actions. External channel identities remain untrusted candidates until an application resolves an active binding and validates the applicable grant.

Grants that carry scope patterns over action IDs can check them with scopeMatches(pattern, actionId) or isActionAllowedByScopes(patterns, actionId). The pattern * on its own admits every action. Elsewhere, * matches any run of characters other than a line terminator, dots included, so review.* admits review.propose and review.batch.propose but not review itself. Every other character is literal, and an empty pattern list admits nothing. Where the patterns are stored, and the credentials they belong to, stays with the application.

Use zod .extend() in an application package to attach tenant or subject scope. Do not add vertical domain fields to the shared registry. The runnable credential-free fixture is examples/agent-registry in the restricted source repository.

An awaiting-approval route has one of two owners. An app-owned route omits approvalOwner (or sets it to 'app') and carries the approvalRequestId of an approval request the application created; clampRoute returns this shape with an empty request ID, which the caller fills in before validating the route.

Platform Host approval works differently. There the proposal is the action invocation itself, so a Host-owned route carries the actionInvocationId of the invocation you created, and the agent waits on, polls and resumes that same invocation without a separate approval request.

import { actionRouteSchema, agentEventEnvelopeSchema } from '@fabric-harness/agent-registry';

const hostRoute = actionRouteSchema.parse({
  status: 'awaiting-approval',
  approvalOwner: 'host',
  actionInvocationId: 'invocation-1',
  reason: 'Human review required',
});

const envelope = agentEventEnvelopeSchema.parse({
  eventId: 'event-1',
  type: 'approval.requested',
  tenantId: 'tenant-1',
  occurredAt: new Date().toISOString(),
  correlationId: 'correlation-1',
  actionInvocationId: 'invocation-1',
  event: { type: 'approval.requested' },
});

Host approval lifecycle events name the invocation only in their envelope. The optional envelope actionInvocationId keeps that identity through normalization, so a consumer can match each event to the invocation it is waiting on; other events omit it, an invalid ID fails schema validation, and the signature still covers the raw body. None of these contracts needs credentials, although creating or resuming an invocation requires the owning application's Platform authentication and authorization.

To migrate TypeScript code, narrow with route.approvalOwner !== 'host' or 'approvalRequestId' in route before reading approvalRequestId, since narrowing on status alone now also admits Host-owned routes.