Agent Mode

60 min intermediate Lesson 7

Learning Outcomes

  • Understand what Agent mode is and how it differs from Chat and inline editing
  • Enable and configure Agent mode in Cursor settings
  • Give effective task descriptions that lead to successful autonomous execution
  • Review, approve, and reject agent-proposed actions
  • Know when to use Agent vs Chat vs inline editing for different tasks

Lesson Plan

Segment Duration Topic
Intro 5 min What autonomous coding agents are and why they matter
Demo 1 10 min Enabling agent mode and giving your first task
Demo 2 10 min Watching the agent plan and execute steps
Explain 8 min Reviewing actions — approve, reject, modify
Demo 3 10 min Complex multi-file task with agent
Demo 4 8 min When to use Agent vs Chat vs inline
Explain 4 min Safety and limitations
Wrap-up 5 min Best practices and key takeaways

Before You Begin

Pre-work:

  • Complete Lesson 6 — Custom Rules & .cursor/rules
  • Have a project with multiple files (at least 5-10 source files)
  • Ensure you're on Cursor Pro or Business plan (Agent mode availability may depend on your plan)
  • Familiarise yourself with Cursor's AI side pane (Cmd+L / Ctrl+L)

Shopping List:

  • A project open in Cursor with a clear task you want to accomplish (e.g., "add a new feature", "refactor this module")
  • Git initialised with a clean working tree (so you can easily revert if needed)
  • The AI side pane visible (View > Chat or Cmd+L / Ctrl+L)

1 What Cursor Agent Mode Is

Agent mode is Cursor's autonomous execution mode. Instead of answering questions or making single edits, the agent plans a series of steps and executes them independently — creating files, editing code, running terminal commands, and reading project context.

The difference between modes:

Mode Who drives Scope Human involvement
Inline (Cmd+K) You Single edit, one location You type the instruction, accept/reject result
Chat (Cmd+L) Collaborative Q&A, one suggestion at a time You ask, AI answers, you apply manually
Agent AI drives Multi-step, multi-file You give a goal, AI plans + executes, you approve

What the agent can do:

  • Read files across your project to understand context
  • Create new files and directories
  • Edit existing files (multiple files in sequence)
  • Run terminal commands (build, test, install packages)
  • Search your codebase for relevant code
  • Iterate on its own work (run tests, see failures, fix them)

What the agent cannot do:

  • Access external services (APIs, databases) unless via terminal commands
  • Make decisions that require business context it doesn't have
  • Guarantee correctness — it can introduce bugs like any developer
  • Push to git or deploy (these require your explicit action)

Mental model:

Think of Agent mode as a junior developer who:

  • Is very fast at typing and searching
  • Follows instructions literally
  • Needs clear goals but can figure out implementation steps
  • Should have their work reviewed before merging
NOTE
How It Works
When you enable Agent mode and give it a task, the AI creates an internal plan (which it may share with you) and then executes steps one by one. After each step, it evaluates whether the goal is met or more steps are needed. You can intervene at any point to redirect, approve, or stop.

2 Enabling and Configuring Agent Mode

Agent mode is accessed through the AI side pane with a specific mode selection.

Enabling Agent mode:

  1. Open AI side pane: Cmd+L
  2. At the top of the AI side pane, look for the mode selector (dropdown or toggle)
  3. Switch from "Chat" to "Agent" (or "Agent Agent" depending on your Cursor version)
  4. The panel will indicate you're in Agent mode — you'll see a different input area or indicator

Alternatively, open Agent mode directly with Cmd+I and select Agent mode from the dropdown.

  1. Open AI side pane: Ctrl+L
  2. At the top of the AI side pane, look for the mode selector (dropdown or toggle)
  3. Switch from "Chat" to "Agent" (or "Agent Agent" depending on your Cursor version)
  4. The panel will indicate you're in Agent mode — you'll see a different input area or indicator

Alternatively, open Agent mode directly with Ctrl+I and select Agent mode from the dropdown.

Configuration options:

In Cursor Settings (Cmd+, / Ctrl+,), search for "Agent" to find relevant settings:

  • Auto-run terminal commands — Whether the agent can execute terminal commands without asking first (recommended: keep this OFF initially, so you approve each command)
  • Auto-apply edits — Whether file edits are applied immediately or shown for approval
  • Model selection — Which AI model powers the agent (newer models tend to be better at multi-step planning)

