Getting AI agent to send data to a workflow tool

Hey, I’m trying to wrap my head around these AI agents.

I am using the ReAct agent to identify a list of steps and associated tools to use to carry out a request.

But I need to pass data to those tools. Data which has been specified by the AI - not hard-coded by me or the other nodes.

So I know there’s the Workflow Values in the tool parameters, but those require me to specify the values. However AI is specifying the values.

So I’ve tried to get it to follow a JSON schema and pass JSON to the workflow, but doing so throws an error “ERROR: Single ‘}’ in template.”.

I’ve also tried using the Structured Output Parser, but that only affects the final output, rather than the tool/workflow input.

What am I missing?

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:

Hey @James_Pardoe,

Have you taken a look at Tutorial: Build an AI workflow in n8n | n8n Docs to see if it helps, I think it uses the workflow tool option and an agent so it could be a solid starting point.

We do also have a collection of 34 AI workflow templates here: n8n workflow templates which could help.

Hi @Jon - thanks for getting back to me on this.

Yes I tried the tutorial but it uses a hard-coded parameter which is sent to the workflow:

What I am trying to do is use parameters that are generated by AI and send those to the workflow.

In one of the template workflows I found they used this value to reference the chat input: {{ $(‘Chat Trigger’).item.json.chatInput }}

Is there a similar way to reference the AI output rather than the chat input?

Hey @James_Pardoe,

Ah… Do you have an example workflow you can share? I would need to have a play with it to see if it is possible.

Yeah sure! Here’s the example where I am specifying JSON schema instructions in the tool, and it throws an error “ERROR: Single ‘}’ in template.”:

Without specifying the JSON, this is the workflow, which throws a different error which I can’t quite understand:

Here’s the Slack tool being called:

To add some context to the above, a request is sent to the AI such as “write a weekly summary for the client Acme Inc for work done this week”

Its task is to go to various tools like Slack, gather all the conversations for the given client (in the client’s Slack channel), and identify everything that was discussed to produce a summary of the work carried out that week.

In order for this to work, we need to provide specific parameters to the Slack tool, in order for the tool to know what data to find and send back.

The current iteration of the AI Agent seems to be able to send hard-coded parameters to tools, but the AI itself is creating those parameters. And I can’t seem to find a way to include those params when requesting data from the tool.

Any thoughts on the above? For now I’ve resorted to building my own AI Agent through manual nodes.

@oleg any thoughts on this one?

So I copied your workflow and removed the instructions on how to format the JSON from the Custom Tool (" {
“method”: “POST or GET”,
“channelName”: “Channel Name”,
“message”: “Message Content”,
“threadId”: “Optional Thread Identifier for Replies”,
“startDate”: {
“type”: “string”,
“format”: “date-time”,
“description”: “Optional start date and time for filtering messages”
“endDate”: {
“type”: “string”,
“format”: “date-time”,
“description”: “Optional end date and time for filtering messages”

And no longer got this error. I think this is redundant, as you have the output parser with the same instructions? It’s possible that because of this, the agent was outputting messed up JSON?

Thanks @Mark_Da_Marketer - if I’m not mistaken, the output parser controls how the agent outputs the final data, whereas the instructions I gave the AI control how the AI sends data to the individual tools. In the big picture there will be multiple tools, each with their own data input requirements.

So the two are quite different and both are needed. Unless I’ve misunderstood something?

Honestly, the documentation for the Langchain nodes are so sparse, that I am not quite sure. I do know that when the output instructions were removed from the tool description, the error didn’t occur - so that seems to be where the issue is.

Thanks for your help in identifying where the issue lies @Mark_Da_Marketer

@oleg would you be able to take a look for me? We appear to be hitting a brick wall.

@James_Pardoe As others pointed out, the structure output parser should only be used for the final output. But I would advise you to use a simple chain just for parsing the output since adding the formatting instructions can sometimes confuse the LLM.

Regarding the tools calling — agent can only provide a single dynamic argument to the tool, so you need to ask it to pass a stringified object if you want it to provide more. Here’s an example:

This would correctly pass the arguments to the tool as stringified JSON:

Regarding the ERROR: Single ‘}’ in the template. error you’ve mentioned, that seems to be due to some clashes in the Langchain expression language; I’ll have a closer look at what’s causing it. But in the meantime, you can get around this by escaping the curly brackets using double-curlies, which is what I did in the workflow above.

1 Like

Ah thank you so much! This makes sense and I look forward to running with it!

1 Like

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