fromAI in n8n: What $fromAI() Does, With Examples
Ready to automate?
Browse 5,000+ copy-paste n8n workflow templates.
fromAI, written $fromAI() in an expression, is an n8n function that lets an AI Agent decide a tool's parameter values at runtime instead of you hardcoding them. You put {{ $fromAI('key', 'description', 'type') }} in a field of a node attached to the AI Agent as a tool, and the model fills that field in each time it calls the tool.
That solves a common wall in agent builds: without it, the tools you attach to the AI Agent node send the same static values on every call, no matter what the agent reasoned about. With $fromAI(), a rigid HTTP Request or service node adapts to each piece of incoming data.
This guide covers the syntax, when to use it, and a concrete request classifier you can build today. If you would rather start from a working agent, browse the AI agent templates and adapt one as you read.
What $fromAI() Does
$fromAI() is an expression function available inside nodes connected as tools to n8n's AI Agent node. When the agent decides to call that tool, it fills in the $fromAI() placeholders based on its understanding of the current task.
The syntax is:
{{ $fromAI('parameterKey', 'A description the AI uses to understand this field', 'type') }}
The arguments are:
- key, an internal name for the parameter (no spaces, lowercase recommended)
- description, plain-language text the AI reads to understand what to put here. Write it the way you'd explain the field to a new team member.
- type, one of
string,number,boolean, orjson. Defaults tostringif omitted. - defaultValue (optional fourth argument), the value to use if the model does not supply one.
Only the key is required. A bare {{ $fromAI('search_query') }} works, but the model then has only the key name to go on, so add a description whenever the value is not obvious.
At runtime, n8n passes the key, description, and type to the AI model as part of the tool schema. The model evaluates the current context, the incoming data, the system prompt, prior reasoning, and fills in an appropriate value.
When to Use $fromAI() vs. Static Parameters
Use $fromAI() when:
- The field value should change depending on what the agent is processing
- You want the AI to extract a specific piece of information from unstructured input
- The tool needs to behave differently for different categories of data
Use a static parameter (a regular expression or hardcoded value) when:
- The value is always the same regardless of input
- You don't want the AI to deviate from a fixed format
- The field is an internal identifier like an API key or base URL
A common pattern is to mix both: static values for credentials and base URLs, $fromAI() for the body fields that should vary.
Example Workflow: AI-Powered Request Classifier
Here's a practical workflow that demonstrates $fromAI() in action. The goal: receive incoming requests from any source, let an AI agent extract the relevant fields, and route each item to the right destination.
Step 1: Webhook Trigger
Add a Webhook Trigger node and set the HTTP method to POST. This is the entry point, it can receive data from a form submission, an internal app, a Zapier webhook, or any other source that can send HTTP. Set the path to something memorable like /classify-request.
Step 2: AI Agent Node
Add an AI Agent node and connect it to the Webhook Trigger. In the system prompt, define what the agent should do:
You receive incoming requests and must classify each one. Based on the content, call the appropriate tool: use the CreateTask tool for requests that describe a bug, feature, or technical issue; use the LogEntry tool for general inquiries, feedback, or anything else. Fill in all required fields accurately.
Connect your preferred language model (OpenAI, Anthropic, or any compatible provider) in the Chat Model slot. Leave memory off for stateless, single-pass classification.
Step 3: HTTP Request Node as "CreateTask" Tool
Add an HTTP Request node. In the AI Agent's Tools section, attach it as a tool named CreateTask with a description like "Creates a task for bugs or feature requests."
In the HTTP Request node's body, use $fromAI() for each field the AI should fill in:
{
"title": "{{ $fromAI('task_title', 'A short, descriptive title for the task', 'string') }}",
"priority": "{{ $fromAI('priority', 'Priority level: low, medium, or high', 'string') }}",
"description": "{{ $fromAI('description', 'Full context for the task, including steps to reproduce if it is a bug', 'string') }}"
}
Point the URL at your project management tool's API endpoint, Linear, Jira, Asana, or any service with a REST API.
Step 4: HTTP Request Node as "LogEntry" Tool
Add a second HTTP Request node as a second tool named LogEntry. This handles general inquiries, feedback, or anything that doesn't fit the task category. Its body uses:
{
"category": "{{ $fromAI('category', 'One of: feedback, question, other', 'string') }}",
"summary": "{{ $fromAI('summary', 'One sentence summarizing the request', 'string') }}",
"raw_content": "{{ $fromAI('raw_content', 'The full original text of the request', 'string') }}"
}
Point this at an Airtable endpoint, a Notion API call, a Google Sheets row append, or any datastore you prefer.
Step 5: Respond to Webhook
Add a Respond to Webhook node at the end. Return a simple confirmation JSON so the calling system knows the request was received and processed.
How the Agent Decides
When the workflow runs, the AI Agent reads the full webhook payload, evaluates which tool to call, fills in all the $fromAI() fields from the content, and calls the tool. You don't write any classification logic, the model handles it based on the tool descriptions and system prompt.
If the input is ambiguous, the agent can call multiple tools in sequence within a single execution.
Tips for Writing Good $fromAI() Descriptions
The description argument is the most important part. The model uses it literally when deciding what value to generate.
Be specific about format. Instead of 'The priority', write 'Priority level: must be one of low, medium, or high'. Constrained options reduce hallucination.
Match the description to the data type. If the type is number, the description should make clear you expect a numeric value: 'Number of items affected, as an integer'.
Use json for structured objects. If a tool needs a nested object, set the type to json and describe the expected schema in the description field: 'A JSON object with keys "name" (string) and "email" (string)'.
Keep descriptions short. One clear sentence with the allowed values is usually enough; long descriptions are harder for the model to follow.
Combining $fromAI() with Other n8n Features
$fromAI() works in nodes attached to the agent as tools, such as HTTP Request and the built-in service nodes (Google Sheets, Slack, Gmail and others). It also composes well with:
- IF node after the agent, for additional conditional logic after classification
- Sub-workflow tools, call another n8n workflow as a tool, with
$fromAI()filling the input fields of that workflow - Error handling, use the node's On Error setting or an error workflow so an API failure does not silently break the agent run (see handling n8n errors with retry logic and alerts)
Finding Pre-Built AI Agent Templates
If you want a head start, n8nresources.dev has a growing collection of ready-to-copy AI agent workflows in the template library. The AI agents use case collection covers common patterns including classifiers, summarizers, and multi-tool routing workflows.
If you call OpenAI directly rather than through an agent, the n8n OpenAI workflow patterns guide shows how function calling maps onto n8n nodes, and the AI ticket routing workflow with Zendesk, OpenAI and Slack is a fuller example of the classify-and-route idea above.
For broader context on where AI agent automation fits into a modern workflow stack, the AI workflow automation section covers the category in more depth.
$fromAI() is one of the more useful primitives n8n exposes for AI-powered workflows. Once you understand how the description field shapes the model's output, you can wire up tools that handle a surprisingly wide range of inputs without writing classification logic by hand.
Enjoyed this article?
Share it with others who might find it useful