# How to Attach and Detach Agent Knowledge Bases on DigitalOcean Gradient™ AI Platform DigitalOcean Gradient™ AI Platform lets you build fully-managed AI agents with knowledge bases for retrieval-augmented generation, multi-agent routing, guardrails, and more, or use serverless inference to make direct requests to popular foundation models. You can [attach knowledge bases](#attach) to give agents access to additional custom data, or [detach them](#detach) if the information is no longer needed. Attaching or detaching knowledge bases triggers an immediate redeployment of the agent. ## Attach a Knowledge Base to an Agent Using the Control Panel To attach a knowledge base using the [DigitalOcean Control Panel](https://cloud.digitalocean.com), click **Agent Platform** in the left menu, then in the **Agent Workspaces** tab, select the workspace that contains the agent you want to attach a knowledge base to. From the workspace’s **Agents** tab, select the agent, then click its **Resources** tab. In the **Knowledge Bases** section, click **Add Knowledge Bases**. In the **Knowledge Bases** field, type and then select the knowledge base you want to attach. A knowledge base must have vector embeddings to appear in the list. If it’s created but not yet indexed, you cannot attach it to an agent. After selecting the knowledge bases, click **Add Knowledge Bases**. You can view attached knowledge bases in the agent’s **Resources** tab, along with the last indexing time and attachment date. ## Attach a Knowledge Base to an Agent Using the API To attach a knowledge base using the API, provide the agent’s ID and the knowledge base ID. Retrieve available knowledge bases using the [List Knowledge Bases](https://docs.digitalocean.com/reference/api/reference/gradientai-platform/index.html.md#genai_list_knowledge_bases) endpoint, and agents using the [List Agents](https://docs.digitalocean.com/reference/api/reference/gradientai-platform/index.html.md#genai_list_agents) endpoint. A knowledge base must have at least one indexed data source to appear in the list. To index a knowledge base, find its ID in the list, then [index its data sources](https://docs.digitalocean.com/products/gradient-ai-platform/how-to/create-manage-agent-knowledge-bases/index.html.md#reindex-data-source-api). ## How to Attach a Knowledge Base to an Agent Using the DigitalOcean API 1. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) and save it for use with the API. 2. Send a POST request to [`https://api.digitalocean.com/v2/gen-ai/agents/{agent_uuid}/knowledge_bases`](https://docs.digitalocean.com/reference/api/reference/gradientai-platform/index.html.md#genai_attach_knowledge_bases). ### cURL Using cURL: ```shell curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ "https://api.digitalocean.com/v2/gen-ai/agents/1b418231-b7d6-11ef-bf8f-4e013e2ddde4/knowledge_bases" \ -d '{ "agent_uuid": "1b418231-b7d6-11ef-bf8f-4e013e2ddde4", "knowledge_base_uuids": [ "9a6e3975-b0c6-11ef-bf8f-4e013e2ddde4", "683c3100-7c18-4c94-aea4-5ac5875cc87c", "4887a78b-74af-46b3-98f4-451a48f9cc5e" ] }' ``` Once attached, the agent can access and retrieve content from the knowledge base during prompt processing. ## Detach a Knowledge Base from an Agent Using the Control Panel You can detach a knowledge base if it’s no longer needed. This stops the agent from referencing it but doesn’t delete or affect the knowledge base itself. Detaching a knowledge base triggers immediate agent redeployment, which may take a few minutes. From the [DigitalOcean Control Panel](https://cloud.digitalocean.com), click **Agent Platform** in the left menu, then in the **Agent Workspaces** tab, select the workspace that contains the agent you want to detach a knowledge base for. From the workspace’s **Agents** tab, select the agent, and then click its **Resources** tab. In the **Knowledge Bases** section, find the knowledge base to detach. To the right of the knowledge base, click **…** to open the knowledge base menu, then click **Detach Knowledge Base**. In the confirmation window, type the knowledge base’s name, then click **Detach Knowledge Base**. ## Detach a Knowledge Base from an Agent Using the API To detach a knowledge base using the API, provide the agent ID and knowledge base ID. Retrieve IDs using the [List Agents](https://docs.digitalocean.com/reference/api/reference/gradientai-platform/index.html.md#genai_list_agents) and [List Knowledge Bases](https://docs.digitalocean.com/reference/api/reference/gradientai-platform/index.html.md#genai_list_knowledge_bases) endpoints. ## How to Detach a Knowledge Base From an Agent Using the DigitalOcean API 1. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) and save it for use with the API. 2. Send a DELETE request to [`https://api.digitalocean.com/v2/gen-ai/agents/{agent_uuid}/knowledge_bases/{knowledge_base_uuid}`](https://docs.digitalocean.com/reference/api/reference/gradientai-platform/index.html.md#genai_detach_knowledge_base). ### cURL Using cURL: ```shell curl -X DELETE \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ "https://api.digitalocean.com/v2/gen-ai/knowledge_bases/9a6e3975-b0c6-11ef-bf8f-4e013e2ddde4/data_sources/bd2a2db5-b8b0-11ef-bf8f-4e013e2ddde4" ```