> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect to Apps, Agents, and Code

> Where an agent knowledge base can be used, and how to cut off each kind of access

One [agent knowledge base](https://docs.dify.ai/en/cloud/use-dify/knowledge-base/overview.md) can serve many apps at once. Connect it to workflows, Agents, or programs that should answer from it, or let a coding agent on your machine read its documents through the Dify CLI.

> [!NOTE]
>
> Chatbot, legacy Agent, and Text Generator apps can't search an agent knowledge base. To answer from one, rebuild the app as a Chatflow or an Agent.

## From Workflow and Chatflow Apps

Add an [Agent Knowledge Retrieval](https://docs.dify.ai/en/cloud/use-dify/nodes/knowledge-retrieval-v2.md) node and pick the knowledge bases it searches. A knowledge base you don't have permission to view doesn't appear in the picker.

To limit searches to certain documents, [filter by metadata](https://docs.dify.ai/en/cloud/use-dify/nodes/knowledge-retrieval-v2.md#filter-by-metadata) in the node.

To stop every workflow from searching the knowledge base, test runs included, turn off **Workflow access** in the knowledge base's **Settings**. Workflows that already use it fail at that node until you turn it back on.

## From the New Agent

In an [Agent](https://docs.dify.ai/en/cloud/use-dify/build/new-agent/overview.md)'s **Configure** editor, add the knowledge base under **[Agent Knowledge Base](https://docs.dify.ai/en/cloud/use-dify/build/new-agent/build.md#agent-knowledge-base)**.

The Agent decides on its own when to search the knowledge base by its name and description, always at the Fast retrieval depth.

To stop published Agents from searching the knowledge base, turn off **API access** in the knowledge base's **Settings**. Agents that use it keep running but can no longer search it. The same switch cuts off the Service API.

## From Your Own Code

Through the [Service API](https://docs.dify.ai/en/api-reference/guides/knowledge-base.md), your code can ask the knowledge base questions, run longer Research searches in the background, and maintain its documents.

To shut API callers out, turn off **API access** in the knowledge base's **Settings**; [Agents](https://docs.dify.ai/en/cloud/use-dify/build/new-agent/overview.md) lose access too.

## From Your Coding Agent

A coding agent on your own machine, such as Claude Code or Codex, can use the knowledge base as reference while it works. Through the Dify CLI, it browses the documents like files in folders, reads them, and searches them for exact words.

It can't change anything in the knowledge base. To search by meaning, as your apps do, use the [Service API](#from-your-own-code).

To set it up, follow [Get Started](https://docs.dify.ai/en/cli/get-started.md) in the CLI docs: install `difyctl`, sign in with your Dify account, and give your agent the `difyctl` skill.

Then ask your agent for what you need, and include two things:

* `difyctl knowledge_fs`, the commands to use. The `difyctl` skill doesn't cover them.
* The knowledge base's ID. With the knowledge base open in Dify, copy it from the browser's address: it's the part between `/datasets/new/` and the next `/`.

For example:

```text wrap theme={null}
Use difyctl knowledge_fs to read the API design guidelines in Dify knowledge base 5b9e2c71-0d4a-4f3e-9a6b-2c8d1e7f4a30, then check my endpoint changes against them.
```

Your agent can open any agent knowledge base you can view in Dify.

It looks in the workspace you had open in Dify when you signed in. For a knowledge base in another workspace, [switch `difyctl` to that workspace](https://docs.dify.ai/en/cli/manage-sign-in#switch-your-workspace) first.

## After Your Apps Go Live

Sync or re-upload a document, and your apps, Agents, API callers, and external coding agents see the new version as soon as it finishes indexing.

On the **Overview** page, watch for sources that stopped syncing and questions that came back empty. See [Maintain an Agent Knowledge Base](https://docs.dify.ai/en/cloud/use-dify/knowledge-base/maintain-knowledge-base.md) for what to do about each.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.