偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

n8n + AI Agent 提示工程:2025 年最有效的實(shí)操技巧

人工智能
根據(jù) Anthropic 的 Context Engineering 研究,在 2025 年,真正重要的不是“prompt engineering”,而是“context engineering”。問題不再是“如何打造完美的 prompt”,而是“哪種 context 組合能引發(fā)期望的行為”。

為什么大多數(shù) Prompting 方法會(huì)失效

根據(jù) Anthropic 的 Context Engineering 研究,在 2025 年,真正重要的不是“prompt engineering”,而是“context engineering”。問題不再是“如何打造完美的 prompt”,而是“哪種 context 組合能引發(fā)期望的行為”。

我會(huì)帶你走一遍當(dāng)前研究(Anthropic、OpenAI、Google、Wharton)對 AI agent prompting 的結(jié)論——以及如何在 n8n 工作流中具體落地。

你將學(xué)到:

  • System Message vs User Prompt(以及為什么錯(cuò)誤的分離會(huì)讓 token 成本翻倍)
  • 2025 年真正有效的五大核心技巧(有研究背書)
  • 高級(jí)模式(Chain-of-Thought、RAG、Structured Outputs、Tool Use)
  • 為什么應(yīng)該與模型一起生成 prompt,而不是手工堆砌
  • 模型相關(guān)注意事項(xiàng)(只講實(shí)際相關(guān)的)
  • 生產(chǎn)級(jí)模式(測試、錯(cuò)誤處理、token 優(yōu)化)

復(fù)制模板的陷阱

我經(jīng)常見到:有人在 Reddit 上找到一個(gè)“完美”的 prompt 模板,復(fù)制到 AI Agent Node 里,然后期待它“魔法生效”。

劇透:不會(huì)。

復(fù)制模板失敗的原因:

  • Context mismatch:模板是為完全不同的用例、數(shù)據(jù)、工具寫的
  • Model differences:模板對 Claude 3 有效,而你用的是 GPT-4o-mini
  • Over-complexity:模板有 500 行,因?yàn)樽髡呦敫采w所有邊界情況
  • Under-specification:模板過于通用,對任何事都不夠好

Anthropic 的 Prompt Engineering 指南強(qiáng)調(diào)“找到合適的高度”(right altitude)——對指導(dǎo)足夠具體,但又為推理留有空間。模板對你的特定場景來說,幾乎總是在錯(cuò)誤的高度。

第二個(gè)問題:Prompt 過于復(fù)雜

“越多越好”的思路會(huì)帶來巨大問題:

  • Ignored instructions:當(dāng) context 超過 800+ 行,模型會(huì)開始忽略指令——Context Engineering 研究顯示 LLM 有“有限注意力預(yù)算”
  • Increased latency:更多 tokens = 更慢響應(yīng)
  • Higher costs:每個(gè)額外 token 都要花錢
  • Maintenance nightmare:800 行 prompt 幾乎無法調(diào)試或優(yōu)化

解決方案:與模型一起生成 prompt

真正的游戲規(guī)則改變者是:讓模型為你寫 prompt。

不要花數(shù)小時(shí)打磨 prompt,而是給模型:

  • 你的目標(biāo)(agent 要做什么)
  • 示例(輸入/輸出對)
  • 約束(不該做什么)

模型會(huì)生成為你場景優(yōu)化的 prompt。你測試、與模型迭代、再細(xì)化。

為什么有效:模型最了解自己的“偏好”。它知道哪種表述、結(jié)構(gòu)、示例最有效。

稍后我會(huì)展示具體做法。

基礎(chǔ):n8n 中的 System Message 與 User Prompt

n8n 的 AI Agent prompting 中最基礎(chǔ)也最常見的錯(cuò)誤:混淆 System Message 和 User Prompt。

在 AI Agent Node 中,有兩個(gè)不同的 prompt 區(qū)域:

System Message(Options → System Message):

  • 定義 agent 的持久“DNA”
  • 每次請求都會(huì)發(fā)送
  • 幾乎不變/不應(yīng)該頻繁更改
  • 包含:role、tools、workflow、constraints

User Prompt(主輸入):

  • 只針對“本次請求”的具體任務(wù)
  • 來自 Chat Trigger、Webhooks 或前置節(jié)點(diǎn)
  • 每次請求都變化
  • 只應(yīng)包含本次的具體任務(wù)

圖片圖片

