Overview
This node implements an enhanced AI agent designed to perform a wide range of tasks by leveraging structured prompts and intelligent tool management. It allows users to create specialized AI agents tailored to different roles such as conversational agents, task solvers, data analysts, or creative writers. The node integrates with an external AI language model and optionally connected tools to execute complex workflows.
Common scenarios where this node is beneficial include:
- Building chatbots or conversational interfaces that require contextual understanding.
- Automating specific task-solving processes with step-by-step instructions.
- Analyzing data and generating insights based on user-defined objectives.
- Creating creative content like stories, marketing copy, or other written materials.
Practical examples:
- A marketing expert agent analyzing social media engagement metrics and providing optimization recommendations.
- A data analyst agent interpreting sales data and suggesting actionable insights.
- A creative writer agent generating story ideas based on given themes and constraints.
Properties
| Name | Meaning |
|---|---|
| Agent Type | Type of AI agent to create. Options: Conversational Agent, Task Solver, Data Analyst, Creative Writer. |
| Role and Expertise | Defines the agent's role and specialized knowledge (e.g., "a marketing expert specialized in social media analytics"). This is a required field. |
| Objective | Clear statement of what the agent should accomplish (e.g., "analyze social media engagement metrics and provide optimization recommendations"). This is a required field. |
| Instructions | Detailed step-by-step instructions for the agent. Multiple instructions can be provided to guide the agent’s behavior precisely. |
| Output Format | Expected response format specified as a JSON schema. Defines how the agent's output should be structured. |
| Constraints | Limitations and restrictions for the agent to follow during execution. Multiple constraints can be added. |
| Examples | Reference input-output examples to guide the agent’s responses. Contains one example with input and expected output. |
| Advanced Options | Collection of advanced parameters controlling generation behavior and cost management: - Max Tokens: Maximum tokens to generate. - Temperature: Controls randomness (0 deterministic, 1 creative). - Top P: Diversity control. - Frequency Penalty: Reduces token repetition. - Presence Penalty: Encourages new topics. - Enable Cost Estimation: Enables cost tracking and safety limits. - Max Credits per Request: Safety limit on credits spent. - Prefer Cost Efficiency: Suggests cost-effective models and parameters. |
| Tool Management | Configuration for managing external tools: - Enable Tool Validation: Validates tools before use. - Max Tool Retries: Number of retries for failed tools. - Enable Tool Caching: Caches tool results to reduce API calls. |
Output
The node outputs a JSON object containing the AI agent's response structured according to the specified Output Format JSON schema. Additionally, it includes metadata about the execution such as:
- Credits used (actual and estimated).
- Token usage (input, output, total).
- Cost in USD and profit margin.
- Model provider and model name.
- Execution time in milliseconds.
If cost estimation is enabled, detailed cost metrics are included in the output metadata.
The node does not output binary data.
Dependencies
- Requires connection to an external AI language model node compatible with OpenAI, Anthropic, or similar large language models.
- Requires an API key credential for the external AI service (configured in n8n credentials).
- Optionally connects to external tools (via the "Tools" input) which must be validated and managed according to configured tool management options.
- Uses internal utility functions for prompt building, validation, and API requests to the AI service endpoint
/agents/enhanced.
Troubleshooting
- No AI Language Model Connected: If no AI language model node is connected to the "Model" input, the node throws an error instructing to connect a compatible LLM node.
- Agent Output Format Mismatch: If the agent's output does not conform to the expected JSON schema defined in
Output Format, an error is thrown indicating the mismatch. - Quota Exceeded (HTTP 429): Indicates the API quota has been exceeded. The error message provides estimated credit consumption and suggestions. Users should check their API usage limits and possibly upgrade their plan.
- Insufficient Credits (HTTP 402): Indicates insufficient credits to perform the operation. The error message shows cost estimate and current balance. Users need to add credits or reduce request complexity.
- Service Unavailable (HTTP 503): Temporary unavailability of the AI service. Retry after some time.
- API Errors (HTTP 4xx/5xx): General API errors return messages describing the issue. Check API keys, network connectivity, and request parameters.
- Connection Errors: Network or connectivity issues result in connection error messages. Verify internet access and proxy settings if applicable.
The node supports "Continue On Fail" mode to allow processing subsequent items even if some fail.