Functions

Functions

Everything else curb exports.

Define an agent

FunctionWhat it does
defineAgentDeclares the agent
createAgentStoreState that lasts the whole call
defineToolTypes the props of a Tool outside JSX
zZod, for validating input

defineAgent

import { defineAgent } from "curb";

export const agent = defineAgent({ app: App, timeZone: "Europe/Berlin", firstTurn: "agent" });
OptionTypeDefaultWhat it does
appcomponentThe agent’s React tree
maxLoadedSkillsnumber3Skills open at once. The least recently used leaves past this
maxStepsnumber8Model steps per turn
maxTranscriptMessagesnumber60Messages sent to the model per step. The full transcript is kept
timeZonestring"UTC"An IANA time zone. Every request carries today’s date and time in it
firstTurn"user", "agent", { say }"user"Who opens the call (Who speaks first)
mcpServersarrayRemote MCP servers (MCP servers)
goalsobjectWhat counts as a successful call (Goals and experiments)
experimentsobjectA/B experiments, by name
preview{ suggestedPrompts?, chatPlaceholder? }Hints for the preview. Never reach the model

It refuses a time zone that does not exist, a firstTurn no conversation can open with, and goals or experiments a host could not evaluate.

createAgentStore

import { createAgentStore } from "curb";

export const useClaim = createAgentStore("claim", (set) => ({
  verified: false,
  verify: () => set({ verified: true }),
}));

createAgentStore(key, initializer) returns a hook on state that lasts the whole call and survives a skill leaving the request. Call it once, at module level. A change re-renders the agent, so a tool gated on a store field appears and leaves on its own (State and conditional tools).

defineTool

const openClaim = defineTool({
  name: "open_claim",
  description: "Open a claim.",
  schema: z.object({ policy: z.string() }),
  onSubmit: async ({ policy }) => ({ ok: true, message: `Opened for ${policy}.` }),
});

<Tool {...openClaim} />

z

Zod, re-exported so a project needs no dependency of its own.

Errors

ErrorThrown when
ToolInputErrorA handler refuses its input, with a message for the model
isToolInputErrorTests for that error
AgentAuthoringErrorThe agent is authored wrongly, with a code and a fix
MessageRefusedErrorA message was refused by the app or the host
HostUnavailableErroraskHost found no host connected
HostTimeoutErroraskHost got no answer in time
SettingsRefusedErrorA settings update is not allowed or not valid

ToolInputError

import { ToolInputError } from "curb";

throw new ToolInputError("That policy number has eight digits.");

The model reads the message and can ask the caller again. data is optional: new ToolInputError(message, { data }).

Building on Curb

These are for programs built around Curb. An agent does not need them.

ExportWhat it does
AgentSessionThe conversation loop on a runtime
AgentSiteRuntimeThe headless React host of one conversation
AgentInfoStoreThe store behind useAgentInfo
RouteProviderProvides the current skill’s path to a tree
AgentRouterRemoved: renders nothing and warns with AGENT_ROUTER_REMOVED
compileSiteCompiles a semantic tree into context and tools
flattenContextCompiled context as text lines
createSemanticRootA React root that renders into a semantic tree
createSkillRoutesRoutes from a project’s skill modules
skillPathFromModuleIdA module’s skill path
titleFromSkillPathA readable title from a skill path
listPublicMarkdownLists context/ files
preloadPublicMarkdownLoads context/ files
resolvePublicMarkdownReads one context/ file
validateSchemaInputValidates input
zodSchemaToFieldsA Zod object as field descriptions
diagnoseAgentAuthoringRuns the authoring checks
formatAuthoringDiagnosticPrints a diagnostic
mergeAuthoringDiagnosticsMerges diagnostics without repeats
AUTHORING_DIAGNOSTIC_CODESEvery code (Diagnostics)
McpManagerConnects to and calls MCP servers
configureMcpSets up the MCP manager
getMcpManagerThe current MCP manager
preloadMcpToolsConnects the configured servers early
resolveMcpServerFinds a configured server
setMcpOAuthCallbackUrlSets where MCP sign-in returns to

Next steps

  • Components: what an agent renders.
  • Hooks: what a component can read and do.