Understanding the Need
Imagine that you want to automate the interaction between a user and an AI agent. For example, upon receiving a message from a customer via WhatsApp, you want this message to be processed by a Tess AI agent, which will respond intelligently to the customer. To achieve this, we need to create a flow where the user's message is sent to the agent, and the agent's response is returned to the user.
Step-by-Step Explanation
Getting Started with N8N
Open N8N and create a new workflow. This will serve as the foundation where we will build our automation.
N8N works with 'nodes,' which represent actions or services. Each node can receive, process, or send data, and you can connect them to create complex flows.
Adding the HTTP Request Node
In the N8N search panel, type "HTTP" to find the "HTTP Request" node.
Add this node to your flow. This node will be responsible for sending a request to Tess AI's API to trigger the agent.
Configuring the HTTP Request
Reference to Tess AI Documentation:
Access the Tess AI documentation and navigate to the section explaining how to "Execute an Agent" via API.
There, you'll find examples of requests and details about the required parameters.
Importing Configurations:
For convenience, you can copy a configuration example from the documentation and paste it into N8N.
Inside the "HTTP Request" node, clear any existing configurations and paste the pre-configured setup you obtained.
Understanding the Request Components:
URL: This is the Tess AI API endpoint where the request will be sent. It usually follows the format
https://api.tess.ai/agents/{agent_id}/execute
.Method: We'll use the
POST
method, as we will be sending data (the user's message) to be processed.Headers: We need an authorization header to authenticate our request. This is done using the API token provided by Tess AI.
Body: Here, we include the data that will be sent to the agent, such as the user's message, configuration parameters, etc.
Obtaining the Agent ID
Each agent created in Tess AI has a unique ID.
To obtain your agent's ID:
Go to the Tess AI platform and open the agent you created.
The ID usually appears in the agent's page URL. For example, if the URL is
https://app.tess.ai/agents/1034
, the ID is1034
.Copy this ID and replace it in the API endpoint in the N8N configuration.
Generating and Inserting the API Token
Generate the Token:
On the Tess AI platform, go to the "API Tokens" section.
Create a new token. Remember that this token is sensitive and must be kept secure.
After creating it, copy the token for immediate use.
Insert into the Authorization Header:
In N8N, in the "HTTP Request" node configuration, insert the token into the request headers.
The header should look like:
Authorization: Bearer {your_token_here}
.This will authenticate your request, allowing Tess AI to recognize and process it.
Personalizing the Message for the Agent
Understanding the Payload:
In the request body, you define the content of the message to be sent to the agent.
This includes the user's message and, depending on how your agent is configured, may include other parameters such as temperature, language model, etc.
Editing the Content:
In the body JSON, locate where
"content": "Hello there"
is defined.Replace
"Hello there"
with the variable containing the user's message.In N8N, you can use the expression functionality to insert dynamic variables obtained from other nodes (e.g., messages received via WhatsApp).
Example:
If you have a previous node capturing input messages (e.g., a node receiving WhatsApp messages), you can insert this variable into the
content
field.Click "Add Expression" or a similar option, and select the variable representing the user's message.
Removing Unnecessary Parameters
Simplifying the Configuration:
If you have predefined certain parameters for the agent (such as AI model, temperature, etc.), you don't need to send them in the request.
You can remove these parameters from the JSON to simplify.
Configuring the Wait Time for the Response
In the HTTP node configuration, adjust it so that the flow waits for the agent's response before proceeding.
This is usually done by setting the parameter
wait for execution
totrue
.This is important as we want the flow to receive the agent's response to process it or send it back to the user.
Testing the Flow
Running the Flow:
Save all configurations and run the flow in N8N.
You can send a test message to see if everything is working correctly.
Checking the Response:
In N8N, you will see the agent's response in the output of the HTTP Request node.
Ensure that the response makes sense and matches your expectations.
Troubleshooting:
If you don't receive a response or encounter an error, check:
Whether the token is correct and valid.
Whether the agent ID is correct.
Whether the JSON is well formatted.
Whether the user's message is being properly inserted.
Integrating with Other Services
Sending the Response to the User:
After receiving the agent's response, you can add it to the flow to be sent back to the user.
For example, if you're integrating with WhatsApp, you can add a node that sends the message back to the user via WhatsApp API!
Security Considerations and Best Practices
Protect Your Tokens:
Do not share your API tokens. They grant access to your agents and must be kept secure.
Avoid including them in public code or shared documentation.
Validate User Inputs:
Consider implementing validation or sanitization of user messages before sending them to the agent to avoid undesirable behavior.
Monitor Usage and Costs:
Depending on your plan with Tess AI, there may be limits or costs associated with agent usage.
Monitor your API calls and ensure they remain within your desired limits.
Conclusion
Integrating a Tess AI agent with N8N via HTTP requests allows you to create powerful solutions that combine workflow automation with artificial intelligence. Although it involves some technical steps, the combination of clear Tess AI documentation and N8N’s user-friendly interface makes the process easier.
By understanding not only the "how" but also the "why" of each step, you will be better prepared to adapt and expand your solution as needed, creating intelligent agents that interact effectively with your users or customers.
Tess AI Documentation: Always refer to the official documentation for up-to-date details on the API and available functionalities.