add_knowledge_base_to_agent
Add knowledge base content to an ElevenLabs agent from files, URLs, or text to enhance its contextual understanding and response capabilities.
Instructions
Add a knowledge base to ElevenLabs workspace. Allowed types are epub, pdf, docx, txt, html.
⚠️ COST WARNING: This tool makes an API call to ElevenLabs which may incur costs. Only use when explicitly requested by the user.
Args:
agent_id: ID of the agent to add the knowledge base to.
knowledge_base_name: Name of the knowledge base.
url: URL of the knowledge base.
input_file_path: Path to the file to add to the knowledge base.
text: Text to add to the knowledge base.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agent_id | Yes | ||
| input_file_path | No | ||
| knowledge_base_name | Yes | ||
| text | No | ||
| url | No |
Implementation Reference
- elevenlabs_mcp/server.py:583-595 (registration)Registration of the 'add_knowledge_base_to_agent' tool using the @mcp.tool decorator, including description and parameters.@mcp.tool( description="""Add a knowledge base to ElevenLabs workspace. Allowed types are epub, pdf, docx, txt, html. ⚠️ COST WARNING: This tool makes an API call to ElevenLabs which may incur costs. Only use when explicitly requested by the user. Args: agent_id: ID of the agent to add the knowledge base to. knowledge_base_name: Name of the knowledge base. url: URL of the knowledge base. input_file_path: Path to the file to add to the knowledge base. text: Text to add to the knowledge base. """ )
- elevenlabs_mcp/server.py:596-659 (handler)The handler function implements the logic to create a knowledge base document via ElevenLabs API (from URL, file, or text input) and appends it to the specified agent's conversation configuration.def add_knowledge_base_to_agent( agent_id: str, knowledge_base_name: str, url: str | None = None, input_file_path: str | None = None, text: str | None = None, ) -> TextContent: provided_params = [ param for param in [url, input_file_path, text] if param is not None ] if len(provided_params) == 0: make_error("Must provide either a URL, a file, or text") if len(provided_params) > 1: make_error("Must provide exactly one of: URL, file, or text") if url is not None: response = client.conversational_ai.knowledge_base.documents.create_from_url( name=knowledge_base_name, url=url, ) else: if text is not None: text_bytes = text.encode("utf-8") text_io = BytesIO(text_bytes) text_io.name = "text.txt" text_io.content_type = "text/plain" file = text_io elif input_file_path is not None: path = handle_input_file( file_path=input_file_path, audio_content_check=False ) file = open(path, "rb") response = client.conversational_ai.knowledge_base.documents.create_from_file( name=knowledge_base_name, file=file, ) agent = client.conversational_ai.agents.get(agent_id=agent_id) agent_config = agent.conversation_config.agent knowledge_base_list = ( agent_config.get("prompt", {}).get("knowledge_base", []) if agent_config else [] ) knowledge_base_list.append( KnowledgeBaseLocator( type="file" if file else "url", name=knowledge_base_name, id=response.id, ) ) if agent_config and "prompt" not in agent_config: agent_config["prompt"] = {} if agent_config: agent_config["prompt"]["knowledge_base"] = knowledge_base_list client.conversational_ai.agents.update( agent_id=agent_id, conversation_config=agent.conversation_config ) return TextContent( type="text", text=f"""Knowledge base created with ID: {response.id} and added to agent {agent_id} successfully.""", )