8.0
热点
AI SCORE
编程提效2026-08-25 10:04
45 个 n8n AI Agent 重构实战:从 Legacy 到 LangChain 3.1
dev.to · AI#n8n#LangChain#AI Agent
Editor brief · 编辑速览
作者被 Reddit 网友指出使用过时 aiAgent 节点后,将 45 个工作流全部迁移到 LangChain 集成架构,总结了 5 种生产级 Prompt 模式。
那篇改变一切的发帖
半年前,我在 r/n8n 发了一个包含 45 个工作流的 n8n AI Agent 套件。那一刻我非常自豪——直到一条评论指出我们正在使用 legacy aiAgent 节点(集成 LangChain 之前的版本)。
他说得对。旧架构的问题:
我们没有争辩,直接重写。
现代架构(v3.1)
现在每个工作流都使用:
{
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 3.1,
"position": [200, 300],
"parameters": {
"promptType": "define",
"text": "={{ $json.input }}",
"options": {
"systemMessage": "=You are a BANT qualification specialist...",
"maxIterations": 5
}
}
}
配合子节点 chat model:
{
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"typeVersion": 1,
"position": [200, 100],
"parameters": {
"modelName": "gemini-1.5-pro",
"temperature": 0.1
},
"credentials": {
"googleAiApi": "Google AI Studio"
}
}
通过 ai_languageModel 连接——而不是旧的 credential 字段。
真正有效的 5 种 Prompt 模式
重写了 9 大类共 45 个 Agent 后,这些模式区分出了可投入生产与只能演示的差距:
像职位描述一样构建 system prompt:
role: "BANT Qualification Specialist"
responsibilities:
- "Score leads 0-100 on Budget, Authority, Need, Timeline"
- "Output deterministic JSON: score, verdict, next_action"
constraints:
- "Never hallucinate fields not in payload"
- "Escalate if confidence < 0.75"
escalation_rules:
- "Below threshold → human review queue"
kpis:
- "Accuracy > 90% on test set"
- "False positive rate < 5%"
每个 Agent 都包含 3 个完整示例:
{
"input": {"lead": {"budget_status": "approved", "decision_maker_check": "yes"}},
"reasoning": "Budget approved + decision maker = strong signal",
"output": {"score": 85, "verdict": "warm", "next_action": "Send case study"}
}
不是"逐步思考",而是定义明确的阶段:
stages:
1. analyze_context: "What fields are present? What's missing?"
2. identify_intent: "What is this lead actually asking for?"
3. draft: "Build JSON response"
4. self_check: "Validate against schema, check confidence"
5. escalate_if: "confidence < 0.75 → human"
每个 Agent 给自己的置信度打分:
// Deterministic scoring (no LLM cost)
const score = calculateBANT(payload.lead);
const confidence = score >= 80 ? 0.95 : score >= 60 ? 0.75 : 0.5;
if (confidence < 0.75) return { escalate: true, reason: "Low confidence" };
const adversarialTests = [
{}, // empty payload
{ lead: { budget_status: "approved", decision_maker_check: "conflicting" }},
{ lead: { pain_point_validation: "" }}, // ambiguous
];
实时演示(无需搭建)
现在就可以测试 BANT Agent:
curl -X POST https://miguelabarca.app.n8n.cloud/webhook/bant-qualification \
-H "Content-Type: application/json" \
-d '{"lead":{"lead_email":"john@acme.com","company":"Acme Corp","lead_name":"John Smith","budget_status":"approved","decision_maker_check":"yes","pain_point_validation":"manual reporting","timeline_proximity":"this quarter"}}'
返回结果:{"score":100,"verdict":"hot","next_action":"Book discovery call"}
架构说明:
产品目录(70 个产品,全部 v3.1)
| Tier | Products | Price |
|---|---|---|
| Free | 4 workflows (RSS, BANT, Cart Recovery, KB) | $0 |
| Individual | 45 agents (9 categories) | $29 each |
| Niche Packs | E-com, Real Estate, SaaS (12 each) | $29 |
| Workflow Pack | All 45 + bonuses | $29 |
| Prompts Pro | 45 blueprints + Handbook | $27 |
| Vertical Bundles | SaaS/Enterprise/Agency | $79/$79/$149 |
| Lifetime License | 53 products, future included | $49 |
Active codes: LAUNCH30 (30% off) · FLASH59 ($20 off bundles)
我们学到的