為什么重要:Token 經(jīng)濟(jì)學(xué)與 Prompt Caching

兩者都會(huì)隨每次 API 調(diào)用發(fā)送。但正確分離對成本和性能都至關(guān)重要:

錯(cuò)誤做法(把一切都塞進(jìn) User Prompt):

"You are Senior Support Engineer. Tools: search_docs, create_ticket.
Use search_docs first. Max 150 words. Friendly.
User question: {{$json.message}}"

若每天 1,000 次請求、每次 400 tokens: = 400,000 個(gè)冗余 tokens = 以 Claude Sonnet($3/M)計(jì):$1.20/天 = 每月 $36 的純?nèi)哂?context

正確做法:

System Message(只定義一次):

You are Senior Support Engineer.
TOOLS:
- search_docs(query): Search Product Docs
- create_ticket(title, priority): Create Support Ticket
WORKFLOW:
1. FAQ → search_docs
2. Complex Issue → create_ticket
BEHAVIOR:
- Max 150 words
- When uncertain: Create ticket, don't guess

User Prompt 僅為:{{$json.message}}

= 每次 50 tokens 而非 400 = 節(jié)省:每天 350K tokens = 每月約 $31.50(以 Claude Sonnet 計(jì))

Prompt Caching:為什么 System Message 應(yīng)盡量保持靜態(tài)

Anthropic 和 OpenAI 提供 Prompt Caching——System Message 會(huì)被緩存,不必每次都重新處理??蓪⒀舆t降低 50–80%,對已緩存的 tokens 成本最高可降至 10%。

但:一旦你更改 System Message,緩存就會(huì)失效。因此:

  • 設(shè)計(jì) System Message 為靜態(tài):基礎(chǔ)角色、工具、工作流邏輯
  • 用 User Prompt 承載可變信息:動(dòng)態(tài)數(shù)據(jù)、具體任務(wù)
  • 僅在出現(xiàn)重大變更時(shí)更新 System Message:新增工具、工作流邏輯改變

緩存影響示例:

無緩存: 請求 1:500 tokens 的 System Message = $0.0015 請求 2:500 tokens 的 System Message = $0.0015 請求 1000:500 tokens 的 System Message = $0.0015 總計(jì):1,000 次請求 $1.50

有緩存(System Message 保持穩(wěn)定): 請求 1:500 tokens 的 System Message = $0.0015(寫入緩存) 請求 2:500 tokens 緩存命中 = $0.00015(便宜 90%) 請求 1000:500 tokens 緩存命中 = $0.00015 總計(jì):~$0.15/1000 次請求 = 90% 節(jié)省

Dynamic System Messages:強(qiáng)大但要謹(jǐn)慎

你可以用 n8n Expressions 讓 System Message 動(dòng)態(tài)化——但要注意緩存:

You are Support Engineer for {{$('Get Config').item.json.company_name}}.

PRODUCT: {{$('Get Config').item.json.product_description}}
TONE: {{$('Get Config').item.json.support_tone}}

適用場景:多租戶系統(tǒng)——一個(gè)工作流,多個(gè)客戶配置。

工作流:Webhook(Customer ID) → DB Lookup → AI Agent(動(dòng)態(tài) System Message) → Response

緩存權(quán)衡:動(dòng)態(tài) System Message 會(huì)破壞緩存——僅在必要時(shí)使用。

五大核心技巧:2024–2025 年研究給出的答案

來自 Anthropic、OpenAI、Google 在 2024–2025 的研究顯示:有一些對所有模型都有效的基本技巧。以下五條最重要:

圖片圖片

技巧 1:清晰與具體(“Altitude” 原則)

Anthropic 的 Prompt Engineering 指南稱之為“找到合適的高度”(right altitude)——既足夠具體以提供指導(dǎo),又為推理保留靈活性。

“同事測試”:如果一個(gè)聰明的同事看不懂這條指令,AI 也不會(huì)懂。

反例:

Classify emails intelligently and accurately.

“intelligently” 是什么?有哪些類別?輸出格式是怎樣?

正例:

Classify emails into: sales, support, billing, general

URGENCY CRITERIA:
- high: contains "urgent", "asap", "immediately", "broken"
- medium: time-related request without extremity
- low: everything else
OUTPUT: JSON
{
  "category": "support",
  "urgency": "high",
  "confidence": 0.92
}

