Skip to main content

パターン 3: OpenClaw

OpenClaw プロジェクトに @sonzai-labs/openclaw-context プラグインを差し込むだけで、Sonzai がエージェントの contextEngine になります — 持続的記憶・ムード・パーソナリティ・関係性、すべて OpenClaw の既存チャットループの下で。

OpenClaw は会話型 AI エージェント 構築のためのオープンソースフレームワークで、スロットベースのプラグイン システムを採用しています。各ターンのシステムプロンプトに何の文脈を入れるかを 決めるスロットが contextEngine です。@sonzai-labs/openclaw-context を インストールすると Sonzai コンテキストエンジン"sonzai" という名前で 登録されるので、openclaw.json でそのスロットに割り当てれば、すべての会話が 追加コードゼロでマインドレイヤーを通るようになります。

使うべき時

  • すでに OpenClaw 上で開発している、もしくはチームで OpenClaw に標準化済み。
  • OpenClaw の既存チャットループ・テレメトリ・ツールプラグインはそのまま残し、 メモリ/パーソナリティ層だけ差し替えたい。
  • 各ターンのシステムプロンプトに <sonzai-context> ブロックを自動注入し、 優先度順に並べトークン予算でトリミングしたい。

切り替えるべき時

アーキテクチャ

OpenClaw Runtime              SonzaiContextEngine            Sonzai Mind Layer
    |                                |                            |
    |-- bootstrap(sessionId) ------->|                            |
    |                                |-- resolve agent + session->|
    |                                |<-- session state ----------|
    |                                |                            |
    |-- assemble(messages, budget) ->|                            |
    |                                |-- fetch memory, mood,      |
    |                                |   personality, goals ----->|
    |                                |<-- ranked context blocks --|
    |<-- systemPromptAddition -------|   priority-ordered,        |
    |                                |   token-budget-trimmed     |
    |                                |                            |
    |  [LLM call w/ enriched prompt] |                            |
    |                                |                            |
    |-- afterTurn(sessionId) ------->|                            |
    |                                |-- send transcript -------->|
    |                                |   Mind Layer extracts      |
    |                                |   facts, updates mood,     |
    |                                |   evolves personality      |
    |                                |                            |
    |-- compact(sessionId) --------->|                            |
    |                                |-- merge short → long term->|

エンドツーエンドの例

OpenClaw プラグインそのものは JavaScript 専用(OpenClaw 自体が JS)です。 Python と Go のブランチでは等価な B2B プロビジョニング を示します: SHA1 で確定的に agent UUID を導出し、OpenClaw の設定ファイルを書き出す だけで、それを消費するランタイムは引き続き JS のままです。

// 1. Install:
//    openclaw plugins install @sonzai-labs/openclaw-context
//    # or: npm install @sonzai-labs/openclaw-context
//
// 2. Run the setup wizard (interactive — asks for API key, agent name):
//    npx @sonzai-labs/openclaw-context setup
//
// 3. The wizard writes openclaw.json:
//    {
//      "plugins": {
//        "slots": { "contextEngine": "sonzai" },
//        "entries": {
//          "sonzai": {
//            "enabled": true,
//            "apiKey": "sk_your_api_key",
//            "agentId": "a1b2c3d4-..."
//          }
//        }
//      }
//    }
//
// 4. Start chatting — Sonzai is now the contextEngine:
//    openclaw chat
//
// For programmatic / B2B provisioning use the exported setup() helper:
import { setup } from "@sonzai-labs/openclaw-context";

const result = await setup({
apiKey:     "sk_your_api_key",
agentName:  "customer-support-bot",
configPath: "/path/to/openclaw.json",
});

console.log(result.agentId);  // deterministic UUID — safe to re-run
console.log(result.written);  // true — config file updated

冪等なプロビジョニング

Agent ID は SHA1(tenantID + agentName) から導出されます。同じ tenant + name で setup()(または Python/Go の等価実装)を何度 呼んでも同じエージェントが返るので、デプロイのたびに再実行しても安全です。

次に読む

On this page