DEV Community

Cover image for Prompts Matter in Agentic Workflows

Prompts Matter in Agentic Workflows

Guys I had created a n8n workflow with all the tools and everything in place.

tl;dr

Too long did not read version


Here is the workflow:

{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.4,
      "position": [
        0,
        0
      ],
      "id": "a28a630c-8f87-4881-bf5a-1c0d3b9ab597",
      "name": "When chat message received",
      "webhookId": "43333eec-230f-44ed-a007-a8513f0904b1",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "You are the a helpful assistant"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        208,
        0
      ],
      "id": "ec551627-7dc3-4884-9f35-bbda0bf038a0",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        80,
        208
      ],
      "id": "e5c2a58c-63b2-4850-9ed5-15aff77ce32b",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "0h4kMjpTValhfJZv",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.4,
      "position": [
        224,
        208
      ],
      "id": "3cee5ca7-d6b9-4d82-a0e0-5d17430bde1f",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc",
          "mode": "list",
          "cachedResultName": "stock-portfolio",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        400,
        208
      ],
      "id": "518fb3c0-f6ee-430d-a8e1-5865f6ac8c77",
      "name": "Get row(s) in sheet in Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "b7aCwM5d7t0oTzxp",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "symbols": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Ticker', ``, 'string') }}",
        "filters": {
          "latest": true
        }
      },
      "type": "n8n-nodes-base.marketstackTool",
      "typeVersion": 1,
      "position": [
        560,
        208
      ],
      "id": "8393c58b-aa11-4b0d-9224-4bd53607c714",
      "name": "Get many EoD data in Marketstack",
      "credentials": {
        "marketstackApi": {
          "id": "uykspUJ9pFnekPFQ",
          "name": "Marketstack account"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc",
          "mode": "list",
          "cachedResultName": "stock-portfolio",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "price": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('price', ``, 'string') }}",
            "stock": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('stock__using_to_match_', ``, 'string') }}"
          },
          "matchingColumns": [
            "stock"
          ],
          "schema": [
            {
              "id": "stock",
              "displayName": "stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "quantity",
              "displayName": "quantity",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        720,
        208
      ],
      "id": "349e23c1-e12e-419f-934b-667239a2d27b",
      "name": "Update row in sheet in Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "b7aCwM5d7t0oTzxp",
          "name": "Google Sheets account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get many EoD data in Marketstack": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update row in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "9f029cb8-8c3b-4002-af31-f3eef8ed0fc4",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "d7f40ac67c918c6b77c1db2f31baa37e504a493b4a22e372f2a513b7bf0ca5a9"
  },
  "nodeGroups": [],
  "id": "6bsOs8ssUv4uxhna",
  "tags": []
}
Enter fullscreen mode Exit fullscreen mode

And when I was passing it this prompt:

Can you update the price column of those stocks in my google sheet?

gpt-4.0-mini replied:

I can help with that! Please provide the details of the stock tickers and their corresponding prices that you want to update in your Google Sheet.

So it was NOT able to know how to use the tools available to it. But then when I just tweaked the model a little it started to work. Here is the new prompt which worked:

Please update the price column of those stocks in that sheet based on latest stock prices?

And the same model this time again replied 🤯:

The prices have been successfully updated in the sheet:

  • GOOGL: $373.51
  • AAPL: $303.42
  • TSLA: $322.08

If you need any further assistance, feel free to ask!


And for this workflow:

{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.4,
      "position": [
        0,
        0
      ],
      "id": "2366f927-9935-46aa-9b9d-bc5505f12834",
      "name": "When chat message received",
      "webhookId": "4d8258af-e64c-4235-9a24-6e90f5596775",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "You are a helpful assistant and speak like a cowboy."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        208,
        0
      ],
      "id": "8828d816-259f-4b65-a3b8-8c8ff25b73d7",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        32,
        208
      ],
      "id": "26891c88-aed5-444a-b545-a5ef9bdc3ad0",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "0h4kMjpTValhfJZv",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.4,
      "position": [
        176,
        208
      ],
      "id": "cadce2fb-f307-4e26-9423-51304618c03b",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc",
          "mode": "list",
          "cachedResultName": "stock-portfolio",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        320,
        320
      ],
      "id": "813a2455-535f-4d85-8460-fa65e119f72f",
      "name": "Get row(s) in sheet in Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "b7aCwM5d7t0oTzxp",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc",
          "mode": "list",
          "cachedResultName": "stock-portfolio",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "price": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('price', ``, 'string') }}",
            "stock": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('stock__using_to_match_', ``, 'string') }}"
          },
          "matchingColumns": [
            "stock"
          ],
          "schema": [
            {
              "id": "stock",
              "displayName": "stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "quantity",
              "displayName": "quantity",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        768,
        224
      ],
      "id": "c69bceb2-b6bc-45f1-84ca-9eaede574fae",
      "name": "Update row in sheet in Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "b7aCwM5d7t0oTzxp",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "symbols": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Ticker', ``, 'string') }}",
        "filters": {
          "latest": true
        }
      },
      "type": "n8n-nodes-base.marketstackTool",
      "typeVersion": 1,
      "position": [
        496,
        320
      ],
      "id": "ca2c2a3b-6f8b-468f-b3cd-11cfe15ab295",
      "name": "Get many EoD data in Marketstack",
      "credentials": {
        "marketstackApi": {
          "id": "uykspUJ9pFnekPFQ",
          "name": "Marketstack account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc",
          "mode": "list",
          "cachedResultName": "stock-portfolio",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dYZQzF6VPY9X47VCywv4MT1Wo9OpT39vhSBvpNn_Mbc/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "stock": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('stock', ``, 'string') }}",
            "price": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('price', ``, 'string') }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "stock",
              "displayName": "stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "quantity",
              "displayName": "quantity",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        672,
        352
      ],
      "id": "8340b44b-fab8-41da-a5a6-9f81d18251fa",
      "name": "Append row in sheet in Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "b7aCwM5d7t0oTzxp",
          "name": "Google Sheets account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update row in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get many EoD data in Marketstack": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Append row in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "f5f3fcf5-c9e2-4cff-876f-a6619e88e49a",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "d7f40ac67c918c6b77c1db2f31baa37e504a493b4a22e372f2a513b7bf0ca5a9"
  },
  "nodeGroups": [],
  "id": "6bsOs8ssUv4uxhna",
  "tags": []
}
Enter fullscreen mode Exit fullscreen mode

If you give it a prompt like this:

Please get all the stocks and update the sheet, leave the quantity empty and do it at max for the first 10 distinct stocks. Also make sure to keep the GOOGL, APPL, and TSLA.

Is going to just add 10 new rows to the Google Sheet, while my intention was more like 10 in total. And also it did NOT use the Marketstack API to fetch their latest stock price!

So yeah 🥲🥹.

Top comments (0)