Course/Chapter 8/5. AI Agents & Tool Calling
    advanced
    Chapter 8: AI & LLM Integration

    5. AI Agents & Tool Calling

    Create autonomous AI agents in n8n.

    20m Lesson 5 of 5

    AI agents can reason about tasks and decide which tools to use — making your workflows truly intelligent.

    Agent Capabilities

    • - Search the web for current information
    • - Query databases and APIs
    • - Perform calculations
    • - Send emails and messages
    • - Create and update records

    How Agents Work in n8n

    1. Define tools: Each tool is a sub-workflow or API call the agent can use
    2. System prompt: Tell the agent its role and constraints
    3. User input: The agent receives a task or question
    4. Reasoning loop: The agent decides which tool(s) to call, processes results, and responds

    n8n AI Agent Node

    The AI Agent node provides a visual interface for building agents: - Connect tools as sub-nodes - Set memory (conversation history) - Configure model and parameters - Add output parsers for structured responses

    Code Examples

    Agent System Prompt Template
    text
    You are a customer support agent for Acme Corp.
    
    You have access to these tools:
    1. search_knowledge_base: Search our docs for answers
    2. lookup_order: Get order details by order ID
    3. create_ticket: Create a support ticket
    4. send_email: Send an email to the customer
    
    Rules:
    - Always search the knowledge base before creating a ticket
    - Never share internal system IDs with customers
    - If you can't resolve the issue, create a ticket and
      inform the customer of the ticket number
    - Be friendly, concise, and professional
    - Always confirm destructive actions before proceeding
    Tool Definition for Agent
    json
    {
      "name": "lookup_order",
      "description": "Look up order details by order ID. Returns order status, items, shipping info, and payment status.",
      "parameters": {
        "type": "object",
        "properties": {
          "order_id": {
            "type": "string",
            "description": "The order ID (e.g., ORD-12345)"
          }
        },
        "required": ["order_id"]
      }
    }

    Pro Tips

    • 💡Start with simple agents (2–3 tools) and add complexity gradually
    • 💡Always set guardrails — limit the actions an agent can take to prevent unintended consequences
    • 💡Log every tool call the agent makes for debugging and auditing purposes

    Comprehension Quiz

    Answer 2 of 2 correctly to unlock lesson completion.

    1. What makes an AI agent different from a simple LLM call?

    2. What should you always set for AI agents?

    Pass the quiz above to unlock lesson completion