Sub topic 1
What agent mode is and when it helps
Prerequisites
This chapter assumes you can edit and run a project in an IDE such as VS Code. It also assumes you know basic Git (commits, diffs, branches), can run build or test commands in a terminal, and have used an inline or chat-based AI coding assistant before.
What agent mode is
Agent mode is a chat mode in which an AI assistant works on a multi-step coding task for you. You describe a goal. The agent breaks it into steps, reads and edits files, runs terminal commands, and checks the results. It keeps going until it decides the task is done or it needs your input.
A plain chat assistant answers a question and stops. An agent acts on your workspace, looks at what happened, and adjusts. That feedback loop is the main difference, and a later chapter covers it in detail.
What the agent can do
In VS Code with GitHub Copilot, the agent typically has access to these kinds of tools:
- Search the workspace and read files.
- Create and edit files across the project.
- Run terminal commands such as builds and tests.
- Read command output and errors, then react to them.
- Call extra tools provided by MCP servers (covered in a later chapter).
Exact tool names and defaults vary by editor and version. Check your IDE's documentation for the current list.
When agent mode helps
Agent mode fits tasks that touch several files or need command output to finish. Good candidates:
- Adding a feature that spans a function, its tests, and a config file.
- Fixing a failing test, where the agent runs the test, reads the error, edits the code, and runs it again.
- Mechanical changes across many files, such as renaming an API or updating imports.
- Scaffolding a small module that follows existing project patterns.
It helps less when:
- You only need an explanation or a quick answer. Ask mode is cheaper and safer.
- The change is one small edit in one place. Doing it yourself or using inline suggestions is faster.
- The task has no way to be checked, such as a vague design question. The agent has nothing to verify against.
- The work is risky and hard to reverse, such as production data or deployment steps.
A first look at the workflow
The diagram shows the overall shape of an agent session.
You stay in control at two points: when you approve tool calls such as terminal commands, and when you review the final edits.
A task the agent handles well
This prompt states a goal, a 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 npm test step gives the agent a way to check its own work. It can edit, run the tests, read failures, and fix them without you relaying each result. Writing prompts like this is the subject of a later chapter.
Common mistakes
- Using agent mode for a question that ask mode would answer.
- Giving a goal with no way to verify it, then trusting the result.
- Starting with uncommitted changes, which mixes your edits with the agent's.
- Approving every tool call without reading it.
Exercise
You want to know why a regex in your code matches too much. You also want to rename a function used in 40 files and have the tests run afterward. Which task suits agent mode, and why?
Show answer
The rename suits agent mode. It spans many files and ends with a test run the agent can use to verify its work. The regex question only needs an explanation, so ask mode is enough.
Exercise
Name two things to do before starting an agent session so you can undo its changes easily.
Show answer
Commit or stash your current work, and create a new branch for the task. Then the agent's edits show up as a clean diff you can review or discard.