Sub topic 5
What the agent can do: built-in tools
This chapter assumes you know the agent loop from the earlier chapters: the model plans, calls a tool, reads the result, and repeats. It also assumes you can read a Git diff and run build and test commands in a terminal. Here you will learn what the tools are, which ones fit which jobs, and where each one tends to fail.
Tools are the agent's only way to act
A language model produces text. It cannot open a file, run a test, or change a line of code. In agent mode, the editor gives the model a list of tools. Each tool has a name, a description, and a set of parameters. When the model wants to act, it emits a structured tool call. The editor runs the tool and sends the result back as new context. The model then decides what to do next.
This has two consequences:
- The agent can only do what its tools allow. If no tool can reach a database, the agent cannot query it.
- Every action goes through the editor. That is where approvals, logging, and limits are enforced, which later chapters cover.
Exact tool names and groupings differ between editors and change between releases. Check the tools picker in your own editor. The categories below are stable.
The four built-in categories
| Category | What it does | Changes anything? | Typical use |
|---|---|---|---|
| Search | Finds files and code by name, text, or meaning | No | Locating where something is defined or used |
| Read | Returns file contents, folder listings, or diagnostics | No | Understanding code before editing |
| Edit | Creates files and modifies existing ones | Yes, workspace files | Implementing the change |
| Terminal | Runs shell commands and returns the output | Yes, potentially anything | Installing, building, testing, running scripts |
Search and read tools are safe because they only look. Edit and terminal tools change state, so they are the focus of review and approval.
Search tools
Search tools answer the question "where is it?" There are three common kinds.
- File search matches file names or glob patterns, such as
src/**/*.test.ts. It is fast and exact. - Text search finds a literal string or regular expression across the workspace. Use it for an error message, a function name, or a configuration key.
- Semantic (codebase) search finds code related to a description such as "where sessions expire". It relies on an index of your workspace, so it can find relevant code that does not share your keywords.
In VS Code you can nudge the agent toward a tool by naming it in your prompt with #. For example, #codebase asks for a search across the workspace. The agent picks search tools by itself too, but explicit hints help when it keeps searching in the wrong place.
Failure modes:
- Stale or partial index. Semantic search can miss files that are new, ignored by
.gitignore, or in a very large repository. If the agent says nothing exists and you know it does, point it at the file directly. - Too many matches. A broad text search returns a truncated list. The agent may then act on the first few hits and miss the rest. Ask for narrower searches, or name the directory.
- Wrong term. Text search needs the code's actual vocabulary. If your team calls it "tenant" and the code says
org, the search finds nothing.
Read tools
Read tools bring content into the model's context window. The main ones return the contents of a file, usually a range of lines. Others list a directory, report editor diagnostics (the Problems panel), or show the current Git changes.
Reading costs context. A 3,000-line file read in full takes space that your instructions and earlier steps also need. Agents often read a window of lines rather than the whole file. This is why they sometimes edit code without having seen a helper function defined 400 lines away.
Diagnostics are a particularly useful read tool. After an edit, the language server reports type errors and lint warnings. An agent that reads them can fix its own mistake without running a full build. In VS Code you can refer to them with #problems.
Failure modes:
- Partial reads. The agent edits based on a slice of a file and breaks something outside it. Ask it to read the whole file when the file is small and central.
- Stale reads. If you edit a file by hand while the agent works, its earlier read is out of date. Tell it to re-read the file.
- Binary or generated files. Reading minified bundles or lock files wastes context. An instructions file can tell the agent to skip them.
Edit tools
Edit tools write to the workspace. There are two shapes:
- Create a new file with given content.
- Modify an existing file, usually by replacing a specific block of text with new text, or by applying a patch.
Targeted replacement is safer than rewriting a whole file. It keeps diffs small and reviewable. It also fails loudly: if the text the model wants to replace does not match the file exactly, the edit is rejected, and the agent has to re-read and retry.
In VS Code, edits appear in the editor as pending changes with a diff view. You keep or undo them, which the chapter on reviewing changes covers. Edits are tracked, so an undo restores the earlier state. Do not rely on this alone. Commit before a large task so Git is your checkpoint.
Failure modes:
- Whitespace and match errors. A replacement fails because of tabs versus spaces or a line the model remembered slightly wrong. The agent normally retries after re-reading.
- Over-wide edits. The agent reformats a whole file or touches unrelated code. Constrain it in the prompt ("change only
createUser") and check the diff. - Edits to protected files. Generated output, lock files, and vendored code should not be edited by hand. State this in your instructions file.
- Out-of-workspace paths. Editors usually ask for extra confirmation before the agent edits files outside the open workspace or sensitive files. Treat that prompt as a real decision.
Terminal tools
The terminal tool runs a shell command and returns its output, often with the exit code. This is what lets the agent verify its own work. It can install dependencies, compile, run tests, start a linter, or run a script.
A prompt that takes advantage of this names the command, so the agent has something to check itself against:
Fix the failing test in src/users.test.ts.
Run `npm test -- src/users.test.ts` to reproduce the failure first,
then change the code, then run the same command again and confirm it passes.
Do not edit the test.Terminal use has the highest risk of the four categories, because a shell command can do anything your user account can do. Commands usually require confirmation. The details of approval are covered in the next chapter.
Practical points:
- Output is truncated or summarized. Very long test logs may be cut. The agent can then misread a failure. Ask it to re-run a single failing test for a clean log.
- Long-running processes. A dev server never exits. Editors typically let the agent start it in the background and read its output later. If the agent hangs waiting for a command that does not return, stop it and run the command yourself.
- Interactive prompts. A command that waits for input, such as a
y/nquestion, may stall. Prefer non-interactive flags, for examplenpm ciovernpm installin a clean checkout, or--yeswhere a tool supports it. - Environment mismatch. The terminal may use a different shell, Node version, or virtual environment than yours. If a command works for you but not for the agent, compare
which nodeorwhich pythonin both. - Side effects. A script that deletes files, publishes a package, or calls a production API will run if approved. Read the command, not just the agent's explanation of it.
Other tools you may see
Beyond the four categories, editors often include a few more built-in tools:
- Fetch retrieves a web page, which is useful for documentation. The page content becomes part of the context, so a hostile page can contain text meant to steer the agent. The safety chapter returns to this.
- Test runner tools run a test suite and return structured results.
- Usages tools find references to a symbol using the language server, which is more precise than text search.
- Task and notebook tools run configured VS Code tasks or edit notebook cells.
Further tools come from extensions and from MCP servers, which a later chapter covers.
Choosing which tools are available
You do not have to leave every tool on. In VS Code, the tools picker in the chat view lets you enable or disable tools for a session. Fewer tools has two benefits:
- Safety. If a task only needs analysis, turn off edit and terminal tools. The agent then cannot change anything.
- Accuracy. Each tool's description consumes context, and a very long list makes the model more likely to pick the wrong one. Editors often cap the number of tools per request.
A good habit is to match the toolset to the task. For "explain how auth works", search and read are enough. For "add validation and run the tests", you need edit and terminal as well.
Exercise
You want the agent to explain how login sessions are created, without any risk of changing your code. Which categories of tools should stay enabled, which should you disable, and what would you name in the prompt to start the search?
Show answer
Keep search and read tools enabled. Disable edit and terminal tools, so the agent cannot change files or run commands. In the prompt, ask it to use workspace search (for example #codebase in VS Code) or text search for terms like session, so it starts from the relevant code instead of guessing.
Exercise
The agent reports that a test now passes, but you suspect it never ran the tests. Which tool category gives you evidence, and what would you look for?
Show answer
The terminal tool. Look in the chat's tool-call log for a test command such as npm test and check its output and exit status. If no terminal call appears, the agent only reasoned about the result. Ask it to run the command and show the output.