This workflow automates code related tasks using OpenAI’s GPT-4o-mini with a code tool agent for processing queries like converting JSON arrays to strings. Key nodes include Manual Trigger (initiates workflow), Input Validation (sets user_query), Validate Input (ensures query length ≥5 characters), Code Tool Agent (processes query with OpenAI), Array Merge Tool (merges string arrays), OpenAI Chat Model (handles AI processing), Format Success Response (returns response, intermediate_steps, tool_calls_count), and Format Validation Error (handles invalid inputs). It leverages OpenAI’s API for natural language and code processing, with the Array Merge Tool executing JavaScript to combine arrays.\n\nSetup Requirements and Configuration: Install n8n by downloading from n8n.io for self-hosting or sign up at cloud.n8n.io for cloud setup. Follow installation prompts or create a cloud account. Obtain an OpenAI API key from platform.openai.com: sign up, navigate to ‘API Keys,’ and generate a key. In n8n, import the JSON workflow. Configure the OpenAI Chat Model node by adding your API key under ‘Credentials’ > ‘OpenAI API’ in n8n’s interface. Replace the Manual Trigger with a Webhook Trigger for automation: set the path to ‘code-tool-agent,’ configure for POST requests, and optionally enable header authentication with a secure key. Ensure sufficient server resources for cloud or self-hosted setups to handle API requests.\n\nTesting and Deployment Steps: Test by sending a POST request to the Webhook URL using Postman. Example JSON: {'user_query': 'Convert this JSON array to a single string: [\"This\", \"Is\", \"An\", \"Array!\"]'} with an authentication header if enabled. Alternatively, use Manual Trigger in n8n’s editor. The ‘Format Success Response’ node returns a 200 status with response, intermediate_steps, and tool_calls_count, or ‘Format Validation Error’ (400 status) for queries shorter than 5 characters. Monitor logs for errors like ‘Invalid API key’ or ‘Tool execution failed,’ and verify credentials or input length if issues arise. Activate the workflow in n8n for deployment. Validate output to ensure response matches the query (e.g., ‘This, Is, An, Array!’) and tool_calls_count is accurate.
$6.99
Workflow steps: 8
Integrated apps: manualTrigger, set, if