為何有效:

  • 消除歧義(明確只有四類)
  • 提供決策標(biāo)準(zhǔn)(非主觀)
  • 明確輸出格式(無需猜測)
  • 可度量(有 confidence 分?jǐn)?shù))

技巧 2:正向指令(質(zhì)量提升 57%)

Bsharat 等(2024)研究顯示,正向指令明顯優(yōu)于負(fù)向指令。將“不要做 X”改為“請做 Y”,平均帶來 57% 的質(zhì)量提升。

負(fù)向指令為何失效:

  • 模型先要理解你“不想要”的
  • 再推斷你“想要”的
  • 這個(gè)兩步推理經(jīng)常失敗

負(fù)向反例:

Don't be too wordy.
Don't use technical jargon.
Don't make assumptions about customer intent.

正向改寫:

Keep responses under 150 words.
Use plain language that a non-technical customer understands.
When customer intent is unclear, ask clarifying questions.

實(shí)際影響:

在生產(chǎn)環(huán)境的郵件分類 agent 中,負(fù)向指令(“不要誤判緊急請求”)造成 31% 的漏判。正向改寫(“凡含時(shí)間限制的請求一律標(biāo)記為 urgent”)將漏判降至 8%。

技巧 3:Few-Shot Learning(示范勝于告知)

Few-shot 示例非常有效——但大多數(shù)人用錯(cuò)了。

研究共識(shí):

  • 大多數(shù)任務(wù) 2–5 個(gè)示例最優(yōu)(更多幫助不大)
  • 示例要“多樣化”(avoid 相似堆砌)
  • 應(yīng)包含 edge cases
  • Label bias 重要:Zhao 等(2021)顯示示例順序會(huì)影響結(jié)果

糟糕的 few-shot(過于相似):

EXAMPLES:
1."How do I reset my password?"→category:support,urgency:low
2."Where is the password reset option?"→category:support,urgency:low
3."I can't find password settings."→category:support,urgency:low

全是同一種問題。模型學(xué)不到邊界處理。

良好的 few-shot(多樣且含 edge cases):

Example 1 (Standard):
Input: "How do I reset my password?"
Output: {"category": "support", "urgency": "low", "confidence": 0.95}
Example 2 (Urgent):
Input: "URGENT: System down, can't access customer data!"
Output: {"category": "support", "urgency": "high", "confidence": 0.98}
Example 3 (Mixed Intent):
Input: "I want to upgrade my plan but also report a billing error."
Output: {"category": "billing", "urgency": "medium", "confidence": 0.78, "note": "Multiple intents detected"}
Example 4 (Edge Case - Unclear):
Input: "help"
Output: {"category": "general", "urgency": "low", "confidence": 0.45, "action": "request_clarification"}

為何有效:

  • 覆蓋不同場景(標(biāo)準(zhǔn)、緊急、混合、不清楚)
  • 示范如何處理邊界(低置信度 → 追問澄清)
  • 展示一致的輸出格式
  • 讓模型學(xué)習(xí)決策模式,而非僅做類別匹配

技巧 4:Constraints & Grounding(對抗幻覺)

AI agents 的大問題之一:hallucination(幻覺)。找不到答案時(shí)它們會(huì)編造。

解決方案:顯式約束,將 agent “落地”。

糟糕做法(無約束):

Answer customer support questions based on our documentation.

后果:找不到信息時(shí) agent 會(huì)胡編。

良好做法(顯式約束):

Answer customer support questions using ONLY information from the documentation you can access via search_docs tool.

CONSTRAINTS:
- If information is not in docs: "I don't have that information in our current documentation. I'll create a ticket for our team to help you."
- Never make assumptions about features or functionality
- Never provide workarounds that aren't documented
- If multiple solutions exist: Present all documented options
ESCALATION CRITERIA:
- Customer mentions "urgent", "broken", "down" → create ticket immediately
- Question requires account-specific data → create ticket with details
- Documentation is incomplete/contradictory → create ticket noting the issue

為何有效:

  • 清晰邊界(ONLY 文檔中的信息)
  • 明確兜底行為(不確定時(shí)怎么做)
  • 升級(jí)標(biāo)準(zhǔn)(何時(shí)轉(zhuǎn)人類)
  • 不留“自由發(fā)揮”的空間

生產(chǎn)影響:

在每月處理 2000+ 詢問的客服 agent 中,加入約束將幻覺率從 23% 降至 3%。升級(jí)的人工工單質(zhì)量顯著提升,因?yàn)楣螘?huì)包含具體的文檔缺口信息。

