A workflow creates another workflow with an ai agent but doesnt set the parameters of Ai agent properly

Hello all

I am desperatly looking for some help here.

I have a workflow which creates another workflow with an ai agent. Everything works until the ai agents prompt settings are not set properly. I want that the ai agent gets its prompt from the first node(webhook), So it should be like in the picture. When I use this:

“promptType”: “define”,
“Prompt”: “={{ $json.body.chatInput }}”,

it sets the prompt type correctly but doesnt get the {{ $json.body.chatInput }} into the prompt type. Instead of “Prompt” I tried other things like:“text“ “chatInput“ etc. everything. its not working.

Anybody might have an idea? Highly appreciated! Thanks in advance

Gr

x

1 Like

hey, yeah this is a common issue when you’re programmatically creating workflows. the problem is how n8n serializes the AI Agent node settings.

when you’re building the workflow JSON, the prompt field needs to be in the `parameters` object, not at the root level. also, the expression syntax changes depending on where it’s coming from.

try this structure instead:

```json

{

“nodes”: [

{

  "parameters": {

    "promptType": "define",

    "text": "={{ $json.body.chatInput }}"

  },

  "type": "n8n-nodes-ai.Agent",

  "name": "AI Agent"

}

]

}

```

key differences:

1. use `“text”` instead of `“Prompt”` - thats the actual parameter name in the Agent node

2. make sure its nested under `parameters`

3. the `={{ }}` expression should work from there since its referencing the webhook input

if youre still not getting the value populated, check:

- is the webhook node actually outputting `body.chatInput`? verify the actual data structure coming in

- sometimes you need to reference it as `$json.body[0].chatInput` or just `$json.chatInput` depending on how the webhook formats it

- if building this in a code node or script, make sure youre not double-escaping the quotes

also double-check the AI Agent node docs here if the parameter name changed: https://docs.n8n.io/integrations/builtin/cluster-nodes/n8n-nodes-base.agent/

lmk if that works or what the actual webhook output looks like and we can debug from there