openclaw

GitHub

OpenClaw内部参考文档,涵盖Gateway协议、Agent运行时、会话管理及Serverless集成。用于处理OpenClaw API调用及调试Agent行为,提供关键配置、入口点和通信协议细节。

.codex/skills/openclaw/SKILL.md serithemage/serverless-openclaw

Trigger Scenarios

调试Agent行为异常 集成OpenClaw API 开发Serverless插件

Install

npx skills add serithemage/serverless-openclaw --skill openclaw -g -y
More Options

Non-standard path

npx skills add https://github.com/serithemage/serverless-openclaw/tree/main/.codex/skills/openclaw -g -y

Use without installing

npx skills use serithemage/serverless-openclaw@openclaw

指定 Agent (Claude Code)

npx skills add serithemage/serverless-openclaw --skill openclaw -a claude-code -g -y

安装 repo 全部 skill

npx skills add serithemage/serverless-openclaw --all -g -y

预览 repo 内 skill

npx skills add serithemage/serverless-openclaw --list

SKILL.md

Frontmatter
{
    "name": "openclaw",
    "description": "References OpenClaw internals and integration points. Covers Gateway protocol, agent runtime, session management, tool system, and serverless integration. Use when working with OpenClaw APIs or debugging agent behavior.",
    "allowed-tools": "Read, Glob, Grep"
}

OpenClaw Internals Reference

Full analysis: docs/openclaw-analysis.md

Key Facts

Property Value
Version pinned v2026.2.13 (v2026.2.14 breaks — default-deny scope)
Codebase size ~675K lines TypeScript
Runtime Node.js >=22.12.0, pnpm monorepo, tsdown bundler
Gateway WS port :18789
HTTP port :18790
Config path ~/.openclaw/openclaw.json (NOT ~/.config/openclaw/)
Session files ~/.openclaw/agents/{id}/sessions/{sid}.jsonl

Entry Points

Entry Purpose
runEmbeddedPiAgent() Run agent in-process, independent of Gateway WS server — the key Lambda integration point
extensionAPI.js Library entry point (NOT in package.json exports map — must use file:// URL import)
openclaw gateway run Start full Gateway WS server (subcommand required, plain openclaw gateway just waits)
// Correct import pattern for Lambda
const ocRoot = process.env.OPENCLAW_ROOT!;
const { extensionAPI } = await import(`file://${ocRoot}/dist/extensionAPI.js`);

SessionManager

  • SessionManager.open(id) — synchronous fs read, JSONL format
  • Returns [] if session file is missing (safe to call on first run)
  • Sessions are append-only JSONL transcripts, compacted periodically
  • SessionLock prevents concurrent access to same session (critical for Lambda concurrency)

Gateway Protocol (JSON-RPC 2.0 over WebSocket)

Handshake Sequence

1. GW → client:  { type: "event", event: "connect.challenge", data: { challenge } }
2. client → GW:  { type: "req", id: 1, method: "connect", params: { client: { id: "gateway-client", mode: "backend" }, response: <challenge-response> } }
3. GW → client:  { type: "res", id: 1, result: { status: "hello-ok", snapshot: { sessionDefaults: { mainSessionKey } } } }

Sending a Message

// sessionKey obtained from hello-ok snapshot
{ type: "req", id: 2, method: "chat.send", params: { sessionKey, message: "..." } }

Streaming Response

// Stream chunks
{ type: "event", event: "chat", data: { state: "delta", content: "..." } }
// Final
{ type: "event", event: "chat", data: { state: "final", content: "..." } }
// Error
{ type: "event", event: "chat", data: { state: "error", error: "..." } }

Valid client Field Values

  • client.id: "cli", "gateway-client", "webchat-ui", etc. (TypeBox Literal)
  • client.mode: "cli", "backend", "ui", "node"NOT "operator" (invalid)
  • device field: Optional — omit entirely (empty publicKey/signature strings fail validation)

Config Requirements

{
  "gateway": { "mode": "local" },
  "auth": { "method": "env" }
}
  • auth.method key: removed in recent versions (invalid if present)
  • gateway.mode: "local" required for embedded operation
  • API keys via env vars only — never write to openclaw.json

Serverless Blockers (and How We Solved Them)

Blocker Problem Solution
Persistent WS server Always-running :18789 Use runEmbeddedPiAgent() instead
Long-lived runs (10 min) Lambda timeout Lambda 15-min timeout + structured streaming
In-process tools (filesystem) /tmp only in Lambda HOME=/tmp, sessions in /tmp
SQLite vector store Write access needed /tmp mount
Plugin loading (~30-35s) Cold start overhead Bedrock discovery disabled, pre-loaded
Bedrock auto-discovery 56s scan on startup bedrockDiscovery.enabled: false

Fargate vs Lambda Runtime

Aspect Fargate (Phase 1) Lambda (Phase 2)
Entry openclaw gateway run runEmbeddedPiAgent()
Session state Persistent (~/.openclaw) /tmp (ephemeral)
Cold start 40-57s 1.35s
Concurrent users 1 per task Many (separate invocations)
Cost ~$0/month idle Per-invocation

Version History

  • 504300d Current 2026-07-25 09:02

Same Skill Collection

.agents/skills/architecture/SKILL.md
.agents/skills/cold-start/SKILL.md
.agents/skills/context/SKILL.md
.agents/skills/cost/SKILL.md
.agents/skills/deploy/SKILL.md
.agents/skills/dev/SKILL.md
.agents/skills/implement/SKILL.md
.agents/skills/lambda-migration/SKILL.md
.agents/skills/openclaw/SKILL.md
.agents/skills/release/SKILL.md
.agents/skills/security/SKILL.md
.agents/skills/solo-maintainer-guard/SKILL.md
.agents/skills/solo-maintainer-inbox/SKILL.md
.agents/skills/solo-maintainer/SKILL.md
.agents/skills/status/SKILL.md
.agents/skills/troubleshoot/SKILL.md
.claude/skills/architecture/SKILL.md
.claude/skills/cold-start/SKILL.md
.claude/skills/context/SKILL.md
.claude/skills/cost/SKILL.md
.claude/skills/deploy/SKILL.md
.claude/skills/dev/SKILL.md
.claude/skills/implement/SKILL.md
.claude/skills/lambda-migration/SKILL.md
.claude/skills/openclaw/SKILL.md
.claude/skills/release/SKILL.md
.claude/skills/security/SKILL.md
.claude/skills/solo-maintainer-guard/SKILL.md
.claude/skills/solo-maintainer-inbox/SKILL.md
.claude/skills/solo-maintainer/SKILL.md
.claude/skills/status/SKILL.md
.claude/skills/troubleshoot/SKILL.md
.codex/skills/architecture/SKILL.md
.codex/skills/cold-start/SKILL.md
.codex/skills/context/SKILL.md
.codex/skills/cost/SKILL.md
.codex/skills/deploy/SKILL.md
.codex/skills/dev/SKILL.md
.codex/skills/implement/SKILL.md
.codex/skills/lambda-migration/SKILL.md
.codex/skills/release/SKILL.md
.codex/skills/security/SKILL.md
.codex/skills/solo-maintainer-guard/SKILL.md
.codex/skills/solo-maintainer-inbox/SKILL.md
.codex/skills/solo-maintainer/SKILL.md
.codex/skills/status/SKILL.md
.codex/skills/troubleshoot/SKILL.md

Metadata

Files
0
Version
504300d
Hash
f4d25bd8
Indexed
2026-07-25 09:02

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-20 08:36
浙ICP备14020137号-1 $방문자$