技巧 5:Context Engineering(最小高信號(hào) token 集)

Anthropic 的研究很明確:不是“更多 context”,而是“正確的 context”。

原則:Smallest High-Signal Token Set

  • 你的 context 中每一個(gè) token 都應(yīng)提供價(jià)值
  • 冗余信息會(huì)稀釋關(guān)鍵信號(hào)
  • 更多 context ≠ 更好表現(xiàn)(往往適得其反)

糟糕的 context(冗長、重復(fù)):

You are a helpful AI assistant designed to help customers with their questions and concerns. You should always be polite, professional, and courteous in your responses. Make sure to read the customer's question carefully and provide a thorough and complete answer that addresses all of their concerns. If you're not sure about something, it's better to say you don't know than to provide incorrect information...

350 個(gè) token 的空話,幾乎沒有可執(zhí)行指導(dǎo)。

良好的 context(密度高、具體):

You are Support Agent.

RESPONSE REQUIREMENTS:
- Max 150 words
- Plain language (non-technical)
- Structure: Problem acknowledgment → Solution → Next steps
TOOLS:
- search_docs(query) → search product documentation
- create_ticket(title, priority, details) → escalate to human team
WORKFLOW:
1. Search docs for relevant information
2. If found: Provide answer with doc reference
3. If not found OR customer mentions "urgent"/"broken": Create ticket

110 個(gè) token,信號(hào)密度很高。每行都有可執(zhí)行信息。

Token 審計(jì):

對 prompt 中每個(gè)句子問一句:“刪掉它,agent 會(huì)變差嗎?”如果不會(huì),就刪。

高級(jí)模式:何時(shí)用(何時(shí)別用)

核心技巧適用于所有場景。下面這些高級(jí)模式非常強(qiáng),但要“對癥下藥”。

模式 1:Chain-of-Thought(CoT)——用于復(fù)雜多步推理

沃頓商學(xué)院 2025 年 6 月的研究給出了迄今最全面的分析:CoT 對復(fù)雜推理有幫助,但對簡單任務(wù)效果參差。

何時(shí)使用 CoT:

  • 需要多步邏輯推理
  • 數(shù)學(xué)計(jì)算
  • 有依賴關(guān)系的復(fù)雜決策樹
  • 中間步驟重要的任務(wù)

不該用 CoT 的場景:

  • 簡單分類(增加負(fù)擔(dān)無益)
  • 模式匹配型任務(wù)
  • 對速度極其敏感(CoT 會(huì)增加延遲)

圖片圖片

在 n8n 中的實(shí)現(xiàn):

TASK: Analyze customer request and determine best resolution path.

REASONING PROCESS (think step-by-step):
1. IDENTIFY: What is the core issue? (Quote specific parts of message)
2. CLASSIFY: Which category? (sales/support/billing/general)
3. ASSESS URGENCY: Time-sensitive keywords? Tone indicators?
4. CHECK PREREQUISITES: Can we resolve with available tools?
5. DECIDE: Route to appropriate handler with reasoning
Think through each step explicitly before providing your final answer.

性能影響:

  • 準(zhǔn)確度提升:復(fù)雜推理任務(wù)提升 2–5%
  • 延遲增加:20–40%(模型輸出更多 tokens)
  • 成本增加:與輸出 token 增長成正比

結(jié)論:只有當(dāng)準(zhǔn)確度提升能抵消成本和延遲的權(quán)衡時(shí),才使用 CoT。

模式 2:RAG(Retrieval-Augmented Generation)——用于外部知識(shí)

當(dāng)你的 agent 需要:

  • 動(dòng)態(tài)/頻繁更新的內(nèi)容(產(chǎn)品目錄、文檔)
  • 體量巨大、放不進(jìn) context 的知識(shí)庫
  • 客戶特定數(shù)據(jù)(訂單記錄、賬戶詳情)
  • 訓(xùn)練語料之外的專有信息

RAG 就是必需的。

n8n 中的 RAG 基本流程:

Webhook/Trigger
  ↓
