|
| 1 | +--- |
| 2 | +ContentId: 5d7a2a1e-9f1c-4d2a-8c6a-1c2a8f7d4a01 |
| 3 | +DateApproved: 05/21/2026 |
| 4 | +MetaDescription: Practice choosing agent tools, tool sets, approvals, and sandboxing settings for focused AI workflows in VS Code. |
| 5 | +MetaSocialImage: ../images/shared/agent-first-development-social.png |
| 6 | +Keywords: |
| 7 | + - copilot |
| 8 | + - agents |
| 9 | + - tools |
| 10 | + - tool sets |
| 11 | + - approvals |
| 12 | + - sandboxing |
| 13 | +--- |
| 14 | + |
| 15 | +# Using tools with agents |
| 16 | + |
| 17 | +Tools are how agents act on your request. They search your workspace, read files, edit code, run terminal commands, fetch web content, and call external services. In this guide, you will start with a small task, choose only the tools the task needs, and decide when to use a tool set, approvals, or sandboxing. |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +Before you start, install VS Code, enable AI features, and sign in to GitHub Copilot. You also need access to any extra tools you want to try, such as MCP servers or extensions that contribute tools. |
| 22 | + |
| 23 | +* [Download VS Code](https://code.visualstudio.com/) |
| 24 | +* [Set up GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview#_step-1-set-up-copilot) |
| 25 | + |
| 26 | +## Start with a task |
| 27 | + |
| 28 | +Imagine you want the agent to explain how authentication works in a repository and then suggest one small test to add. That task needs repository context, but it probably does not need terminal access, web access, or external services at the start. |
| 29 | + |
| 30 | +Use this prompt in an agent session: |
| 31 | + |
| 32 | +```prompt |
| 33 | +Explain the authentication flow in this project. Find the main files involved, then suggest one focused test I should add next. |
| 34 | +``` |
| 35 | + |
| 36 | +Before you send it, decide which tools the agent should have. VS Code supports three kinds of tools: |
| 37 | + |
| 38 | +* Built-in tools, such as read, edit, search, execute, and web. |
| 39 | +* MCP tools from installed Model Context Protocol servers. |
| 40 | +* Extension tools contributed by VS Code extensions. |
| 41 | + |
| 42 | +The agent selects from the enabled tools based on your prompt and context. Your job is to give it enough capability to finish the task without giving it a noisy list of unrelated options. |
| 43 | + |
| 44 | +## Choose tools for the first pass |
| 45 | + |
| 46 | +1. Open the Chat view. |
| 47 | + |
| 48 | +1. Select **Agent** from the agent picker. |
| 49 | + |
| 50 | +1. Select **Configure Tools** in the chat input. |
| 51 | + |
| 52 | +1. Keep repository search and file-reading tools enabled. |
| 53 | + |
| 54 | +1. Leave terminal, web, and external service tools off for this first pass. |
| 55 | + |
| 56 | +1. Send the prompt. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +Starting small helps the agent stay focused. It also reduces tool definitions in the model context window. VS Code can expose some groups as virtual tools to keep tool counts manageable, but a smaller active set still makes the task easier for the model to reason about. |
| 61 | + |
| 62 | +> [!TIP] |
| 63 | +> If the agent says it needs to run tests or inspect generated output, add the terminal tool for the next request instead of restarting with every tool enabled. |
| 64 | +
|
| 65 | +## Add a specific tool when needed |
| 66 | + |
| 67 | +Sometimes you know exactly which tool should ground the answer. Type `#` in the chat input to see available tools, context sources, and tool sets. |
| 68 | + |
| 69 | +For example, revise the previous prompt like this: |
| 70 | + |
| 71 | +```prompt |
| 72 | +Explain the authentication flow in this project. Focus on repository context. #codebase |
| 73 | +``` |
| 74 | + |
| 75 | +Use explicit tool references when the task has a clear source of truth: |
| 76 | + |
| 77 | +* Use `#codebase` when the answer should come from your repository. |
| 78 | +* Use `#problems` when you want the agent to fix current diagnostics. |
| 79 | +* Use `#web` when the answer needs current external documentation. |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +## Decide between individual tools and tool sets |
| 84 | + |
| 85 | +Individual tools work well for one-off requests. Tool sets work better when you repeat the same setup. |
| 86 | + |
| 87 | +| Use | Good fit | Example | |
| 88 | +| --- | --- | --- | |
| 89 | +| Individual tools | A short task with one clear source of context. | Explain a file with `#codebase` and no terminal access. | |
| 90 | +| Tool set | A repeated workflow that needs the same group of tools. | A Python maintenance workflow with search, edit, testing, and Python language tools. | |
| 91 | +| Custom agent tools | A role that should always run with the same boundaries. | A planning agent with search and web tools, but no edit or terminal tools. | |
| 92 | + |
| 93 | +## Create a tool set for repeat work |
| 94 | + |
| 95 | +In this step, create a reusable tool set for repository cleanup work. |
| 96 | + |
| 97 | +1. Open the Command Palette. |
| 98 | + |
| 99 | +1. Run **Chat: Configure Tool Sets** and select **Create new tool sets file**. |
| 100 | + |
| 101 | +1. In the `.jsonc` file that opens, add the tools you use for the cleanup workflow, such as search, edit, and test tools, plus a `description` and `icon`. |
| 102 | + |
| 103 | +1. Save the file. |
| 104 | + |
| 105 | +1. Return to Chat and select the tool set from **Configure Tools**, or reference it in a prompt by typing `#` followed by the tool set name. |
| 106 | + |
| 107 | +Now try a prompt that uses the saved setup: |
| 108 | + |
| 109 | +```prompt |
| 110 | +Find one small cleanup opportunity in this repository, make the change, and run the focused validation for it. |
| 111 | +``` |
| 112 | + |
| 113 | +Tool sets solve the problem of repeatedly rebuilding the same tool selection. They also make reviews easier because the saved file shows which tools are expected for a workflow. |
| 114 | + |
| 115 | +## Limit tools for a custom agent |
| 116 | + |
| 117 | +When you build a [custom agent](https://code.visualstudio.com/docs/copilot/customization/custom-agents), you can list the tools and tool sets it has access to in the `tools` field of the agent's Markdown frontmatter: |
| 118 | + |
| 119 | +```yaml |
| 120 | +--- |
| 121 | +description: Python testing helper |
| 122 | +tools: ['search', 'edit', 'pylance', 'runTests'] |
| 123 | +--- |
| 124 | +``` |
| 125 | + |
| 126 | +You can also edit the `tools` field directly, or open the tools picker with the **Configure Tools** button in the Chat view and let VS Code update the agent's list for you. |
| 127 | + |
| 128 | +Use a custom agent when the tool boundary is part of the role. For example, a planning agent should not edit files by accident, so give it search and web tools but leave out edit and terminal tools. An implementation agent needs a broader set because its job is to modify code and validate the change. |
| 129 | + |
| 130 | +## Pick a permission level |
| 131 | + |
| 132 | +Next, decide how much review you want before tools run. The permissions picker controls how much autonomy the agent has during a session. |
| 133 | + |
| 134 | +* **Default Approvals** asks before sensitive actions. |
| 135 | +* **Bypass Approvals** auto-approves tool calls. |
| 136 | +* **Autopilot** (Preview) auto-approves tool calls and continues working until the task is done. |
| 137 | + |
| 138 | +Use the mode that matches the risk of the task: |
| 139 | + |
| 140 | +* Use **Default Approvals** while exploring unfamiliar code or when the agent can run commands you want to review. |
| 141 | +* Use **Bypass Approvals** for routine workflows in a trusted workspace after you know which tools will run. |
| 142 | +* Use **Autopilot** for contained tasks where the agent can keep iterating until it reaches a result you can review. |
| 143 | + |
| 144 | +You can keep your preferred mode across sessions with `setting(chat.permissions.default)`. Autopilot is available when `setting(chat.autopilot.enabled)` is on. |
| 145 | + |
| 146 | +> [!CAUTION] |
| 147 | +> Higher autonomy levels reduce the amount of review you do before tools run. Use them with care, especially when the agent can edit files or run terminal commands. |
| 148 | +
|
| 149 | + |
| 150 | + |
| 151 | +## Add sandboxing for terminal work |
| 152 | + |
| 153 | +Agent sandboxing adds OS-level isolation for terminal commands run by the agent. It limits file system and network access, and sandboxed commands are auto-approved because they already run in a controlled environment. |
| 154 | + |
| 155 | +Enable it with `setting(chat.agent.sandbox.enabled)`. On macOS and Linux, you can choose full isolation or file system isolation with network access. |
| 156 | + |
| 157 | +Sandboxing is a good fit when the agent needs terminal access but should not reach beyond the workspace or approved domains. For example, use sandboxing before asking the agent to run a generated script, start a local tool, or inspect a project with unfamiliar package scripts. |
| 158 | + |
| 159 | +## Your turn |
| 160 | + |
| 161 | +Try the same repository task three ways: |
| 162 | + |
| 163 | +1. Run it with only repository search and file-reading tools. |
| 164 | + |
| 165 | +1. Add the terminal tool and ask the agent to run one focused validation. |
| 166 | + |
| 167 | +1. Save the tool selection as a tool set and reuse it in a new chat. |
| 168 | + |
| 169 | +After each run, compare what changed. Notice whether the agent stayed focused, asked for missing permissions, or used tools you did not expect. |
| 170 | + |
| 171 | +## Why this matters |
| 172 | + |
| 173 | +The right tool mix keeps agents focused. Tool sets make good workflows repeatable. Custom agents make tool boundaries part of a role. Approvals and sandboxing help you stay in control when the agent can make changes or reach outside the workspace. |
| 174 | + |
| 175 | +## What's next |
| 176 | + |
| 177 | +Now that you know how to use tools, the next course shows how MCP servers add external data and actions to an agent session. |
| 178 | + |
| 179 | +## Learn more |
| 180 | + |
| 181 | +* [Use tools with agents](https://code.visualstudio.com/docs/copilot/agents/agent-tools) |
| 182 | +* [Tools concepts](https://code.visualstudio.com/docs/copilot/concepts/tools) |
| 183 | +* [Agent sandboxing](https://code.visualstudio.com/docs/copilot/concepts/trust-and-safety#agent-sandboxing) |
| 184 | +* [Agent approvals and permissions](https://code.visualstudio.com/docs/copilot/agents/agent-tools#permission-levels) |
0 commit comments