Ep 15: The Secret of Intent — Prompt Engineering & Tool Description Mastery

⏱ Est. reading time: 11 min Updated on 4/9/2026

Why Does the Agent Sometimes Misbehave?

The root cause of wrong tool calls is always: System Prompt and Tool Descriptions are the Agent's steering wheel.

graph TB
    subgraph "Factors Affecting Agent Decisions (by weight)"
        SP[📝 System Prompt ⭐⭐⭐⭐⭐]
        TD[🔧 Tool Descriptions ⭐⭐⭐⭐]
        MC[🧠 Model Choice ⭐⭐⭐]
        T[🌡️ Temperature ⭐⭐]
    end
    SP --> TD --> MC --> T
    style SP fill:#ff6d5b,stroke:#e55a4e,color:#fff

1. Production System Prompt Template (6 Sections)

const systemPrompt = `
## 1. Identity — Who you are
## 2. Capabilities — Tools you have
## 3. Decision Rules — When to use which tool
## 4. Behavior — Language, length, format constraints
## 5. Few-Shot Examples — Show decision process
## 6. Boundaries — What you must never do
`;

2. Few-Shot Guidance

Few-Shot examples are the most effective calibration technique for Agent behavior:

// ✅ Good Few-Shot (shows the decision process):
// """
// User: "What does JavaScript's map function do?"
// Analysis: General programming knowledge, no tool needed
// Action: Answer directly
//
// User: "Calculate 1234 * 5.678 / 3.14"
// Analysis: Precise calculation needed
// Action: Call calculator("1234 * 5.678 / 3.14")
// """

3. WHAT-WHEN-NOT Tool Description Pattern

const toolDescription = `
WHAT: Query real-time inventory by SKU.
      Input: sku (string, e.g. "SKU-2026-001")
      Output: {"stock": 42, "warehouse": "Shanghai"}

WHEN: Use ONLY when user asks about:
      - Stock levels, quantities
      - Warehouse locations
      - Availability

NOT:  Do NOT use when user asks about:
      - Pricing (use query_pricing)
      - Order status (use query_order)
      - General chat
`;

4. Debugging Agent Tool Selection

graph TB
    Test[Test Input] --> Check1{Correct tool called?}
    Check1 -->|"No"| Fix1["Fix Tool Description"]
    Check1 -->|"Yes"| Check2{Correct params?}
    Check2 -->|"No"| Fix2["Fix parameter names"]
    Check2 -->|"Yes"| Check3{Good reply?}
    Check3 -->|"No"| Fix3["Adjust Temperature / Add Few-Shot"]
    Check3 -->|"Yes"| Done[✅ Done]
    style Fix1 fill:#ef4444,stroke:#dc2626,color:#fff
// View Agent's internal reasoning in n8n editor:
// 1. Click AI Agent node → Output tab → Logs section
// 2. See: LLM reasoning, Tool Call requests/responses, final synthesis
// This is n8n's most powerful debugging weapon!

Module 3 Complete!

mindmap
  root((Module 3: AI Agent Core))
    Ep 11 Model Setup
      Credentials
      Model Comparison
      Temperature
    Ep 12 Chatbot
      Chat Trigger
      Agentic Loop
      System Prompt Design
    Ep 13 Memory
      Window Buffer
      Session Isolation
      Injection Mechanics
    Ep 14 Tools
      Function Calling
      Built-in Tools
      Custom HTTP Tools
    Ep 15 Tuning
      6-Section Prompts
      Few-Shot Guidance
      WHAT-WHEN-NOT
      Debugging Flow

Next Module

From Ep 16, we enter RAG territory — equipping your Agent with proprietary domain knowledge via Retrieval-Augmented Generation pipelines.