{
  "name": "11 Ask your books (AI agent)",
  "nodes": [
    {
      "id": "69e89ac4-85ab-4625-89ad-8111a5e47a33",
      "name": "Question in",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "ask-your-books",
        "responseMode": "responseNode",
        "options": {}
      },
      "webhookId": "0487fb80-dbe2-5e6b-a9f1-d969b39b6577"
    },
    {
      "id": "3454809f-1543-47fa-93fb-2905d5ed5407",
      "name": "Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        240,
        300
      ],
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.body.question }}",
        "options": {
          "systemMessage": "=You answer questions about the quotes and invoices of a small business. Always call the business overview tool first and use only what it returns. Do not calculate yourself: take totals and days from the overview. Answer briefly in English, with amounts in dollars. Do not make anything up: if it is not in the overview, say so. When a question is about a client, mention both open invoices and pending quotes. Today's date is {{ $now.toFormat('yyyy-MM-dd') }}.",
          "maxIterations": 6,
          "returnIntermediateSteps": true
        }
      },
      "notes": "Decides which tool to call",
      "notesInFlow": true
    },
    {
      "id": "3c61a706-c1b3-43cd-8ae0-30a5c62b37f8",
      "name": "Chat model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        240,
        520
      ],
      "parameters": {
        "model": "qwen2.5:7b",
        "options": {
          "temperature": 0.2
        }
      }
    },
    {
      "id": "2c1fa561-1703-4250-9c9b-b5c7797e693e",
      "name": "Tool: business overview",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        480,
        520
      ],
      "parameters": {
        "description": "Returns the current overview: open invoices with days overdue, overdue invoices, pending quotes, all totals and what is open per client. Use it for every question.",
        "source": "database",
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "12 Business overview (helper for the agent)"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": []
        }
      },
      "notes": "The math lives in workflow 12",
      "notesInFlow": true
    },
    {
      "id": "3945674d-1ad3-4499-b448-2874c2cceeff",
      "name": "Send answer",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        480,
        300
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"answer\": $json.output } }}",
        "options": {}
      }
    },
    {
      "id": "0c2ca564-d191-4c19-8eca-d8980aef4d60",
      "name": "Read me",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -160
      ],
      "parameters": {
        "content": "## Ask your books (AI agent)\nTested on November 11, 2026, with n8n 2.47.3. Model: qwen2.5:7b via Ollama, 6 of 6 questions right on a repeat run.\n\n**Fill in:** a chat model, and pick template 12 in 'Tool: business overview'. Ask questions with a POST to the webhook: {\"question\": \"...\"}.\n\nThe math lives in workflow 12, not in the model.",
        "height": 220,
        "width": 520,
        "color": 7
      }
    }
  ],
  "connections": {
    "Question in": {
      "main": [
        [
          {
            "node": "Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agent": {
      "main": [
        [
          {
            "node": "Send answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat model": {
      "ai_languageModel": [
        [
          {
            "node": "Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Tool: business overview": {
      "ai_tool": [
        [
          {
            "node": "Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  }
}