https://retellai.com/?utm_source=discord&utm_medium=seo logo
<@1145576664366055464> Create Agent API with know...
# ❓・ai-evy-support
n
@AI Evy Create Agent API with knowledge base Id ?
a
Thanks for tagging me @neha_09141. I'll look through relevant sources and get back to you shortly.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Knowledge Base]() * [Create Knowledge Base]() * [Create Agent]() * [Retell AI | Simplify AI Agent Creation with Retell AI’s Knowledge Base Feature]() -----------------------------
### Answer First, create a knowledge base using the API [(1)]() :
Copy code
javascript
import Retell from 'retell-sdk';

const client = new Retell({
  apiKey: 'YOUR_RETELL_API_KEY',
});

async function main() {
  const knowledgeBaseResponse = await client.knowledgeBase.create({
    knowledge_base_name: "Sample KB",
    knowledge_base_texts: [
      {
        text: "Hello, how are you?",
        title: "Sample Question",
      },
    ],
    knowledge_base_urls: [
      "https://www.retellai.com", 
      "https://docs.retellai.com",
    ],
    knowledge_base_files: [
      fs.createReadStream("../sample.txt"),
    ],
  });

  console.log(knowledgeBaseResponse.knowledge_base_id);
}

main();
Once you have the knowledge base ID, you can connect it to your agent [(2)]() . The knowledge base will be used automatically when added to an agent - no prompt changes needed . I don't see the exact Create Agent API code with knowledge base ID in the provided documentation, so I cannot provide that specific code snippet. However, you can connect a knowledge base to an agent through the agent editor UI by: 1. Opening the agent editor 2. Locating the "Knowledge Base" section 3. Selecting the knowledge base items you want to use The agent will then automatically use this information when responding to queries related to the added content .
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.