AI Agent using google sheets tool

Ahoi everyone,

I’m currently exploring how the AI Agent works and want to create an Agent that can access our demo environment via an MCP server to extract information and write it to an google sheet

The main idea is to create an Agent that can create invoices simply from chatting.

It starts with the chat message:
prepare the invoice for all my customers that have active subscriptions

The final response is the following:
I have prepared the invoices for customers with active subscriptions. Here are the details:

Customer: Technocompany Test (Customer ID: 291154)

** Subscription: M365 Business Std CHAR Trial (25 min), Licenses: 25, Price per License: 0 EUR, Total Price: 0 EUR*
** Subscription: Exchange Online (Plan 1) GOV, Licenses: 1, Price per License: 10 EUR, Total Price: 10 EUR*

Customer: Its Hammertime - Handwerkervermittlung (testing) (Customer ID: 291155)

** Subscription: M365 Business Basic (no Teams), Licenses: 2, Price per License: 10 EUR, Total Price: 20 EUR*
** Subscription: M365 Business Basic, Licenses: 3, Price per License: 80.64 EUR, Total Price: 241.92 EUR*

If you want invoices for more customers or need any other assistance, please let me know.

Describe the problem/error/question

The AI Agent executes the Google Sheets tool to append a row 4 times, and the same row is always overwritten.
I can see that each subscription is written to the row in google sheets, unfortunately it’s always overwritten with the last value:

customerId customerOrganization skuDisplayName subscriptionTotalLicenses price sum
291155 Its Hammertime - Handwerkervermittlung (testing) M365 Business Basic (no Teams) 2 10

When I click through each execution of the tool i see:

[
  {
    "response": [
      {
        "customerOrganization": "Technocompany Test",
        "customerId": "291154",
        "skuDisplayName": "M365 Business Std CHAR Trial (25 min)",
        "price": "0",
        "subscriptionTotalLicenses": "25",
        "sum": "0"
      }
    ]
  }
]
[
  {
    "response": [
      {
        "customerOrganization": "Technocompany Test",
        "customerId": "291154",
        "skuDisplayName": "Exchange Online (Plan 1) GOV",
        "price": "10",
        "subscriptionTotalLicenses": "1",
        "sum": "10"
      }
    ]
  }
]
[
  {
    "response": [
      {
        "customerOrganization": "Its Hammertime - Handwerkervermittlung (testing)",
        "customerId": "291155",
        "skuDisplayName": "M365 Business Basic",
        "price": "80.64",
        "subscriptionTotalLicenses": "3",
        "sum": "241.92"
      }
    ]
  }
]
[
  {
    "response": [
      {
        "customerOrganization": "Its Hammertime - Handwerkervermittlung (testing)",
        "customerId": "291155",
        "skuDisplayName": "M365 Business Basic (no Teams)",
        "price": "10",
        "subscriptionTotalLicenses": "2",
        "sum": "20"
      }
    ]
  }
]

What is the error message (if any)?

The Google Sheets tool is executed 4 times with dirrent values every time.
Unfortunately in Google Sheets the next empty row is always overwritten

Please share your workflow

[
  {
    "output": "The invoice has been prepared for your customers with active subscriptions. Here are the details:\n\nCustomer ID: 291154 (Technocompany Test)\n- Subscription: M365 Business Std CHAR Trial (25 min), Price: 0 EUR, Licenses: 25, Total: 0 EUR\n- Subscription: Exchange Online (Plan 1) GOV, Price: 10 EUR, Licenses: 1, Total: 10 EUR\n\nCustomer ID: 291155 (Its Hammertime - Handwerkervermittlung (testing))\n- Subscription: M365 Business Basic (no Teams), Price: 10 EUR, Licenses: 2, Total: 20 EUR\n- Subscription: M365 Business Basic, Price: 80.64 EUR, Licenses: 3, Total: 241.92 EUR\n\nIf you need invoices for other customers or additional assistance, please let me know."
  }
]

Information on your n8n setup

  • n8n version: 1.95.3
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker):Docker
  • Operating system:Linux - Self Hosted

Do you know how to fix this issue?

BR Maximilian

Ahoi,

topic can be closed.
I managed to format the output of the agent and run the Google Sheets node independently with a Code node before.

Also had to tweak the system message of the AI Agent.
I think the issue with using Google Sheets as a tool is, that the AI Agent is way to fast in adding rows to the Google Sheet

Cheers

Hi @m4xwe11o, you got it! The tool is being called in parallel, and is not set-up to handle that parallelism yet. This is not something that happens with “normal” nodes in n8n, so while in some cases it’s useful, in other cases it can be a problem, as you note here. We’re aware of the issue and solving it requires a bit more changes under the hood.

One way of solving this is, indeed, using a node that executes after the agent. You get the agent to output the requested fields by using structured output, and use a different node to insert the rows into your sheet. You could, of course, use another agent / LLM chain to generate a nice message at the end if you want.
Another thing that might help is asking it to execute tools one by one, but I haven’t tried whether this actually works reliably.