# Limit what an agent reads

A new agent reads none of your knowledge. Pick documents, and it reads only those.

## Before you start

You need an agent and knowledge. See [Add knowledge](/docs/agents/knowledge.md).

## Pick the documents

**Code**

1. Set your agent's `knowledge` to the document's path:

```ts title="agents/support.ts" {7}
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/returns-policy.md",
});
```

`knowledge` also takes a list of paths, a glob such as `"knowledge/policies/**"` for a whole folder, or include and exclude patterns: see [Include or exclude knowledge folders](/docs/agents/knowledge-patterns.md).

2. Start the project with `npm run dev`.
3. In Studio, open **Chat**.
4. Pick Support assistant.
5. Ask "How many days do I have to return an item?". You should now see it call `veryfront__search_knowledge`, which finds only the returns policy, and reply 45 days.

### 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 | cd support-desk && mkdir -p knowledge && printf '%s\n' '---' 'title: Returns policy' '---' '' 'Returns are accepted within 45 days of delivery.' > knowledge/returns-policy.md && printf '%s\n' '---' 'title: Shipping guide' '---' '' 'Orders ship within 2 business days.' > knowledge/shipping-guide.md
step: Set the knowledge | 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/returns-policy.md",' '});' > 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**. You should now see your documents with a box beside each.
5. Tick the box beside Returns policy. You should now see 1 document selected.
6. Click **Save**. You should now see "Agent updated" on 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 to one document of the agent `support`, with your [API key](/docs/authentication/api-keys.md). Only the fields you send change:

```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/returns-policy.md"}'
```

3. Get the agent. You should now see `"knowledge": "knowledge/returns-policy.md"`:

```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 | curl -X PUT https://api.veryfront.com/projects/$PROJECT/files/knowledge%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"}'
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/returns-policy.md"}'
check: curl https://api.veryfront.com/projects/$PROJECT/agents/support -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: "knowledge":"knowledge/returns-policy.md"
```

## 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/returns-policy.md"`. The project reference is its slug or its ID.
2. It worked when the answer reads `knowledge` as `knowledge/returns-policy.md`.

## Next steps

* [Include or exclude knowledge folders](/docs/agents/knowledge-patterns.md)
* [Upload files](/docs/projects/uploads.md)