Extract Query (user's question)
  ↓
Vector Search (retrieve relevant chunks from knowledge base)
  ↓
AI Agent (answer using retrieved context)
  ↓
Response

關(guān)鍵 RAG 要點(diǎn)(基于 kapa.ai 的分析):

  • Chunk size:每塊 500–800 tokens(大多任務(wù)的最佳區(qū)間)
  • Overlap:塊間重疊 50–100 tokens(避免邊界信息丟失)
  • Number of chunks:返回 3–5 個(gè)最相關(guān)塊
  • Reranking:向量召回后做語義重排以提升相關(guān)性
  • Metadata:包含來源、時(shí)間戳、置信度

RAG Prompt 示例:

Answer the customer's question using ONLY the information provided below.

CONTEXT FROM DOCUMENTATION:
{{$json.retrieved_chunks}}
CUSTOMER QUESTION:
{{$json.user_message}}
INSTRUCTIONS:
- Base answer strictly on provided context
- If context doesn't contain the answer: "I don't have that information in our current documentation."
- Include source reference: "According to [doc_title]..."
- If multiple relevant sections: Synthesize information from all
CONFIDENCE ASSESSMENT:
- High confidence: Answer directly stated in context
- Medium confidence: Answer can be inferred from context
- Low confidence: Context is incomplete → escalate

模式 3:Document Repacking——順序比你想的更重要

Wang 等(2024)研究發(fā)現(xiàn):context 的“順序”影響顯著。

發(fā)現(xiàn)要點(diǎn):

  • Primacy bias:模型更注意開頭的信息
  • Recency bias:也更注意結(jié)尾的信息
  • Middle neglect:中間的信息更容易被忽略
  • 性能影響:通過最優(yōu)排序可提升 5–10% 準(zhǔn)確度

最優(yōu)排序策略:

  1. 最相關(guān)/最重要的信息放最前
  2. 次要的支持信息放中間
  3. 約束與提醒放最后(利用近因效應(yīng))

示例(RAG context):

MOST RELEVANT DOCUMENTATION:
[Chunk with highest relevance score]

ADDITIONAL CONTEXT:
[Supporting chunks]
CONSTRAINTS (IMPORTANT):
- Answer only from provided context
- If uncertain: Escalate to human team

模式 4:Structured Outputs——為數(shù)據(jù)抽取提供 100% 可靠性

OpenAI 的 Structured Outputs(GPT-4o)及其他模型的類似能力,解決了一個(gè)大問題:獲得一致、可解析的輸出。

傳統(tǒng) prompting 的問題:

Output format: JSON with fields category, urgency, confidence

模型可能會(huì)輸出:

  • 合法 JSON
  • 帶多余字段的 JSON
  • 缺字段的 JSON
  • 格式錯(cuò)誤的 JSON
  • 先文字解釋再給 JSON

你得為這些情況全部做兜底。

Structured Outputs 的方案:

定義 JSON schema,配合 Structured Output Parser 節(jié)點(diǎn)攔截異常即可。

示例 schema:

{
  "type":"object",
"properties":{
    "category":{
      "type":"string",
      "enum":["sales","support","billing","general"]
    },
    "urgency":{
      "type":"string",
      "enum":["low","medium","high"]
    },
    "confidence":{
      "type":"number",
      "minimum":0,
      "maximum":1"
    },
    "reasoning": {
      "type": "string"
    }
  },
  "required": ["category", "urgency", "confidence"]
}

好處:

  • 不再有解析錯(cuò)誤
  • 保證 schema 合規(guī)
  • 下游處理更簡單
  • Enum 約束(只允許有效值)

何時(shí)使用:

  • 非結(jié)構(gòu)化文本的數(shù)據(jù)抽取
  • 固定類別的分類
  • 需要特定格式的 API 集成
  • 任何對輸出格式一致性要求高的任務(wù)

元技能:與模型一起生成 prompt

我構(gòu)建 AI agents 的方式就此改變:別再手寫 prompt,讓模型來生成。

流程:

  1. 定義需求(agent 要做什么)
  2. 提供示例(能代表期望行為的輸入/輸出對)
  3. 指定約束(絕不該做什么)
  4. 讓模型生成“優(yōu)化后的”prompt
  5. 測試并迭代(基于實(shí)際表現(xiàn)微調(diào))

Meta-prompt 示例:

I'm building an AI agent for customer support email classification. Help me create an optimal system message prompt.

REQUIREMENTS:
- Classify emails into: sales, support, billing, general
- Assess urgency: low, medium, high
- Output format: JSON with category, urgency, confidence
- Must handle edge cases: unclear intent, multiple topics, spam
TOOLS AVAILABLE:
- search_docs(query): Search documentation
- create_ticket(title, priority, description): Escalate to humans
EXAMPLES OF DESIRED BEHAVIOR:
[Include 3-5 diverse examples with input and expected output]
CONSTRAINTS:
- Never make up information
- When uncertain (confidence < 0.7): Escalate
- Response under 150 words for direct answers
- Include reasoning in output
Generate an optimized system message that will consistently produce these results.

模型會(huì)生成一個(gè):

  • 結(jié)構(gòu)與措辭最優(yōu)
  • 融合有效技巧
  • 在具體與靈活間取得平衡
  • 針對你用例的 prompt

為何有效:

  • 模型了解自己的“偏好”
  • 它會(huì)采用最優(yōu)結(jié)構(gòu)和表述
  • 你能省下大量試錯(cuò)時(shí)間

模型相關(guān)注意事項(xiàng):哪些真的重要

大多數(shù)“模型特定技巧”并不靠譜。但有些差異確實(shí)重要:

Claude(Anthropic):

  • 優(yōu)勢:復(fù)雜推理、長 context(200K tokens)
  • 劣勢:有時(shí)過度謹(jǐn)慎,會(huì)拒絕無害請求
  • 最佳實(shí)踐:明確寫清 constraints,再讓其自由推理
  • Prompt caching:對 >1024 tokens 的 System Messages 啟用

GPT-4o(OpenAI):

  • 優(yōu)勢:Structured Outputs(100% schema 合規(guī))、速度快
  • 劣勢:context 較短(128K),較少“深思熟慮”
  • 最佳實(shí)踐:數(shù)據(jù)抽取使用 Structured Outputs,配合精確指令
  • Prompt caching:對 System Messages 自動(dòng)啟用

GPT-4o-mini:

  • 優(yōu)勢:便宜($0.15/M vs $3/M),適合簡單任務(wù)
  • 劣勢:復(fù)雜指令魯棒性較弱
  • 最佳實(shí)踐:使用具體、結(jié)構(gòu)化的 prompts,配 few-shot 示例

Gemini(Google):

  • 優(yōu)勢:多模態(tài)(圖像、視頻)、超長 context(2M tokens)
  • 劣勢:tool-use 支持較弱,有時(shí)不穩(wěn)定
  • 最佳實(shí)踐:用于多模態(tài)場景,避免復(fù)雜工具編排

選型經(jīng)驗(yàn)法則:

  • 復(fù)雜推理 + 長文檔 → Claude Sonnet
  • 數(shù)據(jù)抽取 + Structured Outputs → GPT-4o
  • 簡單分類 + 預(yù)算敏感 → GPT-4o-mini
  • 多模態(tài)(圖/視頻)→ Gemini

生產(chǎn)級(jí)模式:測試、錯(cuò)誤處理、優(yōu)化

好 prompt 遠(yuǎn)遠(yuǎn)不夠——你需要生產(chǎn)級(jí)工作流。

測試策略

用真實(shí)的 edge cases 測,別只測“快樂路徑”:

Test cases for email triager:
? Standard support request
? Angry customer (caps, exclamation marks)
? Sales inquiry with technical questions (mixed intent)
? Very short message ("help")
? Wrong language (if only English supported)
? Spam/irrelevant content

錯(cuò)誤處理

AI agents 可能失敗——要有兜底:

n8n workflow:
AI Agent Node
  → IF Error OR confidence < 0.7:
     → Fallback: Route to Human
  → ELSE:
     → Continue with automated workflow

帶 confidence 的 System Message 約定:

If you're uncertain (confidence < 70%):
Set "needs_human_review": true in output

Token 優(yōu)化

高并發(fā)下,每個(gè) token 都很寶貴:

  • 移除冗余:例如 “Please”、“Thanks”、“I think”
  • 合理縮寫:“Maximum”→“Max”,“Information”→“Info”
  • 使用符號(hào):“→” 代替 “then”,“?” 代替 “correct”
  • 用 JSON 替代散文:結(jié)構(gòu)化數(shù)據(jù)優(yōu)于長句
  1. 監(jiān)控與日志

跟蹤關(guān)鍵指標(biāo):

  • Latency:agent 響應(yīng)耗時(shí)
  • Token usage:每次請求的輸入 + 輸出 tokens
  • Error rate:失敗頻率
  • Confidence distribution:置信度分布

在 n8n 中:用 Webhook → Google Sheets 進(jìn)行輕量記錄:

After AI Agent Node:
→ Set Node (Extract Metrics):
   - latency: {{$now - $('AI Agent').json.startTime}}
   - input_tokens: {{$('AI Agent').json.usage.input_tokens}}
   - output_tokens: {{$('AI Agent').json.usage.output_tokens}}
   - confidence: {{$('AI Agent').json.confidence}}
→ Google Sheets (Append Row)

上線檢查清單

上線前:

Prompt 質(zhì)量:

  • System Message 與 User Prompt 是否正確分離?
  • System Message 是否穩(wěn)定以利用 prompt caching?
  • 是否使用正向指令(而非“避免 X”)?
  • 是否有含 edge cases 的 few-shot 示例?
  • 約束是否清晰?
  • 輸出格式是否明確?

測試:

  • 是否用 10+ 個(gè)真實(shí)測試用例?
  • 邊界情況(短輸入、錯(cuò)別字、混合意圖)是否覆蓋?
  • 錯(cuò)誤處理是否有效?
  • 不確定時(shí)是否有 fallback 策略?

性能:

  • Token 是否優(yōu)化(無冗余)?
  • 是否啟用 prompt caching?
  • 延遲是否可接受(< 3s)?
  • 單次請求成本是否核算?

監(jiān)控:

  • 是否記錄 token 使用?
  • 是否實(shí)現(xiàn)錯(cuò)誤跟蹤?
  • 是否啟用置信度評(píng)分?
  • 是否有關(guān)鍵指標(biāo)儀表板?

迭代:

  • 是否有 A/B 測試策略來改進(jìn) prompt?
  • 是否建立基于真實(shí)用戶數(shù)據(jù)的反饋回路?
  • 是否規(guī)劃定期復(fù)盤?

總結(jié):2025 年真正有效的是什么

五大通用核心技巧:

  • Clarity & Specificity:合適的“高度”——具體且保留推理空間
  • Positive Instructions:質(zhì)量提升 57%(Bsharat 等,2024)
  • Few-Shot Learning:多樣示例 + 邊界情況
  • Constraints & Grounding:以清晰邊界對抗幻覺
  • Context Engineering:最小高信號(hào) token 集

情境性高級(jí)模式:

  • Chain-of-Thought:僅用于復(fù)雜多步推理(提升 2–5%)
  • RAG:應(yīng)對外部/更新知識(shí)(chunk 500–800 tokens)
  • Document Repacking:通過排序提升 5–10% 準(zhǔn)確度
  • Structured Outputs:數(shù)據(jù)抽取 100% 可靠(GPT-4o)

元結(jié)論:

  • 復(fù)制模板會(huì)失敗——與模型一起生成 prompts
  • 保持 System Message 穩(wěn)定以發(fā)揮 prompt caching(可省 90% 成本)
  • Token 經(jīng)濟(jì)學(xué)比“完美措辭”更重要
  • 用 edge cases 做測試比“再加幾個(gè) few-shot”更關(guān)鍵

圖片圖片

你的下一步:挑一個(gè)現(xiàn)有的 n8n AI Agent 工作流,套用以上五大核心技巧。對比前后 token 使用。通常你會(huì)看到成本大幅下降,同時(shí)輸出質(zhì)量不降反升。

這就是“勉強(qiáng)可用”的 prompting 與“可規(guī)模化、可上生產(chǎn)”的 prompting 的區(qū)別。

責(zé)任編輯:武曉燕 來源: AI大模型觀察站
相關(guān)推薦

2025-10-27 01:22:00

n8nwindowsdocker

2010-04-14 11:22:12

Oracle同時(shí)訪問

2025-08-25 08:05:23

2025-06-30 09:37:39

2025-04-21 07:00:00

2025-07-01 08:17:16

2025-05-13 04:00:00

2025-06-30 08:31:08

2025-06-06 02:11:00

MCP服務(wù)器AI

2025-05-28 02:45:00

Dify扣子Ragflow

2025-10-28 02:11:00

AI幻覺AI輸出工具

2025-09-24 00:00:00

2025-10-17 02:11:00

AIAgent機(jī)器人

2023-10-30 00:14:34

Agent提示工程LLM

2022-01-11 07:59:15

K8S KubernetesAirflow

2025-01-17 09:30:21

2025-08-26 03:00:00

Excel技巧數(shù)據(jù)

2010-04-28 16:59:16

2010-03-23 14:24:12

2010-07-01 14:59:51

FreeBSD 8
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)