Agent / Expose, do not reimplement
Dynamic capabilities and audit logging
When available(model) changes with application state (for example, clear_completed appearing once a todo is marked done) and the host provides subscribe, adapters like WebMCP update registered tools automatically—and calling an unavailable tool directly still fails with AgentCapabilityUnavailableError.
Attach Agent.auditLog to record every invocation and refusal without storing your Model:
const audit = Agent.auditLog<Principal>({
capacity: 500,
principal: principal => principal.actorId,
})
const auditedRuntime = AgentBuilder.bind({
definition: AssistantAgent,
host,
audit,
})Audit logs store only projected principal IDs, opt-in/redacted inputs, and bounded entries, and failing sinks never interrupt dispatch.
Inspecting contracts without running an LLM
Extract schemas, manifests, and Markdown summaries statically for tests, PR diffs, and foldkit-surface Module validation:
Agent.messages(AssistantAgent)
Agent.schema(AssistantAgent)
Agent.contextSchema(AssistantAgent)
Agent.toManifest(AssistantAgent)
Agent.toManifest(AssistantAgent, AssistantParts)
Agent.toMarkdown(AssistantAgent)Works identically on local-first apps
Because Sync.mount provides model, dispatch, subscribe, and observe, both human UI controls and foldkit-agent feed Messages into the exact same update and Sync replica—no second server endpoint needed.
Similarly, Surface defines what a feature may observe and emit, while Agent wraps a Surface with protocol schemas, availability, authorization, completion, parts, and audit without taking state ownership away from update, Remote, or Sync.
When to use another tool
- DOM automation or scraping:
foldkit-agentdispatchesMessages rather than clicking raw selectors; addMessages for actions you want agents to perform. - Exposing an unprojected
Model: Define a dedicatedSurfaceorProjectioncarrying only what the task needs. - Exactly-once external effects: Completion tracks state transitions, not transaction recovery; see Durable effect recovery.
- Stateless function tools: Plain tool functions need less ceremony when there is no
ModelorMessageboundary to preserve.
Next
- Study a complete contract with Surface context, completion, authorization, and resources in
examples/todo-app/src/agent.ts. - See a standalone host setup in
examples/todoand a full replicated browser app inexamples/todo-app. - Read the
foldkit-agentREADME and adapter READMEs (WebMCP, MCP, A2A, Agent Native).