How to Call n8n Workflows Through Tools
n8n is a powerful workflow automation tool that can be used to create various automated tasks. ConsoleX supports calling n8n workflows through tools to extend the capabilities of large models, enabling them to complete more complex tasks. n8n workflows can be created and used through the official cloud service or self-hosted methods.
Basic Process
- Create a workflow in n8n triggered by a Webhook Trigger module, and create a Response to webhook module to return results in JSON format.
- Add a tool with interface type n8n in ConsoleX, and set up the tool's description, Webhook URL, and required API Key for calling.
- When initiating a conversation, add the created tool to the conversation for the large model to autonomously call and return results.
Detailed Steps
Configure workflow calling method and parameters in n8n
Workflows created in n8n need to be triggered by a Webhook Trigger module and finally return a Response to webhook module. The return content of the Response to webhook module is recommended to be set to JSON format, and the object content in the Response Body will be used as the tool's return result.
Configure workflow auth verification in n8n (optional)
If you need to set up auth token verification for workflows, you need to first set the verification rules in the Authorization module of the n8n workflow's Webhook Trigger to Header Auth. Next, create a Credential for Header Auth with the Credential name set to: Authorization, and the Credential value set to: Bearer <your_auth_token>
, where <your_auth_token>
is the workflow auth token you specify arbitrarily.
Configure workflow return content in n8n
Workflows created in n8n need to return a Response to webhook module, and the return content of the Response to webhook module should be set to JSON format. The object content in the Response Body will be used as the tool's return result.
Create a tool with interface type n8n in ConsoleX
When creating a tool, first you need to input the tool's JSON Schema description to be consistent with the input parameters received by the workflow. The specific format of the description follows the standard OpenAI tool description format. You can refer to examples or use AI assistance to generate.
Next, you need to enable tool calling. The tool's calling method needs to select either GET or POST method, depending on how the Webhook Trigger module in the n8n workflow receives parameters. The tool's interface type needs to be set to n8n.
The tool's function interface URL needs to be consistent with the Webhook URL in n8n. The Test URL in n8n can be used to test workflow execution during development but can only be called once. After the workflow is published, the Production URL can be used for multiple calls.
If auth token verification is set up in the n8n workflow, you need to input the auth token into the tool's API Key.
Select one of the tool's reply methods according to the situation, then click Save. The tool corresponding to the n8n workflow is created.
Example Workflow
The following is an n8n example workflow for weather forecasting. You can right-click to save it locally and then import it into n8n's workspace for reference.