How to create a key for AI Agent output to a tool

n8n 1.66.0 self hosted docker (sqlite)

In my AI Agent prompt, I ask a question, then say: Output the result in the format: {“ai-summary”: “<output_here>”}

In the attached Google Sheets tool, I access the output with: {{ $fromAI("ai-summary") }} so I can write that to a Google Sheets row.

I’m getting mixed results. Is that the proper way to do it?

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @RichardC ,

You might get better results if you tweak your prompt to be a bit clearer.
Something like:

Generate a concise summary of the following question: [question]

Format the output as follows:
{ "ai-summary": "<output_here>" }

Are you consistently getting the output from the AI agent in the format you requested?

It would be easier to advise you if we could see exactly what you’re working with. Think you could share your workflow and the output you’re currently getting? As well as what results you’re seeing.

You can share a wf by following these steps

Select your nodes in the UI and press Ctrl+c or cmd+c, like shown here: Export and import workflows | n8n Docs.
Then select the </> option in the forum textbox and paste the wf in the middle of the backticks by pressing Ctrl+v or cmd+v

1 Like

Thanks for the reply. I really just wanted to know the proper way to apply a key to the output of an AI Agent. It seems this is the answer.

Format the output as follows:
{ "ai-summary": "<output_here>" }

I wanted to confirm that in case the output of the AI Agent was assigned some key automagically. It might be worth mentioning this in the docs (unless I missed it). I would imagine anyone using AI Agent tools would need to know this.

Some feedback: rather than use the AI Agent, I ended up creating a manual loop and sending the output to a stand-alone node rather than to a tool within the AI Agent. I’m sure it’s me not you but I had a hard time debugging what the tool was doing inside the AI Agent.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.