Agent / Expose, do not reimplement

Linking capabilities to UI controls with parts

Capabilities name what an agent can do; parts map them to specific headings, buttons, or repeated rows from the contract alone:

ts
const AssistantParts = AgentBuilder.parts(AssistantAgent, {
  title: Agent.part({ label: 'List title', role: 'heading', field: 'listTitle' }),
  clear: Agent.part({ label: 'Clear completed', role: 'button', invokes: Message.ClearedCompleted }),
  toggle: Agent.part({
    role: 'checkbox',
    invokes: Message.ToggledTodo,
    each: context => context.todos,
    key: todo => todo.id,
    label: todo => todo.title,
    input: todo => ({ id: todo.id }),
  }),
})

const partsRuntime = AgentBuilder.bind({ definition: AssistantAgent, host, parts: AssistantParts })

Parts reference context keys (field), exposed capability constructors (invokes/sets), and repeated context items (each, key, label, input):

  • Zero extra authority: Invoking a part dispatches through messages.dispatch with full availability, schema decoding, authorize, and completion checks.
  • Follows availability and context schemas: Unavailable capabilities drop from parts.list, and callbacks receive schema-filtered context data.
  • Ambiguity checks: parts.find({ label }) returns Ambiguous with all matches instead of picking arbitrarily when labels collide.
  • DOM test hooks: AssistantParts.attributes(h, 'clear') and attributes(h, 'toggle', todo.id) emit data-fk-part and data-fk-part-key attributes for browser adapters and tests.

How every call flows through the pipeline

Every adapter translates incoming protocol requests into one shared eight-step contract pipeline:

  1. Resolve the capability by name.
  2. Check available(model).
  3. Decode protocol input against its Schema.
  4. Check authorize for the current principal.
  5. Check applies(model, input, principal).
  6. Construct the application Message via toMessage.
  7. Dispatch the Message to the host.
  8. Wait for correlated completion if configured.

Any refusal prior to dispatch stops before reaching update, keeping validation and policy uniform across every transport.

Complementary client and server policy

Client authorize checks refuse unauthorized tool calls early with typed errors. For server-backed or synchronized state, enforce the same predicate inside your server APIs or Sync journal (authorize) as well—the contract improves UX while the server remains the trusted boundary.