Sub topic 1
What agent mode is and when it helps
Agent mode is a chat mode in your editor where an AI assistant works toward a goal over many steps. You describe the outcome. The agent searches your code, reads files, edits them, runs terminal commands, looks at the results, and keeps going until it decides the task is done or it needs your input. This chapter defines the idea, shows where it fits, and gives you criteria for choosing it.
Prerequisites
This chapter assumes you already have the following:
- You are comfortable editing and running projects in an IDE such as VS Code.
- You know basic Git: commits, diffs, and branches.
- You can use the terminal and run build or test commands.
- You have used an inline or chat-based AI coding assistant at least a few times.
You do not need to know anything about agents, tool calling, or MCP. Later chapters cover those.
What agent mode is
A normal chat assistant answers a question with text. You then copy the answer, paste it into a file, run the code, and report any error back to the assistant. You are the connection between the model and your project.
Agent mode removes you from that middle position. The model is given tools it can call. Examples are searching the workspace, reading a file, editing a file, and running a terminal command. The editor runs those tools on the model's behalf and returns the output. The model reads that output and decides what to do next.
Three properties set agent mode apart:
- Multi-step. One request can produce dozens of tool calls across many files.
- Autonomous within limits. The agent chooses which files to open and which commands to run. You still approve sensitive actions, such as terminal commands.
- Self-checking. The agent can run your tests or build and read the failures. It can then fix its own mistakes without you pasting error messages.
The product names differ between editors. In VS Code with GitHub Copilot it is called agent mode. Other editors use similar names for the same pattern. The behavior described here is the common core.
A first look at the flow
The diagram shows one request. Notice that the loop between the agent and its tools repeats until a stop condition is met.
The final step matters. The agent finishing does not mean the work is correct. Reviewing the result is still your job, and a later chapter covers it in detail.
When agent mode helps
Agent mode pays off when the task has these traits:
- It touches several files. Renaming a concept, adding a field through a model, an API, and its tests, or migrating a usage pattern.
- It needs discovery. You do not know which files are involved, so the agent must search first.
- It has a check the agent can run. A test suite, a type checker, a linter, or a build gives the agent feedback it can act on.
- It involves routine work. Scaffolding, boilerplate, test writing, and mechanical refactors are tasks where a wrong guess is cheap to spot.
- It spans code and commands. For example, install a dependency, update the code that uses it, and run the tests.
Here is a prompt that fits well. It states the goal, the location, acceptance criteria, a verification step, and a constraint:
Add input validation to the createUser function in src/users.ts.
Reject empty names and malformed email addresses with a clear error.
Add unit tests for both cases next to the existing tests, then run `npm test` and fix any failures.
Do not change the public function signature.The agent can locate createUser, read the existing tests to copy their style, make the edits, run npm test, read any failures, and repeat. The sentence "run npm test and fix any failures" is what turns this from a one-shot edit into a loop with a built-in check.
When it does not help
Agent mode is not the best tool for every request. Avoid or limit it in these situations:
- You only need an explanation. Asking how a function works does not require edits or commands. A simpler mode is faster and cannot change your files.
- The change is one small edit. If you know the exact line, typing it is quicker than describing it.
- The goal is vague. "Make this better" gives the agent nothing to check against, so it may make many unrequested changes.
- There is no way to verify. Without tests or a build, the agent cannot detect its own errors. You then carry the whole verification cost.
- The work is high risk. Production credentials, database migrations against real data, or deployment scripts need much tighter control than a default agent session offers.
- The task needs knowledge the agent cannot see. Decisions that depend on a conversation, a business rule outside the repository, or a private service may lead it to guess.
Costs and trade-offs
Agent mode trades your effort for other costs.
| Cost | What it means in practice |
|---|---|
| Review effort | A multi-file diff takes longer to read than a single suggestion. Large diffs hide small mistakes. |
| Latency | Many tool calls and model turns mean a task can take minutes, not seconds. |
| Usage | Each step consumes model capacity. Depending on your plan, long sessions may count against limits. |
| Blast radius | The agent can edit many files and run commands, so a bad plan can do more damage than a bad suggestion. |
| Context drift | In long sessions the agent can lose track of earlier instructions or details. |
None of these rule out agent mode. They explain why the rest of this tutorial covers context, approvals, instructions files, and review practices. Each one reduces one of these costs.
A quick decision guide
Ask these questions before you start a request:
- Do I need files changed or commands run, or only an answer? If only an answer, use a read-only mode.
- Can I name a check, such as a test or a build, that proves the work is correct? If yes, agent mode is a strong fit.
- Is the change spread over several files, or hard to locate? If yes, agent mode saves you the search.
- Is my Git working tree clean, so I can see exactly what the agent changed? If not, commit or stash first.
The next chapter compares ask, edit, and agent modes so you can make this choice precisely.
Summary of the key ideas
- Agent mode is a multi-step, tool-using mode. The model plans, calls tools, reads the results, and continues.
- Its strength is tasks with several files, unknown locations, and a runnable check.
- Its weakness is vague goals, missing verification, and high-risk operations.
- You remain responsible for approving risky actions and reviewing the final changes.
Exercise
You have a project with a passing test suite. You want to rename the field userName to username in the data model, the API handlers, and the tests. Is agent mode a good fit? Name two traits of the task that support your answer and one step you should take before starting.
Show answer
Yes. The change spans several files and the agent must search to find every use, and the existing test suite gives the agent a check it can run to confirm nothing broke. Before starting, commit or stash your current work so the agent's edits appear as a clean diff that you can review or discard.
Exercise
A teammate asks the agent, "Make the checkout code better," in a repository with no tests. List two reasons this request is likely to go poorly, and rewrite it so it fits agent mode.
Show answer
The goal is vague, so the agent has no definition of "better" and may change things you did not want. There is also no test or build to verify the work, so errors will not be caught automatically. A better version: "In src/checkout.ts, extract the tax calculation in processOrder into a function named calculateTax without changing behavior. Add a unit test for calculateTax, run it, and fix any failures. Do not change the exported API."