# Include or exclude knowledge folders

Patterns pick knowledge by folder. Include a folder and the agent reads the documents in it; exclude a folder inside it to leave those out.

## Before you start

You need an agent and knowledge in folders. See [Limit what an agent reads](/docs/agents/knowledge-select.md).

## Include a folder, exclude another

**Code**

1. Set your agent's `knowledge` to patterns. `true` includes a folder and `false` leaves one out:

```ts title="agents/support.ts" {7-10}
import { agent } from "veryfront/agent";

export default agent({
  id: "support",
  name: "Support assistant",
  system: "Answer customer questions about orders and refunds from the project's knowledge. Keep replies to two sentences.",
  knowledge: {
    "knowledge/policies/**": true,
    "knowledge/policies/drafts/**": false,
  },
});
```

2. Start the project with `npm run dev`.
3. Open **Chat** in Studio.
4. Pick Support assistant.
5. Ask "How many days do I have to return an item?". You should now see it reply 45 days, not the draft's 60.

### Try it in a sandbox

```playground
step: Create a project | npm create -y veryfront@latest support-desk -- --template ai-agent --yes
step: Before you start: knowledge in folders | cd support-desk && mkdir -p knowledge/policies/drafts && printf '%s\n' '---' 'title: Returns policy' '---' '' 'Returns are accepted within 45 days of delivery.' > knowledge/policies/returns-policy.md && printf '%s\n' '---' 'title: Refund timeline' '---' '' 'Refunds are issued within 5 business days.' > knowledge/policies/refund-timeline.md && printf '%s\n' '---' 'title: New returns policy' '---' '' 'Draft: returns within 60 days.' > knowledge/policies/drafts/new-returns-policy.md && printf '%s\n' '---' 'title: Shipping guide' '---' '' 'Orders ship within 2 business days.' > knowledge/shipping-guide.md
step: Set the patterns | mkdir -p agents && printf '%s\n' 'import { agent } from "veryfront/agent";' '' 'export default agent({' '  id: "support",' '  name: "Support assistant",' '  system: "Answer customer questions about orders and refunds from the project'\''s knowledge. Keep replies to two sentences.",' '  knowledge: {' '    "knowledge/policies/**": true,' '    "knowledge/policies/drafts/**": false,' '  },' '});' > agents/support.ts
step: Start it | npm run dev
agent: support
ask: How many days do I have to return an item?
tool: veryfront__search_knowledge
expect: 45
```

**Studio**

1. In your project, open **Agents**.
2. Click your agent.
3. Click **Edit**.
4. Under **Add knowledge**, pick **Selected**.
5. Click **Advanced**. You should now see **Select knowledge**, with each document and its path.
6. Click **Include**.
7. Enter `knowledge/policies/**`.
8. Press Enter. You should now see the tab read Include (1).
9. Click **Exclude**.
10. Enter `knowledge/policies/drafts/**`.
11. Press Enter. You should now see the tab read Exclude (1).
12. Click **Save**. You should now see the policies ticked, the `drafts` folder unticked and 2 documents selected.
13. Click **Save**. You should now see the agent's page.

**API**

These calls change the agent on the main branch. To change it on a preview branch, add `?source_target_kind=preview_branch&target_branch_id=$BRANCH_ID` to both URLs before you run them, where `$BRANCH_ID` is the branch's `id` from `GET /projects/$PROJECT/branches`.

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. Set the agent's knowledge, here of the agent `support`, with your [API key](/docs/authentication/api-keys.md). `true` includes a pattern and `false` excludes it:

```bash
curl -X PUT https://api.veryfront.com/projects/$PROJECT/agents/support \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"knowledge": {"knowledge/policies/**": true, "knowledge/policies/drafts/**": false}}'
```

3. Get the agent. You should now see both patterns under `knowledge`:

```bash
curl https://api.veryfront.com/projects/$PROJECT/agents/support \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

### Try it in a sandbox

```playground
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_ID
step: Before you start: an agent | curl -X POST https://api.veryfront.com/projects/$PROJECT/agents -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"id": "support", "name": "Support assistant", "system_prompt": "Answer customer questions about orders and refunds. Keep replies to two sentences."}'
step: Before you start: knowledge in folders | curl -X PUT https://api.veryfront.com/projects/$PROJECT/files/knowledge%2Fpolicies%2Freturns-policy.md -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"content": "---\ntitle: Returns policy\n---\n\nReturns are accepted within 45 days of delivery.\n"}' && curl -X PUT https://api.veryfront.com/projects/$PROJECT/files/knowledge%2Fpolicies%2Fdrafts%2Fnew-returns-policy.md -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"content": "---\ntitle: New returns policy\n---\n\nDraft: returns within 60 days.\n"}'
step: Set the agent's knowledge | curl -X PUT https://api.veryfront.com/projects/$PROJECT/agents/support -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"knowledge": {"knowledge/policies/**": true, "knowledge/policies/drafts/**": false}}'
check: curl https://api.veryfront.com/projects/$PROJECT/agents/support -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: "knowledge/policies/drafts/**":false
```

## With MCP

On a preview branch, pass `"source_target_kind": "preview_branch"` and the branch's ID as `target_branch_id` (`veryfront__list_branches` lists them) in the call below, or it changes the agent on the main branch.

1. Call `veryfront__update_agent` with your agent's ID as `agent_id` (here `support`; `veryfront__list_agents` lists them), `"project_reference": "my-project"` and `"knowledge": { "knowledge/policies/**": true, "knowledge/policies/drafts/**": false }`. The project reference is its slug or its ID.
2. It worked when the answer reads both patterns under `knowledge`. The `knowledge` you send replaces the agent's own, and the change is saved to `agents/support.ts`.

## Next steps

* [Chat with an agent](/docs/agents/chat.md)
* [Create an agent](/docs/agents/create-agent.md)
