⚠️ 入行提示:本文档为官方英文原版文献,社区中文精翻版本正在筹备中。
OpenClaw + n8n 工作流编排
.env.local 里又多一个凭证,又多一个可能被智能体意外泄露或滥用的攻击面。痛点
- 不可见:当智能体构建的内容埋在 JavaScript 技能文件或 shell 脚本中时,很难审查它实际做了什么
- 凭证泛滥:每个 API 密钥都存在于智能体的环境中,一次糟糕的提交就可能造成泄露
- Token 浪费:确定性的子任务(如发送邮件、更新电子表格)会消耗 LLM 的推理 token,而这些任务本可以作为简单的工作流运行
它能做什么
- 代理模式:OpenClaw 创建带有传入 webhook 的 n8n 工作流,然后通过调用这些 webhook 来完成所有未来的 API 交互
- 凭证隔离:API 密钥存储在 n8n 的凭证库中 —— 智能体只知道 webhook URL
- 可视化调试:每个工作流都可以在 n8n 的拖放式 UI 中查看
- 可锁定的工作流:一旦工作流构建并测试完毕,你可以将其锁定,防止智能体修改它与 API 的交互方式
- 安全防护步骤:你可以在任何外部调用执行之前,在 n8n 中添加验证、限速和审批门控
工作原理
- 智能体设计工作流:告诉 OpenClaw 你需要什么(例如,"创建一个工作流,当 GitHub issue 被标记为
urgent时发送 Slack 消息") - 智能体在 n8n 中构建:OpenClaw 通过 n8n 的 API 创建工作流,包含一个传入的 webhook 触发器
- 你添加凭证:打开 n8n 的 UI,手动添加你的 Slack token / GitHub token
- 你锁定工作流:防止智能体进一步修改
- 智能体调用 webhook:从现在起,OpenClaw 调用
http://n8n:5678/webhook/my-workflow并附带 JSON payload —— 它永远不会看到 API 密钥
┌──────────────┐ webhook call ┌─────────────────┐ API call ┌──────────────┐
│ OpenClaw │ ───────────────────→ │ n8n Workflow │ ─────────────→ │ External │
│ (agent) │ (no credentials) │ (locked, with │ (credentials │ Service │
│ │ │ API keys) │ stay here) │ (Slack, etc)│
└──────────────┘ └─────────────────┘ └──────────────┘
你需要的技能
n8nAPI 访问权限(用于创建/触发工作流)fetch或curl用于 webhook 调用- Docker(如果使用预配置的工具栈)
- n8n 凭证管理(手动,每个集成一次性设置)
如何搭建
选项 1:预配置的 Docker 工具栈
社区维护的 Docker Compose 设置(openclaw-n8n-stack)在共享的 Docker 网络上预连接了一切:
git clone https://github.com/caprihan/openclaw-n8n-stack.git
cd openclaw-n8n-stack
cp .env.template .env
# 在 .env 中添加你的 Anthropic API 密钥
docker-compose up -d
这为你提供:
- OpenClaw 运行在 3456 端口
- n8n 运行在 5678 端口
- 共享的 Docker 网络,让 OpenClaw 可以直接调用
http://n8n:5678/webhook/... - 预构建的工作流模板(多 LLM 事实核查、邮件分类、社交媒体监控)
选项 2:手动设置
- 安装 n8n(
npm install n8n -g或通过 Docker 运行) - 配置 OpenClaw,让它知道 n8n 的基础 URL
- 将以下内容添加到你的 AGENTS.md:
本页中文翻译尚未完成。以下保留同步时的完整英文原文,供核对全部步骤与限制。
完整英文原文
⚠️ 入行提示:本文档为官方英文原版文献,社区中文精翻版本正在筹备中。
OpenClaw + n8n Workflow Orchestration
Letting your AI agent directly manage API keys and call external services is a recipe for security incidents. Every new integration means another credential in .env.local, another surface for the agent to accidentally leak or misuse.
This use case describes a pattern where OpenClaw delegates all external API interactions to n8n workflows via webhooks — the agent never touches credentials, and every integration is visually inspectable and lockable.
Pain Point
When OpenClaw handles everything directly, you get three compounding problems:
- No visibility: It's hard to inspect what the agent actually built when it's buried in JavaScript skill files or shell scripts
- Credential sprawl: Every API key lives in the agent's environment, one bad commit away from exposure
- Wasted tokens: Deterministic sub-tasks (send an email, update a spreadsheet) burn LLM reasoning tokens when they could run as simple workflows
What It Does
- Proxy pattern: OpenClaw writes n8n workflows with incoming webhooks, then calls those webhooks for all future API interactions
- Credential isolation: API keys live in n8n's credential store — the agent only knows the webhook URL
- Visual debugging: Every workflow is inspectable in n8n's drag-and-drop UI
- Lockable workflows: Once a workflow is built and tested, you lock it so the agent can't modify how it interacts with the API
- Safeguard steps: You can add validation, rate limiting, and approval gates in n8n before any external call executes
How It Works
- Agent designs the workflow: Tell OpenClaw what you need (e.g., "create a workflow that sends a Slack message when a new GitHub issue is labeled
urgent") - Agent builds it in n8n: OpenClaw creates the workflow via n8n's API, including an incoming webhook trigger
- You add credentials: Open n8n's UI, add your Slack token / GitHub token manually
- You lock the workflow: Prevent further modifications by the agent
- Agent calls the webhook: From now on, OpenClaw calls
http://n8n:5678/webhook/my-workflowwith a JSON payload — it never sees the API key
┌──────────────┐ webhook call ┌─────────────────┐ API call ┌──────────────┐
│ OpenClaw │ ───────────────────→ │ n8n Workflow │ ─────────────→ │ External │
│ (agent) │ (no credentials) │ (locked, with │ (credentials │ Service │
│ │ │ API keys) │ stay here) │ (Slack, etc)│
└──────────────┘ └─────────────────┘ └──────────────┘
Skills You Need
n8nAPI access (for creating/triggering workflows)fetchorcurlfor webhook calls- Docker (if using the pre-configured stack)
- n8n credential management (manual, one-time setup per integration)
How to Set It Up
Option 1: Pre-configured Docker Stack
A community-maintained Docker Compose setup (openclaw-n8n-stack) pre-wires everything on a shared Docker network:
git clone https://github.com/caprihan/openclaw-n8n-stack.git
cd openclaw-n8n-stack
cp .env.template .env
# Add your Anthropic API key to .env
docker-compose up -d
This gives you:
- OpenClaw on port 3456
- n8n on port 5678
- Shared Docker network so OpenClaw can call
http://n8n:5678/webhook/...directly - Pre-built workflow templates (multi-LLM fact-checking, email triage, social monitoring)
Option 2: Manual Setup
- Install n8n (
npm install n8n -gor run via Docker) - Configure OpenClaw to know the n8n base URL
- Add this to your AGENTS.md:
## n8n Integration Pattern
When I need to interact with external APIs:
1. NEVER store API keys in my environment or skill files
2. Check if an n8n workflow already exists for this integration
3. If not, create one via n8n API with a webhook trigger
4. Notify the user to add credentials and lock the workflow
5. For all future calls, use the webhook URL with a JSON payload
Workflow naming: openclaw-{service}-{action}
Example: openclaw-slack-send-message
Webhook call format:
curl -X POST http://n8n:5678/webhook/{workflow-name} \
-H "Content-Type: application/json" \
-d '{"channel": "#general", "message": "Hello from OpenClaw"}'
Key Insights
- Three wins in one: Observability (visual UI), security (credential isolation), and performance (deterministic workflows don't burn tokens)
- Lock after testing: The "build → test → lock" cycle is critical — without locking, the agent can silently modify workflows
- n8n has 400+ integrations: Most external services you'd want to connect already have n8n nodes, saving the agent from writing custom API calls
- Audit trail for free: n8n logs every workflow execution with input/output data
Inspired By
This pattern was described by Simon Høiberg, who outlined three reasons this approach beats letting OpenClaw handle API interactions directly: observability through n8n's visual UI, security through credential isolation, and performance by running deterministic sub-tasks as workflows instead of LLM calls. The openclaw-n8n-stack repository provides a ready-to-run Docker Compose setup implementing this pattern.