Skip to content

Let AI specify tool parameters with $fromAI()#

When configuring app node tools connected to the Tools Agent, you can use the $fromAI() function to dynamically populate parameter values using the AI model. The AI model will fill in appropriate data given the context from the task and information from other connected tools.

How the $fromAI() function works#

The $fromAI() function uses AI to dynamically fill in parameters for tools connected to the Tools AI agent. You can use the $fromAI() function in expressions within app nodes (like Gmail, Notion, or Slack) connected to a tool node.

Only for the Node Tools

The $fromAI() function is only available for app node tools connected to the Tools Agent. It isn't possible to use the $fromAI() function with the Call n8n Workflow, Code, HTTP Request, or other cluster sub-nodes.

To use the $fromAI() function, call it with the required key parameter:

1
{{ $fromAI('email') }}

The key parameter and other arguments to the $fromAI() function aren't references to existing values. Instead, think of these arguments as hints that the AI model will use to populate the right data.

For instance, if you choose a key called email, the AI Model will look for an email address in its context, other tools, and input data. In chat workflows, it may ask the user for an email address if it can't find one elsewhere. You can optionally pass other parameters like description to give extra context to the AI model.

Parameters#

The $fromAI() function accepts the following parameters:

Parameter Type Required? Description
key string ✅ A string representing the key or name of the argument. This must be between 1 and 64 characters in length and can only contain lowercase letters, uppercase letters, numbers, underscores, and hyphens.
description string ❌ A string describing the argument.
type string ❌ A string specifying the data type. Can be string, number, boolean, or json (defaults to string).
defaultValue any ❌ The default value to use for the argument.

Examples#

As an example, you could use the following $fromAI() expression to dynamically populate a field with a name:

1
$fromAI("name", "The commenter's name", "string", "Jane Doe")

If you don't need the optional parameters, you could simplify this as:

1
$fromAI("name")

To dynamically populate the number of items you have in stock, you could use a $fromAI() expression like this:

1
$fromAI("numItemsInStock", "Number of items in stock", "number", 5)

Templates#

You can see the $fromAI() function in action in the following templates: