返回顶部
o

openclaw-plugin-dev

OpenClaw Plugin Development Guide. For creating OpenClaw plugins, including hook mechanisms, logging, configuration management, etc. Trigger words: develop plugin, create plugin, plugin development, llm_input hook, llm_output hook, wrapStreamFn.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
120
下载量
1
收藏
概述
安装方式
版本历史

openclaw-plugin-dev

# OpenClaw Plugin Development Guide ## Core Concepts ### Hook Mechanism OpenClaw provides various hooks to intercept and process events: | Hook | Trigger Timing | Usage | |------|----------------|-------| | `llm_input` | Before an LLM request is sent | Capture requests (prompt, systemPrompt, historyMessages) | | `llm_output` | After an LLM response is completed | Capture responses (assistantTexts, usage) | | `agent_start` | When an Agent session starts | Initialize session state | | `agent_end` | When an Agent session ends | Clean up resources and record statistics | ### Request-Response Correlation Use `runId` to correlate requests and responses: ```typescript const inFlightRequests = new Map<string, RequestData>(); api.on("llm_input", (event: any) => { const runId = event.runId; inFlightRequests.set(runId, { timestamp: Date.now(), input: event }); }); api.on("llm_output", (event: any) => { const runId = event.runId; const request = inFlightRequests.get(runId); // Successfully paired, record the complete request-response inFlightRequests.delete(runId); }); ``` ## Plugin Structure ``` ~/.openclaw/extensions/plugin-name/ ├── openclaw.plugin.json # Plugin manifest ├── index.ts # Main entry ├── logger.ts # Utility module (optional) └── README.md # Documentation (optional) ``` ### Manifest Example ```json { "id": "plugin-name", "name": "Plugin Name", "version": "1.0.0", "main": "index.ts", "description": "Plugin description" } ``` ### Main Entry Template ```typescript type OpenClawPluginApi = { config?: any; pluginConfig?: unknown; logger: { info: (msg: string) => void; warn: (msg: string) => void; error: (msg: string) => void }; on: (hookName: string, handler: (event: any, ctx?: any) => void, opts?: { priority?: number }) => void; }; const plugin = { id: "plugin-name", name: "Plugin Name", description: "Plugin description", register(api: OpenClawPluginApi) { // Get configuration const config = api.config?.plugins?.entries?.["plugin-name"]?.config ?? {}; // Register hooks api.on("llm_input", (event) => { /* Handle request */ }); api.on("llm_output", (event) => { /* Handle response */ }); }, }; export default plugin; ``` ## Common Patterns ### Logging ```typescript // JSONL format, split files by date const logPath = path.join(basePath, `${new Date().toISOString().split('T')[0]}.jsonl`); fs.appendFileSync(logPath, JSON.stringify(entry) + "\n"); ``` ### Configuration Management ```typescript const DEFAULT_CONFIG = { enabled: true, logPath: "~/.openclaw/logs/plugin-name", }; const config = { ...DEFAULT_CONFIG, ...rawConfig }; ``` ## Notes ### Hook Lifecycle - `llm_output` **depends on normal session termination** - `llm_output` may not fire if the session is interrupted (gateway restart, user sends a new message) - Design for interruption scenarios to avoid resource leaks ### Debugging Methods ```bash # Check gateway logs to confirm hook triggering grep "llm_output" ~/.openclaw/logs/gateway.log # Check plugin loading grep "plugin-name" ~/.openclaw/logs/gateway.log ``` ### Configuration Location Enable the plugin in `openclaw.json`: ```json { "plugins": { "entries": { "plugin-name": { "enabled": true, "config": { "option1": "value1" } } } } } ``` ## Example: LLM API Logger Full example available at `https://github.com/cicadaFang/openclaw-llm-api-logger` Features: - Log all LLM API requests and responses - JSONL formatted logs, split by date - Correlate requests and responses using runId - Record metrics such as durationMs and usage

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 openclaw-plugin-dev-1775940900 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 openclaw-plugin-dev-1775940900 技能

通过命令行安装

skillhub install openclaw-plugin-dev-1775940900

下载 Zip 包

⬇ 下载 openclaw-plugin-dev v1.0.0

文件大小: 2.39 KB | 发布时间: 2026-4-12 10:50

v1.0.0 最新 2026-4-12 10:50
Initial release of the OpenClaw Plugin Development Guide.

- Introduces hook mechanisms for plugin development, including llm_input, llm_output, agent_start, and agent_end.
- Documents plugin structure and manifest requirements.
- Provides code templates for request-response correlation, logging, and configuration management.
- Includes notes on hook lifecycle and debugging methods.
- Offers example configuration and a reference LLM API logger plugin.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部