Agent / Expose, do not reimplement

What an agent can read: context and resources

context defines the agent's primary read model using any foldkit-surface Surface or Projection, keeping internal UI fields private. Add named read-only resources alongside context for secondary summaries such as counts:

ts
const CountsAgent = AgentBuilder.make({
  name: 'counts-assistant',
  context: Overview,
  resources: [
    Agent.resource('counts', {
      description: 'How many todos are active and completed',
      schema: Schema.Struct({
        total: Schema.Number,
        active: Schema.Number,
        completed: Schema.Number,
      }),
      read: model => ({
        total: model.todos.length,
        active: model.todos.filter(todo => !todo.completed).length,
        completed: model.todos.filter(todo => todo.completed).length,
      }),
    }),
  ],
  messages: AgentBuilder.expose(Message, {
    ToggledTodo: { name: 'toggle_todo', description: 'Toggle a todo' },
  }),
})

In short: context is the default read model, resources are additional named reads, and messages are capabilities that trigger update.

Exposing intents rather than internal facts

Expose intent Messages (such as RequestedTodo) instead of result facts (SubmittedTodo). If creating a todo generates an ID and timestamp via a Command inside update, letting an agent construct SubmittedTodo directly would bypass that logic and push nondeterminism into the protocol layer. Use Agent.variant with input and toMessage so decoding happens cleanly before update runs.