#How can i make conversational ai agent navigate to pages based on user query
1 messages · Page 1 of 1 (latest)
To make a Conversational AI agent navigate to pages based on user queries, you can utilize the external function calls feature in ElevenLabs' Conversational AI. This allows your agent to take actions in third-party apps or systems based on user input.
Here's a general approach:
-
Set up your Conversational AI agent with the necessary knowledge base and system prompts to understand user navigation requests.
-
Implement external function calls that can trigger page navigation based on the user's query. This could involve creating functions that map user intents to specific URLs or page identifiers.
-
In your agent's configuration, define the external functions that handle navigation. These functions would interpret the user's request and return the appropriate page or URL to navigate to.
-
When a user asks to navigate to a specific page, the AI agent will process the request, call the appropriate external function, and then use the returned information to guide the user to the correct page.
Remember to structure your system prompt and knowledge base to cover common navigation scenarios. This will help your agent better understand and respond to user queries about moving between pages.
If you need more specific guidance on implementing this feature, I recommend checking the Conversational AI documentation for detailed instructions on setting up external function calls and customizing your agent's behavior.
I need a deatiled example outine this
I also need to know how to implement this with client side so it can activly manage to navigate pages based on this function output
To create a Conversational AI agent that can navigate pages based on user queries and implement this functionality on the client side, you'll need to utilize the Conversational AI features provided by ElevenLabs. Here's a detailed outline of how you can achieve this:
-
Set up your Conversational AI agent:
- Create a new agent in the ElevenLabs platform
- Configure the agent's knowledge base with information about your website structure and content
-
Implement page navigation logic:
- Use the agent's natural language understanding to interpret user queries
- Create a mapping between user intents and corresponding page URLs
- Implement a function that returns the appropriate URL based on the user's query
-
Client-side integration:
- Set up a frontend application (e.g., using React, Vue, or vanilla JavaScript)
- Implement the ElevenLabs SDK for voice interaction
- Create a function to handle the agent's response and navigate to the appropriate page
Here's a basic example of how you might implement this in JavaScript:
// Function to handle user query and navigate
async function handleQueryAndNavigate(userQuery) {
try {
// Call the Conversational AI API with the user's query
const response = await callConversationalAI(userQuery);
// Extract the navigation intent from the response
const navigationIntent = extractNavigationIntent(response);
// Get the corresponding URL
const url = getURLFromIntent(navigationIntent);
// Navigate to the new page
window.location.href = url;
} catch (error) {
console.error('Error handling query:', error);
}
}
// Function to call the Conversational AI API
async function callConversationalAI(query) {
// Implement API call to ElevenLabs Conversational AI
// Return the agent's response
}
// Function to extract navigation intent from the AI response
function extractNavigationIntent(response) {
// Implement logic to parse the AI response and determine the navigation intent
// Return the intent (e.g., 'home', 'products', 'contact')
}
// Function to map intents to URLs
function getURLFromIntent(intent) {
const urlMap = {
home: '/',
products: '/products',
contact: '/contact',
// Add more mappings as needed
};
return urlMap[intent] || '/';
}
// Event listener for user input
document.getElementById('userInput').addEventListener('keypress', async (e) => {
if (e.key === 'Enter') {
const userQuery = e.target.value;
await handleQueryAndNavigate(userQuery);
}
});
To implement this with active page management on the client side, you could:
- Use a single-page application (SPA) framework like React or Vue.js
- Implement a router to handle page transitions without full page reloads
- Update the handleQueryAndNavigate function to use the router instead of directly changing window.location
Here's how you might modify the code for a React application using React Router:
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
function NavigationComponent() {
const [userInput, setUserInput] = useState('');
const navigate = useNavigate();
async function handleQueryAndNavigate(userQuery) {
try {
const response = await callConversationalAI(userQuery);
const navigationIntent = extractNavigationIntent(response);
const url = getURLFromIntent(navigationIntent);
navigate(url);
} catch (error) {
console.error('Error handling query:', error);
}
}
// ... other functions remain the same ...
return (
<div>
<input
type="text"
value={userInput}
onChange={(e) => setUserInput(e.target.value)}
onKeyPress={(e) => {
if (e.key === 'Enter') {
handleQueryAndNavigate(userInput);
}
}}
/>
</div>
);
}
This approach allows for seamless navigation within your application based on the Conversational AI agent's responses.
do i need to add any tools to the agent configuration
To enable a Conversational AI agent to navigate pages based on user queries, you will need to configure tools within the agent's setup. These tools allow the agent to interact with external APIs or perform specific actions dynamically during conversations. Here's a detailed outline:
Steps to Configure Page Navigation Based on User Queries
1. Define the Tool
You need to add a tool to the agent configuration that can handle navigation requests. This involves specifying the tool's purpose and parameters. For example:
- Name: Page Navigation Tool
- Description: Allows the agent to navigate to specific pages based on user input.
2. Set Up Parameters
Define the parameters the tool will use:
- Path Parameters: Include variables in the URL path, e.g.,
/navigate/{page}where{page}is dynamically replaced based on the user query. - Query Parameters: Add parameters like
?section=aboutto refine navigation. - Body Parameters: If the tool requires additional data, include it in the request body.
3. Update the System Prompt
Modify the agent's system prompt to specify:
- When the tool should be used (e.g., based on keywords like "go to" or "navigate").
- How the tool should handle responses (e.g., redirecting the user or providing a confirmation).
4. Client-Side Implementation
To actively manage page navigation on the client side:
- Use JavaScript to listen for the agent's output (e.g., a navigation command).
- Parse the output to extract the target page or section.
- Use
window.location.hrefor a similar method to navigate to the specified page.
Example JavaScript snippet:
function handleAgentResponse(response) {
const navigationCommand = response.navigationCommand; // Extracted from agent output
if (navigationCommand) {
window.location.href = navigationCommand.url; // Navigate to the target page
}
}
5. Test and Refine
Test the tool with various user queries to ensure it correctly interprets and executes navigation commands. Adjust the tool's configuration or system prompt as needed to improve accuracy.
Do You Need to Add Tools?
Yes, you need to add tools to the agent configuration to enable this functionality. Tools allow the agent to dynamically generate and execute navigation commands based on user input. For detailed guidance on tool configuration, refer to the documentation on tools.
If you need further assistance with implementation or have specific requirements, feel free to ask!
in this part do i add client tool or webhook teps to Configure Page Navigation Based on User Queries
1. Define the Tool
You need to add a tool to the agent configuration that can handle navigation requests. This involves specifying the tool's purpose and parameters. For example:
Name: Page Navigation Tool
Description: Allows the agent to navigate to specific pages based on user input.
2. Set Up Parameters
Define the parameters the tool will use:
Path Parameters: Include variables in the URL path, e.g., /navigate/{page} where {page} is dynamically replaced based on the user query.
Query Parameters: Add parameters like ?section=about to refine navigation.
Body Parameters: If the tool requires additional data, include it in the request body.
3. Update the System Prompt
Modify the agent's system prompt to specify:
When the tool should be used (e.g., based on keywords like "go to" or "navigate").
How the tool should handle responses (e.g., redirecting the user or providing a confirmation).
To implement a conversational AI agent that can navigate pages based on user queries, you'll need to set up a navigation tool and integrate it with your client-side application. Here's a detailed example of how to achieve this:
First, add a custom tool to your agent's configuration in the ElevenLabs dashboard:
{
"name": "navigate_page",
"description": "Navigates to a specific page based on user request",
"parameters": {
"type": "object",
"properties": {
"page": {
"type": "string",
"description": "The page to navigate to (e.g. 'home', 'about', 'contact')"
}
},
"required": ["page"]
}
}
Modify your agent's system prompt to include instructions for using the navigation tool:
You are a helpful assistant that can navigate users to different pages on our website. When a user asks to go to a specific page or section, use the navigate_page tool to direct them there. Always confirm the navigation action with the user before proceeding.
On the client-side, you'll need to handle the navigation tool's output. Here's an example using JavaScript and a simple routing system:
// Function to handle navigation
function handleNavigation(page) {
switch(page) {
case 'home':
window.location.href = '/';
break;
case 'about':
window.location.href = '/about';
break;
case 'contact':
window.location.href = '/contact';
break;
default:
console.log('Unknown page');
}
}
// Listen for messages from the AI agent
elevenlabsConvAI.on('message', (message) => {
if (message.tool === 'navigate_page') {
handleNavigation(message.parameters.page);
}
});
Use the ElevenLabs SDK to set up the conversation and handle responses:
import { ConversationalAI } from '@elevenlabs/conversational-ai';
const convAI = new ConversationalAI({
apiKey: 'YOUR_API_KEY',
agentId: 'YOUR_AGENT_ID'
});
convAI.on('message', (message) => {
if (message.tool === 'navigate_page') {
handleNavigation(message.parameters.page);
}
});
// Start the conversation
convAI.start();
Test your implementation with various user queries and refine as needed. For example:
User: "Can you take me to the about page?"
Agent: "Certainly! I'll navigate you to the about page. Is that okay?"
User: "Yes, please."
Agent: "Great, I'm taking you to the about page now."
(The page then changes to the about page)
Remember to handle cases where the requested page doesn't exist or when the user changes their mind about navigation.
This implementation uses a client-side tool rather than a webhook. If you need server-side logic for navigation, you could implement a webhook instead, but for most simple navigation tasks, a client-side tool should suffice.
By following these steps, your conversational AI agent should be able to navigate pages based on user queries, enhancing the interactive experience on your website.
How can i correctly fill the tool filed Parameters
Define the parameters that will be sent with the event.
Add param
Data type
object
Identifier
Required
Description
This field will be passed to the LLM and should describe in detail how to extract the data from the transcript.
Properties
Data type
string
Identifier
Required
Value Type
LLM Prompt
Description
Delete
Add property
To correctly fill the tool's parameter fields for configuring page navigation based on user queries, follow these steps:
1. Define the Main Parameter
-
Data Type:
object
This allows you to group multiple properties (like page name, section, etc.) into a single parameter. -
Identifier: Provide a unique name, such as
navigation_request. -
Required: Check this box if the parameter is mandatory for the tool to function.
-
Description: Write a detailed explanation for the LLM to understand what data to extract. For example:
"Extract the page name and any additional navigation details (e.g., section or query parameters) from the user's query."
2. Add Properties to the Object
Each property represents a specific piece of data the tool will use. Add the following:
Property 1: Page Name
- Data Type:
string - Identifier:
page_name - Required: Yes
- Value Type: LLM Prompt
- Description:
"Extract the name of the page the user wants to navigate to. For example, if the user says 'Go to the About page,' extract 'About' as the page name."
Property 2: Section (Optional)
- Data Type:
string - Identifier:
section - Required: No
- Value Type: LLM Prompt
- Description:
"Extract the specific section of the page the user wants to navigate to, if mentioned. For example, 'Go to the Contact section of the About page' should extract 'Contact' as the section."
Property 3: Query Parameters (Optional)
- Data Type:
string - Identifier:
query_params - Required: No
- Value Type: LLM Prompt
- Description:
"Extract any additional query parameters the user specifies, such as filters or sorting options. For example, 'Show me the latest news on the News page' should extract 'latest' as a query parameter."
3. Example Configuration
Here’s how the tool parameters might look:
Main Parameter
- Data Type:
object - Identifier:
navigation_request - Description:
"Extract navigation details from the user's query, including the page name, section, and any query parameters."
Properties
-
Page Name
- Data Type:
string - Identifier:
page_name - Description: "Extract the name of the page to navigate to."
- Data Type:
-
Section
- Data Type:
string - Identifier:
section - Description: "Extract the specific section of the page, if mentioned."
- Data Type:
-
Query Parameters
- Data Type:
string - Identifier:
query_params - Description: "Extract any additional query parameters, if specified."
- Data Type:
4. Update the System Prompt
In the system prompt, guide the LLM on when and how to use the tool. For example:
"If the user mentions navigation (e.g., 'Go to,' 'Navigate to,' or 'Take me to'), use the Page Navigation Tool to extract the page name, section, and query parameters. Respond with a confirmation or perform the navigation."
This setup ensures the tool can dynamically handle user queries and navigate accordingly.
I keep getting this error An error occurred
Invalid message received
after it navigate me to the page
The error "Invalid message received" typically indicates that the tool configuration or the parameters being sent to the agent are not properly defined or formatted. Here are steps to troubleshoot and correctly configure the tool for page navigation:
1. Check Tool Configuration
Ensure the tool is properly defined in the agent configuration:
- Name: Ensure the tool has a clear name, such as "Page Navigation Tool."
- Description: Clearly describe the tool's purpose, e.g., "Handles navigation requests based on user input."
2. Define Parameters Correctly
When filling the tool's parameters, ensure the following:
Data Type
- Use the correct data type for each parameter. For example:
- Object: If the parameter contains multiple properties.
- String: For simple text values like page names or URLs.
Identifier
- Provide a unique identifier for each parameter. For example:
pageNamefor the page to navigate to.sectionfor specific sections within a page.
Required
- Mark parameters as required only if they are essential for the tool to function. Optional parameters should not be marked as required.
Description
- Write a detailed description for each parameter to help the agent understand how to extract the data from the user query. For example:
"Extract the page name from the user query, such as 'home' or 'about.'"
Properties
If the parameter is an object, define its properties:
- Data Type: Specify the type of each property (e.g., string, number).
- Identifier: Provide a unique name for each property.
- Value Type: Specify how the value will be extracted (e.g., from the LLM prompt or user query).
- Description: Clearly describe the purpose of each property.
3. Update System Prompt
Ensure the agent's system prompt is configured to handle navigation requests:
- Specify when the tool should be triggered (e.g., based on keywords like "navigate to" or "go to").
- Include instructions for the agent to validate the navigation request and provide a confirmation message before redirecting.
4. Validate Navigation Logic
If the tool is navigating to a page, ensure the following:
- URL Format: Verify that the URL being generated is valid and matches the expected format.
- Dynamic Parameters: Ensure dynamic parameters (e.g.,
{page}) are being replaced correctly based on the user query. - Client-Side Integration: If the navigation is handled on the client side, ensure the tool's output is properly passed to the client-side script.
5. Handle Errors Gracefully
Add error handling to the tool configuration:
- If the tool encounters an invalid message, configure it to return a user-friendly error message.
- Include fallback logic to handle cases where navigation fails (e.g., "Sorry, I couldn't navigate to that page. Please try again.").
6. Test the Tool
Run tests to ensure the tool is functioning correctly:
- Test with different user queries to verify that the tool extracts the correct parameters.
- Check the browser console for errors during navigation.
If the issue persists, you may need to review the webhook or client-side integration to ensure the tool's output is being processed correctly.
Ok i will use one param can you show me examp;e
To configure a tool for page navigation with a single parameter, follow these steps:
1. Define the Tool
Set up the tool in the agent configuration with the following details:
- Name: Page Navigation Tool
- Description: Allows the agent to navigate to specific pages based on user input.
2. Add a Parameter
Define a single parameter that will be sent with the event. Here's an example:
Parameter Configuration:
- Data Type:
string - Identifier:
page - Required:
true - Description: Extract the page name or identifier from the user query to navigate to the correct page.
Example LLM Prompt:
Extract the page name or identifier from the user query. For example, if the user says "Go to the About page," extract "about."
3. Update the System Prompt
Modify the system prompt to guide the agent on when and how to use the tool. For example:
You are a virtual assistant capable of navigating to pages based on user input. When the user mentions "go to" or "navigate," use the Page Navigation Tool to redirect them to the specified page. Confirm the navigation before proceeding.
4. Handle Responses
Ensure the tool is configured to handle responses correctly. For example:
- Redirect the user to the extracted page.
- Provide a confirmation message like "Navigating to the About page."
Example Workflow:
- User query: "Navigate to the Contact page."
- Tool extracts
contactas thepageparameter. - The agent uses the tool to navigate to
/navigate/contact.
Troubleshooting the "Invalid Message Received" Error
If you're encountering this error:
- Verify the tool's configuration, especially the parameter setup.
- Ensure the extracted parameter matches the expected format (e.g., valid page names or identifiers).
- Check the system handling the navigation request to ensure it accepts the parameter and processes it correctly.
Test the setup thoroughly to ensure smooth navigation.
How can i add a custom tool in an agent?
I have added this in tool
{
"type": "webhook",
"name": "notify_webhook",
"description": "Sends a notification to a webhook with user details",
"url": "https://aiagents.app.n8n.cloud/webhook-test/7000752e-a7aa-4814-ac68-b567c748c3f8/bland-check-calendar",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
"body": {
"calendarId": calendarId,
"botId": agentHashId,
"calendarAccountId": calendarAccountId,
},
"api_schema": {
"type": "object",
"properties": {
"calendarId": {
"type": "string",
"description": "The ID of the calendar"
},
"botId": {
"type": "string",
"description": "The ID of the bot"
},
"calendarAccountId": {
"type": "string",
"description": "The calendar account ID"
}
},
"required": ["calendarId", "botId", "calendarAccountId"]
},
"dynamic_variables": {
"dynamic_variable_placeholders": {
"user_name": "John Doe"
}
},
"expects_response": false
}
but it is giving me 400 error