---
title: Let AI specify tool parameters
description: Understand how n8n's `$fromAI()` function works and how to use it to dynamically populate parameters for AI app tools, or use the built-in automation to complete them instead.
contentType: explanation
tags:
  - $fromAI
  - $fromAI()
  - fromAI
  - fromAI()
hide:
  - tags
---

# Let AI specify the tool parameters

When configuring [tools](/glossary.md#ai-tool) connected to the Tools Agent, many parameters can be filled in by the AI model itself. The AI model will use the context from the task and information from other connected tools to fill in the appropriate details.

There are two ways to do this, and you can switch between them.

## Let the model fill in the parameter

Each appropriate parameter field in the tool's editing dialog has an extra button at the end:

![image showing stars icon to the right of parameter field](/_images/advanced-ai/ai-stars.png)

On activating this button, the [AI Agent](/glossary.md#ai-agent) will fill in the expression for you, with no need for any further user input.
The field itself is filled in with a message indicating that the parameter has been defined automatically by the model.

If you want to define the parameter yourself, click on the 'X' in this box to revert to user-defined values. Note that the 'expression' field will now contain the expression generated by this feature, though you can now edit it further to add extra details as described in the following section.

/// warning 
Activating this feature will overwrite any manual definition you may have already added.
///

## Use the `$fromAI()` function 

The `$fromAI()` function uses AI to dynamically fill in parameters for tools connected to the [Tools AI agent](/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/tools-agent.md).

/// note | Only for tools
The `$fromAI()` function is only available for tools connected to the AI Agent node. The `$fromAI()` function doesn't work with the [Code](/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolcode.md) tool or with [other non-tool cluster sub-nodes](/integrations/builtin/cluster-nodes/sub-nodes/index.md).
///

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

```javascript
{{ $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:

<!-- vale off -->

| Parameter | Type | Required? | Description |
| --------- | ---- | --------- | ----------- |
| `key` | string | :white_check_mark: | 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 | :x: | A string describing the argument. |
| `type` | string | :x: | A string specifying the data type. Can be string, number, boolean, or json (defaults to string). |
| `defaultValue` | any | :x: | The default value to use for the argument. |

<!-- vale on -->

### Examples

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

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

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

```javascript
$fromAI("name")
```

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

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

If you only want to fill in parts of a field with a dynamic value from the model, you can use it in a normal expression as well. For example, if you want the model to fill out the `subject` parameter for an e-mail, but always pre-fix the generated value with the string 'Generated by AI:', you could use the following expression:

```javascript
Generated by AI: {{ $fromAI("subject") }}
```

### Templates

You can see the `$fromAI()` function in action in the following [templates](/glossary.md#template-n8n):

* [Angie, Personal AI Assistant with Telegram Voice and Text](https://n8n.io/workflows/2462-angie-personal-ai-assistant-with-telegram-voice-and-text/)
* [Automate Customer Support Issue Resolution using AI Text Classifier](https://n8n.io/workflows/2468-automate-customer-support-issue-resolution-using-ai-text-classifier/)
* [Scale Deal Flow with a Pitch Deck AI Vision, Chatbot and QDrant Vector Store](https://n8n.io/workflows/2464-scale-deal-flow-with-a-pitch-deck-ai-vision-chatbot-and-qdrant-vector-store/)
