createRuntime
Every option createRuntime takes, with what it does and what happens without it.
createRuntime(config) builds the runtime: the object your server calls to run chat turns, apply approvals, resume crashed runs and fire schedules. Create it once per process and reuse it.
ts
import { createRuntime, defineAgent } from "@intentface/latch-core";
import { createPostgresAdapter } from "@intentface/latch-drizzle";
export const runtime = createRuntime<Principal>({
storage: createPostgresAdapter(db, { owner: (p) => [p.orgId, p.userId] }),
context: ({ principal }) => ({ orgId: principal.orgId }),
agents: {
support: defineAgent({ model: anthropic("claude-sonnet-4-6"), instructions: "…" }),
},
});Only storage and agents are required. Every other option switches a capability on; leave it out and that capability doesn't exist. Click a row to see its full type and description.
Options
| Option | Type | Default | Details |
|---|---|---|---|
storage | StorageAdapter<P> | — | |
context? | ContextInput<P, RuntimeContext> | — | |
messageContext? | object | — | |
agents | Record<string, AgentFactory<P, any, any>> | — | |
durability? | DurabilityConfig | — | |
pricing? | Pricing | — | |
connections? | ConnectionRegistry<P> | — | |
dynamicAgents? | DynamicAgentStore<P> | — | |
memory? | MemoryProvider<P> | — | |
reconstructPrincipal? | ReconstructPrincipal<P> | (identity) => identity | |
cron? | function | — | |
runSchedule? | function | — | |
sandbox? | function | — | |
harnessTools? | object | — | |
resolveProviderTools? | ((modelId: string) => Record<string, unknown>) | — | |
resolveReasoningOptions? | function | — | |
resolvePromptCaching? | function | — | |
telemetry? | LatchTelemetry<P> | — | |
onOwnerKeyMismatch? | function | — | |
limits? | LatchLimits<P> | — | |
extensions? | Extension[] | — | |
maxInlineFileBytes? | number | 20 MB |
durability
Crash recovery. Turn it on, then call runtime.cron() on a timer: that is what finds and resumes interrupted runs.
ts
createRuntime({ …, durability: { enabled: true } });| Option | Type | Default | Details |
|---|---|---|---|
enabled? | boolean | false | |
leaseTtlMs? | number | 30_000 | |
heartbeatMs? | number | 10_000 | |
instanceId? | string | a random id per process |
limits
Usage limits. limitsFor returns the limits a run counts against; each limit is a counter, a window and caps.
ts
import { DAY_MS } from "@intentface/latch-core";
import { createPostgresLimitStore } from "@intentface/latch-drizzle";
createRuntime({
…,
limits: {
store: createPostgresLimitStore(db),
limitsFor: ({ principal }) => [
{ key: `org:${principal.orgId}`, windowMs: 30 * DAY_MS, max: { tokens: 5_000_000 }, label: "your organization's monthly budget" },
{ key: `user:${principal.orgId}:${principal.userId}`, windowMs: DAY_MS, max: { turns: 200 }, label: "your daily requests" },
],
},
});| Option | Type | Default | Details |
|---|---|---|---|
store | LimitStore | — | |
limitsFor | function | — | |
onRefused? | function | — |
Each limit:
| Option | Type | Default | Details |
|---|---|---|---|
key | string | — | |
windowMs | number | — | |
max | object | — | |
label? | string | — |