Skip to content

feat(agents): formal declarative agent-definition schema (#51) - #62

Merged
serge-ivo merged 1 commit into
mainfrom
feat/agent-definition-schema
Aug 1, 2026
Merged

feat(agents): formal declarative agent-definition schema (#51)#62
serge-ivo merged 1 commit into
mainfrom
feat/agent-definition-schema

Conversation

@serge-ivo

Copy link
Copy Markdown
Contributor

Second slice of the creator way (epic #58, workstream #51), building on the tool catalog (#59) and the repo-chat dogfood (#61).

Why

An agent's config is currently assembled and validated piecemeal — create sets a few columns + inits the DO, while capabilities and settingsSchema have their own separate PUT routes and guardrails live only in DO state. There's no single "here is a complete agent, as data" shape. A third-party creator (or the authoring UI / AI builder) needs exactly that.

What

  • lib/agent-definition.tsAgentDefinition + sanitizeAgentDefinition(input): one validator that composes the existing sanitizers (sanitizeDeclaredCapabilities, sanitizeToolList, sanitizeSettingsSchema) + the canonical defaultGuardrails normalizer, and emits exactly the agents.config shape the platform already reads (per the repo-chat seed): { identity: { personality, goal, guardrails, welcomeMessage }, capabilities: { surfaces, runtime, workflow, tools }, settingsSchema? }. Never throws — coerces/drops to safe defaults, so it's safe directly on an untrusted body.
  • sanitizeDeclaredCapabilities(raw) in agent-capabilities.ts — validates a raw capabilities object (drops unknown surfaces/runtime/workflow; tools via sanitizeToolList). Reused by the definition and available to PUT /:id/capabilities.

Safety / scope

  • Pure library — no route or DO changes, so nothing behaves differently yet. Fully additive.
  • DRY: reuses the canonical Guardrails type + defaultGuardrails; no shape is redefined.

Tests

  • New agent-definition.test.ts (6): normalize/trim, guardrail defaulting, drop-unknown capabilities, settingsSchema omission, never-throws-on-garbage, and a round-trip proving the emitted config resolves through the same agentCapabilities registry the runtime uses.
  • 692 workers/api tests pass, typecheck clean.

Next in #51

Wire POST / (and PUT /:id) to accept a full definition — validate with sanitizeAgentDefinition, persist as config, and init the DO with the identity/guardrails — so an agent can be created from one declarative payload (the end-to-end creator way). Then the "view/fork source" example gallery.

Part of #58.

Second slice of the "creator way" (#58): one validated shape describing everything
an agent IS as data, so an agent can be defined without a platform code change.

- lib/agent-definition.ts: AgentDefinition + sanitizeAgentDefinition(input) — composes
  the existing per-field sanitizers (capabilities, tools, settings schema) + the
  canonical defaultGuardrails normalizer, and emits exactly the agents.config shape the
  platform already reads (identity{personality,goal,guardrails,welcomeMessage} +
  capabilities{surfaces,runtime,workflow,tools} + settingsSchema). Never throws —
  coerces/drops to safe defaults, so it's safe on an untrusted request body.
- agent-capabilities.ts: sanitizeDeclaredCapabilities(raw) — validates a raw
  capabilities object (drop unknown surfaces/runtime/workflow, tools via
  sanitizeToolList). Reused by the definition + usable by PUT /:id/capabilities.

Round-trip test proves the emitted config resolves through the same agentCapabilities
registry the runtime uses. 692 workers/api tests pass; typecheck clean. Pure library —
no route/DO changes; wiring create/update to accept a full definition is the next PR.

Part of #58.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
serge-ivo pushed a commit that referenced this pull request Aug 1, 2026
Mark the tool catalog (#59) + repo-chat dogfood (#61) + agent-definition schema
(#62) as landed/in-progress across the strategy doc, the third-party plan, and the
README's repo-chat row (now the first "creator way" exemplar).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@serge-ivo
serge-ivo merged commit 97706f1 into main Aug 1, 2026
1 check passed
@serge-ivo
serge-ivo deleted the feat/agent-definition-schema branch August 1, 2026 03:13
serge-ivo pushed a commit that referenced this pull request Aug 1, 2026
)

sanitizeAgentDefinition / AgentDefinition had zero non-test consumers — built as a
"pure library, wiring deferred to the next PR" that never came. The lead-finder (and
every agent so far) is a standalone worker or a config chat agent; nothing consumes the
declarative definition. Removed agent-definition.{ts,test.ts} plus the helpers added
solely for it (sanitizeDeclaredCapabilities, DeclaredCapabilities, KNOWN_RUNTIMES,
KNOWN_WORKFLOWS).

KEPT (live): the tool catalog + capabilities.tools allowlist (PR #59) — repo-chat uses
it via migration 0050 through toolNamesFor. Recoverable from PR #62 history if/when the
create/update wiring is actually built.

715 workers/api tests pass; typecheck clean.
serge-ivo pushed a commit that referenced this pull request Aug 1, 2026
…ead code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
serge-ivo pushed a commit that referenced this pull request Aug 2, 2026
…141)

The Coder agent's runtime is already fully capability-driven (surfaces/
runtime/workflow/tools), not slug-hardcoded — but capabilities could only
be set via SQL migrations. This adds the missing authoring path so a
Coder-equivalent (or any agent built from existing primitives) is
stampable as pure data with no platform code change.

- sanitizeDeclaredCapabilities(input): validates the closed-enum power
  fields (surfaces ∈ KNOWN_SURFACES, runtime ∈ {browser,coding,null},
  workflow ∈ {JOB_APPLY,CODING_SESSION,INSURANCE_QUOTES,null}) + tools
  via sanitizeToolList. Only present keys returned → clean partial PATCH.
- POST /agents accepts an optional `capabilities` object at creation.
- GET/PUT /agents/:id/capabilities now round-trip surfaces/runtime/
  workflow/tools alongside customSurfaces; PUT merges per-key and no
  longer wipes customSurfaces on a capabilities-only PATCH.
- Console AgentDetail: a Capabilities editor (surfaces/runtime/workflow/
  tools) beside the existing custom-surfaces + settings-schema editors.

Closed-enum validation is the safety boundary — no arbitrary code, so
this is safe operator-side now; opening it to third-party creators is
gated on the trust model (#142). Refs #51, #58, #62 (removed dead code).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants