#Hi, so I have a interview simulator app using the conversational AI Agent api, I want to integrate

1 messages · Page 1 of 1 (latest)

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl

To integrate your CV into the interview simulator app, you can use the Knowledge Base feature of the Conversational AI platform. The Knowledge Base allows you to provide additional information that the AI agent can reference during conversations. This would be ideal for storing detailed information like your CV, as it ensures the agent can access and use it effectively during the simulation.

Here’s how you can proceed:

  1. Upload Your CV to the Knowledge Base: You can upload your CV as a file or provide it as a link. Non-enterprise users are limited to 5 files or links, with a total size of up to 20MB and 300,000 characters.

  2. System Prompt for Context: While the Knowledge Base stores the detailed information, you can use the system prompt to guide the agent's behavior and instruct it to reference the CV when answering questions. For example, you could include a prompt like:
    "You are an interview simulator. Use the candidate's CV in the Knowledge Base to provide realistic and relevant interview questions and feedback."

This combination ensures that the agent behaves appropriately while having access to the detailed information in your CV. If you need more flexibility or higher limits, you might want to explore enterprise options.

atomic swan
#

so it's better to put it on the Knowledge base than in the prompt

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl

To integrate your CV effectively, using a knowledge base would generally be a better approach than embedding it directly into the prompt. By storing your CV in a knowledge base, you can ensure that the conversational AI retrieves relevant information dynamically during the interaction, rather than relying on a static prompt. This allows for more flexibility and scalability, especially if you plan to update or expand the CV content over time.

If you're using a knowledge base like Vectara, you can configure it to store and filter the CV data, ensuring the AI retrieves only the most relevant details during the simulation. You can then use the API to fetch this information in real-time, making the interview simulation more realistic and tailored to the user's profile.

atomic swan
#

so what would I put in the prompt ?

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl

For your interview simulator app, the system prompt should focus on setting the overall behavior and tone of the AI agent. It should guide the agent on how to act, such as being a professional interviewer, asking relevant questions, and providing feedback. For example, you could include instructions like:

  • "You are a professional interviewer conducting a mock interview for a job candidate."
  • "Ask questions based on the candidate's CV and provide constructive feedback on their answers."
  • "Maintain a formal and professional tone throughout the conversation."

Your CV would be better integrated into the Knowledge Base, as it contains detailed, structured information that the AI can reference when generating responses. This allows the AI to pull relevant details from the CV without overloading the system prompt.

atomic swan
#

and I have a question, if I want to train the agent time to time how can I do that ?

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl

For your interview simulator app, here's how you approach your questions:

1. What to put in the prompt?

The system prompt is used to define the agent's behavior, style, and demeanor For example, in your case, you could include instructions like:

  • "You are a professional interviewer specializing in [industry/role]."
  • "Ask questions based on the candidate's CV and provide constructive feedback."
  • "Maintain a formal tone and focus on assessing the candidate's skills and experience."

The prompt should guide the agent on how to interact, but it shouldn't include large amounts of data like your CV. Instead, the CV should be part of the knowledge base.

2. Where to integrate your CV?

The CV should go into the knowledge base. This allows the agent to access and reference it during the conversation. The knowledge base is designed to store additional information that the agent can use to enhance its responses. Non-enterprise users can upload up to 5 files or links, with a total limit of 20MB and 300,000 characters.

3. How to train the agent over time?

The agent itself cannot be "trained" in the traditional sense, as it relies on the underlying LLM (Large Language Model). However, you can update its knowledge base periodically with new information (e.g., an updated CV or additional resources). Additionally, you can refine the system prompt to adjust the agent's behavior or focus as needed.

If you need more advanced customization or ongoing updates, you might want to explore options like integrating a custom LLM via server settings, which is planned for future support.

atomic swan
#

so what is it for? the criteria : evaluation
object
Optional
Settings to evaluate an agent’s performance. Agents are evaluated against a set of criteria, with success being defined as meeting some combination of those criteria.

Hide property
criteria
list of objects
Optional

Hide 5 properties
id
string
Required
conversation_goal_prompt
string
Required
<=800 characters
name
string
Optional
type
"prompt"
Optional
Defaults to prompt
use_knowledge_base
boolean
Optional
Defaults to false

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl
  1. What to put in the prompt?
    The system prompt is used to define the agent behavior, style, and demeanor. For example, you can specify that the agent should act as a professional interviewer, asking questions based on the CV and providing feedback. The prompt should guide the agent on how to interact with the user, but it should not include large datasets like a CV. Instead, the CV should be stored in the knowledge base for the agent to reference during the conversation.

  2. Training the agent over time:
    The provided content does not include specific details about training the agent over time. However, you can periodically update the knowledge base with new information or adjust the system prompt to refine the agent's behavior. If you need more advanced training options, you may need to explore external tools or APIs that support such functionality.

  3. Evaluation criteria:
    The evaluation criteria are used to assess the agent's performance. You can define success criteria, such as whether the agent met the conversation goal or provided accurate and helpful responses. These criteria are specified as objects, with properties like:

    • id: A unique identifier for the criterion.
    • conversation_goal_prompt: A description of the goal the agent should achieve (e.g., "The agent should ask relevant questions based on the CV").
    • name: An optional name for the criterion.
    • type: Defaults to "prompt" but can be adjusted.
    • use_knowledge_base: Indicates whether the agent should use the knowledge base for this evaluation.

By setting these criteria, you can monitor and improve the agent's performance over time.

atomic swan
#

can I add knowledge_base via the api ?

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl

Based on the provided content, there is no explicit information about adding a knowledge base via the API. If you need further clarification or assistance with this, I recommend reaching out to the support team or consulting the API References for detailed documentation.

atomic swan
#

can I add file throught the knowledge_base via the api ?

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl

Yes, you can add a file to the knowledge base using the API. To do this, you need to use the Create Knowledge Base Document endpoint. Here's how it works:

Endpoint

POST /v1/convai/agents/{agent_id}/add-to-knowledge-base

Required Parameters

  • agent_id: The ID of the agent you want to add the file to.
  • file: The file you want to upload. It must be sent as part of a multipart/form-data request.

Example Code (Python)

import requests

url = "https://api.elevenlabs.io/v1/convai/agents/{agent_id}/add-to-knowledge-base"
files = [
    ('file', ('your_file_name.txt', open('your_file_name.txt', 'rb'), 'text/plain'))
]
headers = {
    'xi-api-key': 'YOUR_API_KEY',
}

response = requests.post(url, headers=headers, files=files)
print(response.json())

Notes

  1. After uploading the file, you will receive a document_id in the response. You must patch your agent with this document_id to attach the file to the agent's knowledge base.
  2. Ensure the file size is within the platform's limits (21MB for a single file, with a total limit of 20MB and 300,000 characters for non-enterprise users).

For more details, you can refer to the Create Knowledge Base Document.

atomic swan
#

in typescript ?

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl

Yes, you can add a file to the knowledge base via the API in TypeScript. Here's an example of how you can achieve this using the POST /v1/convai/agents/:agent_id/add-to-knowledge-base endpoint:

import axios from 'axios';
import * as fs from 'fs';

const addFileToKnowledgeBase = async () => {
  const apiKey = 'YOUR_API_KEY';
  const agentId = 'YOUR_AGENT_ID';
  const filePath = 'path/to/your/file.txt';

  const url = `https://api.elevenlabs.io/v1/convai/agents/${agentId}/add-to-knowledge-base`;

  const formData = new FormData();
  formData.append('file', fs.createReadStream(filePath), {
    filename: 'file.txt',
    contentType: 'text/plain',
  });

  try {
    const response = await axios.post(url, formData, {
      headers: {
        'xi-api-key': apiKey,
        ...formData.getHeaders(),
      },
    });

    console.log('Response:', response.data);
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
};

addFileToKnowledgeBase();

Key Points:

  1. Replace YOUR_API_KEY and YOUR_AGENT_ID with your actual API key and agent ID.
  2. Ensure the file path (filePath) points to the file you want to upload.
  3. The file's MIME type should match its content (e.g., text/plain for a .txt file).

After uploading the file, you will need to patch the agent with the returned document ID to make the knowledge base changes effective. Let me know if you need help with that!

atomic swan
#

in the api how do you create a agent with a knowledge using typescript ?

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl

To create an agent with a knowledge base using TypeScript, you need to follow a sequential process since the API does not allow creating an agent and its knowledge base in a single step. Here's how you can do it:

1. Create the Agent

First, use the POST /v1/convai/agents endpoint to create the agent. This step does not require attaching a knowledge base.

import axios from 'axios';

const createAgent = async () => {
  const response = await axios.post(
    'https://api.elevenlabs.io/v1/convai/agents',
    {
      name: 'Interview Simulator Agent',
      description: 'An agent for simulating interviews',
      // Add other agent configuration details here
    },
    {
      headers: {
        'xi-api-key': 'YOUR_API_KEY',
      },
    }
  );

  return response.data.id; // Returns the agent ID
};

2. Add Knowledge Base Documents

Once the agent is created, use the POST /v1/convai/agents/{agent_id}/add-to-knowledge-base endpoint to upload files or URLs to the agent's knowledge base.

const addToKnowledgeBase = async (agentId: string, file: File) => {
  const formData = new FormData();
  formData.append('file', file);

  const response = await axios.post(
    `https://api.elevenlabs.io/v1/convai/agents/${agentId}/add-to-knowledge-base`,
    formData,
    {
      headers: {
        'xi-api-key': 'YOUR_API_KEY',
        'Content-Type': 'multipart/form-data',
      },
    }
  );

  return response.data.id; // Returns the document ID
};

3. Patch the Agent

After adding the knowledge base documents, you need to patch the agent to associate it with the uploaded document IDs.

const patchAgent = async (agentId: string, documentIds: string[]) => {
  await axios.patch(
    `https://api.elevenlabs.io/v1/convai/agents/${agentId}`,
    {
      knowledge_base: documentIds,
    },
    {
      headers: {
        'xi-api-key': 'YOUR_API_KEY',
      },
    }
  );
};

4. Complete Workflow

Here’s how you can combine the steps:

const setupAgentWithKnowledgeBase = async (file: File) => {
  try {
    // Step 1: Create the agent
    const agentId = await createAgent();

    // Step 2: Add the file to the knowledge base
    const documentId = await addToKnowledgeBase(agentId, file);

    // Step 3: Patch the agent with the document ID
    await patchAgent(agentId, [documentId]);

    console.log('Agent setup complete with knowledge base!');
  } catch (error) {
    console.error('Error setting up agent:', error);
  }
};

Notes:

  • Replace YOUR_API_KEY with your actual API key.
  • Ensure the file size and character limits comply with the non-enterprise user restrictions (5 files/links, 20MB, or 300,000 characters).
  • If you need to update the knowledge base over time, you can repeat the process of adding new documents and patching the agent.

This approach ensures your agent is properly configured with a knowledge base using TypeScript.

atomic swan
#

Ok but can you create agent with knowledge base ?

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl

No, you cannot create an agent with a knowledge base in a single step using the API. The process requires two sequential steps:

  1. Create the Agent: Use the POST /v1/convai/agents endpoint to create the agent. At this stage, you don't attach a knowledge base.

  2. Add to the Knowledge Base: After the agent is created, use the POST /v1/convai/agents/{agent_id}/add-to-knowledge-base endpoint to upload a file or reference a webpage for the agent's knowledge base. This step generates a document ID.

  3. Patch the Agent: Once the knowledge base document is added, you need to update the agent to use the new document ID(s) in its knowledge base.

This process ensures that the agent and its knowledge base are configured properly. If you're using TypeScript, you can follow the same API flow programmatically. Let me know if you'd like an example!

atomic swan
#

Ok it's adding file to the knowledge base but I want that it use this specific file in the knowledge base not just adding thel

kindred salmonBOT
#
AI-generated Answer for jljljljljljljljljljljljljl

To ensure that a specific file in the knowledge base is actively used by the agent, you need to follow these steps:

  1. Add the File to the Knowledge Base: Use the POST /v1/convai/agents/{agent_id}/add-to-knowledge-base API endpoint to upload the file. This will generate a document ID for the uploaded file.

  2. Patch the Agent to Use the File: After the file is added, you need to update the agent's configuration to include the document ID in its knowledge base. This is done by patching the agent with the document ID.

Here’s an example in TypeScript:

import axios from 'axios';

const API_KEY = 'YOUR_API_KEY';
const AGENT_ID = 'YOUR_AGENT_ID';
const FILE_PATH = 'path/to/your/file.pdf'; // Replace with your file path

async function addFileToKnowledgeBase() {
  try {
    // Step 1: Add the file to the knowledge base
    const formData = new FormData();
    formData.append('file', FILE_PATH);

    const addResponse = await axios.post(
      `https://api.elevenlabs.io/v1/convai/agents/${AGENT_ID}/add-to-knowledge-base`,
      formData,
      {
        headers: {
          'xi-api-key': API_KEY,
          'Content-Type': 'multipart/form-data',
        },
      }
    );

    const documentId = addResponse.data.id;

    // Step 2: Patch the agent to use the document
    const patchResponse = await axios.patch(
      `https://api.elevenlabs.io/v1/convai/agents/${AGENT_ID}`,
      {
        conversation_config: {
          agent: {
            prompt: {
              knowledge_base: [documentId],
            },
          },
        },
      },
      {
        headers: {
          'xi-api-key': API_KEY,
          'Content-Type': 'application/json',
        },
      }
    );

    console.log('Agent updated successfully:', patchResponse.data);
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
}

addFileToKnowledgeBase();

Key Points:

  • The first step uploads the file and retrieves its document ID.
  • The second step updates the agent's configuration to actively use the uploaded file by including its document ID in the knowledge_base array.

This ensures the agent uses the specific file in its knowledge base during conversations.

atomic swan
#

but I got this error when I do that : Error in createInterviewAgent: Error [AxiosError]: Request failed with status code 400
at async POST (app/api/createInterviewAgent/route.ts:192:12)
190 | // Step 3: Patch the agent with the knowledge base in the correct location
191 | const documentId = knowledgeBaseResponse.data.id;

192 | await axios.patch(
| ^
193 | https://api.elevenlabs.io/v1/convai/agents/${agentId},
194 | {
195 | conversation_config: { {
code: 'ERR_BAD_REQUEST',
config: [Object],
request: [ClientRequest],
response: [Object],
status: 400,
constructor: [Function],
toJSON: [Function: toJSON]
}
POST /api/createInterviewAgent 500 in 4014ms