Recommended initial configuration:

For beginners:

Auto-run commands: OFF (review each terminal command before it runs)
Auto-apply edits: OFF (review each file edit before it's applied)

As you gain confidence:

Auto-run commands: ON for safe commands (tests, builds), OFF for installs/destructive commands
Auto-apply edits: ON (trust the agent more, revert via git if needed)
WARNING
Watch Out
If you enable auto-run for terminal commands, the agent could install packages, modify configuration files, or run scripts without your approval. Start with manual approval until you trust the agent's behaviour in your project.
TIP
Tip
Before starting an agent task, make sure your git working tree is clean (commit or stash changes). This gives you a safety net — if the agent makes a mess, you can git checkout . to revert everything.

3 Giving Agent Tasks and Watching It Work

The quality of your task description directly impacts the quality of the agent's output. Here's how to write effective agent prompts.

The anatomy of a good agent task:

[GOAL]: What you want to achieve (the "what")
[CONTEXT]: Relevant details about your project (the "where/why")
[CONSTRAINTS]: Rules or limitations (the "how" boundaries)
[SUCCESS CRITERIA]: How you'll know it worked (the "done" definition)

Example — good task description:

Create a user registration form component.

Context:
- This is a Next.js 14 project with TypeScript
- We use React Hook Form for forms and Zod for validation
- Existing form components are in src/components/forms/

Requirements:
- Fields: name, email, password, confirm password
- Validate: email format, password min 8 chars, passwords match
- On submit, call the API at /api/auth/register
- Show inline validation errors under each field
- Show a success message or error toast after submission

Follow the patterns in src/components/forms/LoginForm.tsx for styling and structure.

Example — poor task description:

Make a signup form

(This lacks context about tech stack, validation needs, file location, and design expectations.)

Watching the agent work:

Once you submit a task, the agent will:

  1. Plan — It may outline steps it intends to take
  2. Read — It reads relevant files in your project for context
  3. Execute — It creates/edits files, one at a time
  4. Verify — It may run tests or check for errors
  5. Report — It tells you what it did and what's next

You'll see each step in the AI side pane. Depending on your settings, you may need to approve each action.

What a typical agent execution looks like:

Agent: I'll create the registration form. Here's my plan:
1. Read LoginForm.tsx to understand the existing pattern
2. Create RegistrationForm.tsx with form fields
3. Create a Zod validation schema
4. Add the API call handler
5. Add the component to the page

Step 1: Reading src/components/forms/LoginForm.tsx...
[Shows file content]

Step 2: Creating src/components/forms/RegistrationForm.tsx...
[Shows proposed file content — awaiting your approval]
TIP
Tip
Reference existing files in your task description. Saying 'follow the pattern in LoginForm.tsx' is much more effective than describing the pattern in words. The agent will read that file and match its structure.
NOTE
How It Works
The agent maintains a 'scratchpad' of its progress. It remembers what it's done, what files it's read, and what's left to do. This is why multi-step tasks work — the agent has internal state across steps.

4 Reviewing Agent Actions — Approve, Reject, Modify

Reviewing agent output is a critical skill. The agent works fast, but you're responsible for the code that enters your project.

The review interface:

When the agent proposes a file edit or new file:

  • You see a diff view (green = additions, red = deletions)
  • You can Accept to apply the change
  • You can Reject to skip it and tell the agent why
  • You can Modify by accepting then editing manually

When the agent proposes a terminal command:

  • You see the command it wants to run
  • You can Allow to let it execute
  • You can Deny to block it

What to look for when reviewing:

Check What to Look For
Correctness Does the logic actually do what you asked?
Conventions Does it follow your .cursor/rules and project patterns?
Completeness Is anything missing? Edge cases? Error handling?
Security Any hardcoded values, missing validation, exposed data?
Dependencies Did it import anything new? Is that acceptable?
Scope Did it change more than you expected? Unrelated modifications?

Redirecting the agent:

If the agent goes in the wrong direction, interrupt it:

You: Stop. That approach won't work because we need to support
pagination. Instead of fetching all users at once, use the
usePaginatedQuery hook from src/hooks/usePaginatedQuery.ts.
Continue with that approach.

The agent will adjust its plan and continue.

Partial acceptance:

Sometimes the agent gets 80% right:

  1. Accept the proposed changes
  2. Make manual adjustments to the parts you want different
  3. Tell the agent: "I've accepted and modified the RegistrationForm. The validation schema needs an update — add a check that the email domain is not from disposable email providers. See our existing validation helpers in src/lib/validation.ts."

When to reject and start over:

  • The agent's approach is fundamentally wrong (wrong architecture pattern)
  • It's modifying files you didn't want touched
  • The output is so far from what you need that fixing it is harder than starting fresh

To start over: reject the pending changes, start a new agent conversation, and provide a clearer task description with more constraints.

WARNING
Watch Out
The agent may modify files beyond what you expect. If you ask it to 'add a feature to the user page', it might also modify route files, add imports to index files, or create utility functions. Review ALL proposed changes, not just the main file.
TIP
Tip
Use git diff after the agent completes its work. This gives you a complete picture of everything that changed, even if you approved steps individually without noticing cumulative changes.

5 When to Use Agent vs Chat vs Inline

Choosing the right mode for the task saves time and produces better results.

Use Inline (Cmd+K / Ctrl+K) when:

  • You know exactly where the change goes (one location, one file)
  • The change is small: rename a variable, add a parameter, refactor a function
  • You can describe the change in one sentence
  • Examples: "Add error handling to this function", "Convert this to TypeScript", "Add a loading state"

Use Chat (Cmd+L / Ctrl+L) when:

  • You need to discuss or explore before implementing
  • You want explanations alongside code suggestions
  • You want to compare approaches before committing
  • The task is conversational: "How should I structure this?", "What's the best way to handle X?"
  • Examples: "Explain this code", "What are my options for state management here?", "Help me debug this"

Use Agent when:

  • The task spans multiple files
  • You need files created, imports added, tests written — as a coordinated set
  • The task has multiple steps that build on each other
  • You can clearly describe the end goal but not every implementation step
  • Examples: "Build the entire CRUD for this resource", "Refactor this module into smaller files", "Add authentication to all API routes"

Decision matrix:

Task Best Mode Why
Fix a typo Inline One change, one location
Add a prop to a component Inline Small, localised change
Understand an error Chat Discussion, explanation needed
Compare two approaches Chat Exploration, not execution
Create a new feature with 3+ files Agent Multi-file coordinated creation
Refactor a module into pieces Agent Many files change in concert
Add tests for an existing module Agent Reads module, creates test file, runs tests
Set up a new API route with validation Agent Route + schema + handler + test

Combining modes in a workflow:

A real workflow might use all three:

  1. Chat: "How should I structure a notification system for this app?" (AI suggests an approach with stores, components, and API hooks)

  2. Agent: "Implement the notification system as discussed. Create the store, the NotificationToast component, and the useNotifications hook." (Agent creates 4-5 files)

  3. Inline (Cmd+K): Select a line in the generated code and say "Also handle the case where notifications are disabled in user settings" (Quick targeted edit to one function)

NOTE
How It Works
Each mode uses the same underlying AI model but with different system prompts and capabilities. Agent mode has access to file system operations and terminal commands. Chat mode has access to your selected code and referenced files. Inline mode has tight focus on the surrounding code context.
TIP
Tip
Start with a smaller scope than you think. Instead of 'build the entire feature', try 'create the database schema and API routes for user profiles'. You can always give the agent another task for the frontend. Smaller, focused tasks produce better results.

6 Complex Multi-File Tasks with Agent

Agent mode truly shines on complex, coordinated tasks that would take many manual steps. Here are patterns for common multi-file tasks.

Pattern 1: Feature scaffolding

Create a complete "Blog Posts" feature with:
1. Prisma schema for a Post model (title, content, slug, published, authorId, createdAt, updatedAt)
2. API routes: GET /api/posts (list), GET /api/posts/[slug] (detail), POST /api/posts (create), PUT /api/posts/[id] (update), DELETE /api/posts/[id] (delete)
3. Zod validation schemas for create and update
4. React Query hooks for each endpoint
5. A basic PostList page component and PostDetail page component

Follow existing patterns in the "Users" feature (src/features/users/).

Pattern 2: Refactoring

Refactor src/components/Dashboard.tsx (currently 450 lines) into smaller components:
1. Extract the stats cards section into DashboardStats.tsx
2. Extract the activity feed into DashboardActivity.tsx
3. Extract the charts section into DashboardCharts.tsx
4. Keep Dashboard.tsx as the layout container that composes these pieces
5. Move shared types into a types.ts file in the same directory
6. Ensure all existing functionality is preserved

Do not change any styling or behaviour — this is a pure structural refactor.

Pattern 3: Adding cross-cutting concerns

Add error boundary and loading states to all page components in src/app/:
1. Create a reusable ErrorBoundary component in src/components/common/
2. Create a PageSkeleton loading component
3. Wrap each page in src/app/(main)/ with the ErrorBoundary
4. Add Suspense boundaries with PageSkeleton as fallback
5. Test by adding a temporary throw in one page to verify the boundary catches it

Reference the Next.js 14 error.tsx and loading.tsx conventions.

Pattern 4: Test generation

Generate comprehensive tests for src/lib/pricing.ts:
1. Read the file and understand all exported functions
2. Create src/lib/pricing.test.ts
3. Test each function with:
   - Happy path cases
   - Edge cases (zero, negative, very large numbers)
   - Error cases (invalid input types)
4. Use Jest with the existing test configuration
5. Run the tests and fix any failures

Target: 90%+ line coverage for this file.

Tips for complex tasks:

  • Number your requirements — the agent follows numbered lists more reliably than prose
  • Reference existing code — "Follow the pattern in X" is your most powerful tool
  • Define boundaries — "Only modify files in src/features/posts/" prevents scope creep
  • Include success criteria — "Run the test suite and ensure all tests pass" gives the agent a verification step
  • Break mega-tasks into phases — If you need 20 files changed, do it in 2-3 agent sessions of 5-8 files each

After the agent completes:

  1. Run git diff to see all changes in one view
  2. Run your test suite to verify nothing broke
  3. Run your linter to catch style violations
  4. Do a manual review of the key logic files
  5. Commit if satisfied, or ask the agent to fix specific issues
WARNING
Watch Out
Agent mode can generate a lot of code quickly. Resist the urge to approve everything without reading it. Schedule 5-10 minutes for review after each agent session. Bugs introduced by agents are often subtle — tests pass but behaviour is slightly wrong.
TIP
Tip
After a successful agent task, save your prompt for future use. Good prompts are reusable templates: 'Create a complete CRUD feature for [resource] following the pattern in [existing feature].' Keep a prompts.md file in your project for your team to reference.

Questions & Answers

Q: Can the agent access the internet or external services?
The agent cannot browse the web directly. However, it can run terminal commands — so if you have a CLI tool installed (like curl or an API client), it could technically invoke those. Most agent tasks are focused on reading and writing files within your project. For documentation lookups, use @docs or references in your prompt instead.
Q: What happens if the agent makes a mistake partway through a multi-step task?
You can interrupt at any time by rejecting a proposed action or typing a correction. The agent will adjust its plan. If the mistake has already been applied, you have two options: tell the agent to fix/revert it, or use git to revert the changes yourself. This is why starting with a clean git state is so important — you always have a safe rollback point.
Q: Does the agent remember context from previous agent sessions?
Each agent session (conversation) is independent. The agent doesn't remember what it did yesterday. However, within a single session, it maintains full context of all steps taken. If you need to continue work from a previous session, start a new session and briefly describe what was already done: "In a previous session, I created the Post model and API routes. Now I need the frontend components."
Q: How do I handle agent mode with large codebases where it can't read everything?
Be explicit about which files the agent should read. Instead of hoping it finds the right context, tell it: "Read src/features/users/ for the pattern to follow. The database schema is in prisma/schema.prisma. The shared types are in src/types/." This directed reading is much more reliable than letting the agent search a 10,000-file codebase on its own.

Key Takeaways

  1. Agent mode is autonomous multi-step execution — give it a goal, it plans and executes
  2. Start with manual approval — review each action until you trust the agent's patterns
  3. Write clear task descriptions — include goal, context, constraints, and success criteria
  4. Always start with a clean git state — your safety net for reverting agent mistakes
  5. Choose the right mode — inline for small edits, chat for discussion, agent for multi-file coordination
  6. Review everything — run git diff, tests, and linter after every agent session

Next Steps: In Lesson 8 — Workspace Management, you'll learn how to organise large projects in Cursor and use AI-enhanced bulk operations for efficient editing.