Caricamento in corso...
Caricamento in corso...
Last synced: Today, 22:00
Technical reference for the OpenClaw framework. Real-time synchronization with the official documentation engine.
Use this file to discover all available pages before exploring further.
The OpenClaw App SDK is the public client API for apps outside the OpenClaw process. Use
@openclaw/sdk@openclaw/sdk| Surface | Status | What it does |
|---|---|---|
text OpenClaw | Ready | Main client entry point. Owns transport, connection, requests, and events. |
text GatewayClientTransport | Ready | WebSocket transport backed by the Gateway client. |
text oc.agents | Ready | Lists, creates, updates, deletes, and gets agent handles. |
text Agent.run() | Ready | Starts a Gateway text agenttext Run |
text oc.runs | Ready | Creates, gets, waits for, cancels, and streams runs. |
text Run.events() | Ready | Streams normalized per-run events with replay for fast runs. |
text Run.wait() | Ready | Calls text agent.waittext RunResult |
text Run.cancel() | Ready | Calls text sessions.abort |
text oc.sessions | Ready | Creates, resolves, sends to, patches, compacts, and gets session handles. |
text Session.send() | Ready | Calls text sessions.sendtext Run |
text oc.models | Ready | Calls text models.listtext models.authStatus |
text oc.tools | Partial | Lists tool catalog and effective tools; direct tool invocation is not wired. |
text oc.artifacts | Ready | Lists, gets, and downloads Gateway transcript artifacts. |
text oc.approvals | Ready | Lists and resolves exec approvals through Gateway approval RPCs. |
text oc.rawEvents() | Ready | Exposes raw Gateway events for advanced consumers. |
text normalizeGatewayEvent() | Ready | Converts raw Gateway events into the stable SDK event shape. |
The SDK also exports the core types used by those surfaces:
AgentRunParamsRunResultRunStatusOpenClawEventOpenClawEventTypeGatewayEventOpenClawTransportGatewayRequestOptionsSessionCreateParamsSessionSendParamsArtifactSummaryArtifactQueryArtifactsListResultArtifactsGetResultArtifactsDownloadResultRuntimeSelectionEnvironmentSelectionWorkspaceSelectionApprovalModeCreate a client with an explicit Gateway URL, or inject a custom transport for tests and embedded app runtimes.
typescriptimport { OpenClaw } from "@openclaw/sdk"; const oc = new OpenClaw({ url: "ws://127.0.0.1:14565", token: process.env.OPENCLAW_GATEWAY_TOKEN, requestTimeoutMs: 30_000, }); await oc.connect();
new OpenClaw({ gateway: "ws://..." })urlgateway: "auto"urlFor tests, pass an object that implements
OpenClawTransporttypescriptconst oc = new OpenClaw({ transport: { async request(method, params) { return { method, params }; }, async *events() {}, }, });
Use
oc.agents.get(id)agent.run()typescriptconst agent = await oc.agents.get("main"); const run = await agent.run({ input: "Review this pull request and suggest the smallest safe fix.", model: "openai/gpt-5.5", sessionKey: "main", timeoutMs: 30_000, }); for await (const event of run.events()) { const data = event.data as { delta?: unknown }; if (event.type === "assistant.delta" && typeof data.delta === "string") { process.stdout.write(data.delta); } } const result = await run.wait({ timeoutMs: 120_000 }); console.log(result.status);
Provider-qualified model refs such as
openai/gpt-5.5providermodeltimeoutMsagentrun.wait()agent.waitstatus: "accepted"timed_outcancelledUse sessions when the app wants durable transcript state.
typescriptconst session = await oc.sessions.create({ agentId: "main", label: "release-review", }); const run = await session.send("Prepare release notes from the current diff."); await run.wait();
Session.send()sessions.sendRuntypescriptawait session.abort(run.id); await session.patch({ label: "renamed-session" }); await session.compact({ maxLines: 200 });
The SDK normalizes raw Gateway events into a stable
OpenClawEventtypescripttype OpenClawEvent = { version: 1; id: string; ts: number; type: OpenClawEventType; runId?: string; sessionId?: string; sessionKey?: string; taskId?: string; agentId?: string; data: unknown; raw?: GatewayEvent; };
Common event types include:
| Event type | Source Gateway event |
|---|---|
text run.started | text agent |
text run.completed | text agent |
text run.failed | text agent |
text run.cancelled | Aborted/cancelled lifecycle end |
text run.timed_out | Timeout lifecycle end |
text assistant.delta | Assistant streaming delta |
text assistant.message | Assistant message |
text thinking.delta | Thinking or plan stream |
text tool.call.started | Tool/item/command start |
text tool.call.delta | Tool/item/command update |
text tool.call.completed | Tool/item/command completion |
text tool.call.failed | Tool/item/command failure or blocked status |
text approval.requested | Exec or plugin approval request |
text approval.resolved | Exec or plugin approval resolution |
text session.created | text sessions.changed |
text session.updated | text sessions.changed |
text session.compacted | text sessions.changed |
text task.updated | Task update events |
text artifact.updated | Patch stream events |
text raw | Any event without a stable SDK mapping yet |
Run.events()typescriptconst run = await agent.run("Summarize the latest session."); for await (const event of run.events()) { if (event.type === "run.completed") { break; } }
For app-wide streams, use
oc.events()oc.rawEvents()Model helpers map to current Gateway methods:
typescriptawait oc.models.list(); await oc.models.status({ probe: false }); // calls models.authStatus
Tool helpers expose the Gateway catalog and effective tool view:
typescriptawait oc.tools.list(); await oc.tools.effective({ sessionKey: "main" });
Artifact helpers expose the Gateway artifact projection for session, run, or task context. Each call requires one explicit
sessionKeyrunIdtaskIdtypescriptconst { artifacts } = await oc.artifacts.list({ sessionKey: "main" }); const first = artifacts[0]; if (first) { const { artifact } = await oc.artifacts.get(first.id, { sessionKey: "main" }); const download = await oc.artifacts.download(artifact.id, { sessionKey: "main" }); console.log(download.encoding, download.url); }
Approval helpers use the exec approval RPCs:
typescriptconst approvals = await oc.approvals.list(); await oc.approvals.respond("approval-id", { decision: "approve" });
The SDK includes names for the product model we want, but it does not silently pretend Gateway RPCs exist. These calls currently throw explicit unsupported errors:
typescriptawait oc.tasks.list(); await oc.tasks.get("task-id"); await oc.tasks.cancel("task-id"); await oc.tools.invoke("tool-name", {}); await oc.environments.list(); await oc.environments.create({}); await oc.environments.status("environment-id"); await oc.environments.delete("environment-id");
Per-run
workspaceruntimeenvironmentapprovalsagentUse the App SDK when code lives outside OpenClaw:
Use the Plugin SDK when code runs inside OpenClaw:
App SDK code should import from
@openclaw/sdkopenclaw/plugin-sdk/*© 2024 TaskFlow Mirror
Powered by TaskFlow Sync Engine