PAIPAI

createAgentRuntime()

One in-process agent runtime without HTTP. Prefer createPai.

createAgentRuntime runs a single agent in-process. New apps should use createPai(), which shares storage and files across agents. Use this only for tests or a one-agent process with no registry.

import { createAgentRuntime } from "@pai/core";

const runtime = createAgentRuntime({
  agent: assistantAgent,
  scopeKey: (identity) => identity.workspaceId,
});

createTestRuntime() wraps this with in-memory storage and a scripted model.

Import

import { createAgentRuntime } from "@pai/core";

Signature

function createAgentRuntime(options: CreateAgentRuntimeOptions): AgentRuntime;

Parameters

options: CreateAgentRuntimeOptions

agent: AgentDefinition

scopeKey: (identity) => ScopeKey

Same meaning as on createPai.

storage?: ThreadStore

Defaults to in-memory.

files?: FileProvider

realtime?: ThreadLiveProvider

live?: { mode?: RuntimeLiveMode }

"distributed" requires realtime.

mode?: "auto" | "singleRuntime" | "distributed"

"auto" is distributed when realtime is set and single-runtime otherwise.

Defaults to auto.

capabilities?: Record<id, CapabilityBinding>

Required when the agent declares capabilities (sandbox).

userKey?: (identity) => UserKey

mapError?: RuntimeErrorMapper

onRuntimeError?: false | RuntimeErrorHandler

telemetry?: PaiTelemetryProvider | false

Returns

A AgentRuntime.

client: (input) => AgentClient

In-process thread client.

admin: (input) => TrustedAgentClient

Trusted operations (hidden threads, compaction).

access: (input) => RuntimeAccess

tools: (input) => RuntimeToolClient

Invoke backend tools with no thread.

close: () => Promise<void>

agent: AgentDefinition

manifest: AgentManifest

resolveIdentity: ResolveIdentity

telemetry: PaiTelemetryProvider | false | undefined

Learn more

On this page