Ir para o conteúdo

Lição 9 · Agent Mode

How the Cursor Agent Works

Understand Cursor Agent: its tools and loop, how to write tasks with clear limits, and how checkpoints, queued messages and stopping keep you in control.

Agent is the mode that does work. You describe a goal, and it can search the project, read files, edit them, run commands and react to what it sees. The documentation describes each agent as a combination of instructions (a system prompt and your rules), tools and the model you choose.

The loop

flowchart TD
  G["Your goal"] --> M["Model chooses a next step"]
  M --> T["Tool: search, read, edit or run"]
  T --> R["Result returns to the model"]
  R --> M
  M --> F["Final report to you"]

The agent repeats choose, act and observe until it decides the task is done.

This is the same idea as in What is an AI agent. "Done" is the agent's own judgment, which is why you give it a check that it can run and that you can repeat.

The tools

As of December 2026, the documented abilities include:

  • Searching files and folders by name, structure or pattern.
  • Searching the web.
  • Reading files, including common image formats.
  • Suggesting and applying edits.
  • Running shell commands in your terminal.
  • Controlling a browser, for screenshots and testing.
  • Generating images.
  • Asking you clarifying questions.

The documentation says there is no limit on the number of tool calls in a task. That is convenient, but a confused agent can spend a lot of time and usage, so watch long runs.

Write a good task

A strong agent task has these parts:

TEXT
Goal: Users can export their order list as CSV.
Context: @orders/views.py @orders/tests.py
Constraints: Standard library only. Do not change the database schema.
Done when: python -m unittest passes, including new tests for
  an empty list and a name that contains a comma.
Stop and ask me before you change a public function signature.

The last line is worth copying. It names a situation where the agent should stop instead of deciding alone. It is an instruction, not a technical lock, so you still check.

The comma test is not random. CSV code written by joining strings breaks on commas and quotes. Here is real code that shows the difference:

Python Why the acceptance test mentions commas

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

An acceptance test like this turns a vague "make it work" into a result you can verify.

Stop, steer and queue

While the agent works, you can:

  • Stop it with the Stop button or Ctrl+Shift+Backspace (Cmd+Shift+Backspace on a Mac). Stopping early is better than waiting for a wrong approach to finish.
  • Queue a message by pressing Enter while it works, so that it is handled after the current work. You can reorder queued messages.
  • Send immediately with Ctrl+Enter (Cmd+Enter), which skips the queue.
  • Steer a run with Send now (or Enter twice), so the message reaches the agent at its next tool call. In December 2026, the documentation said steering was still rolling out in the Agents Window.

Key behavior for queuing and steering differs between interfaces (the terminal product, for example, is different) and may change, so test it once in your own app with a harmless task.

The documentation also describes /goal, which sets a long-running objective, and /loop, which runs a prompt or skill again and again. Use them only with clear stopping conditions, and watch your usage. The lesson on stop conditions and budgets explains why.

Checkpoints

The agent saves checkpoints, snapshots of files it modifies, before significant changes. To go back, hover over an earlier message and use Restore Checkpoint, which rolls back later agent changes.

Know the limits:

  • Restoring reverts files; it does not delete the chat messages.
  • Checkpoints are stored locally and are separate from Git.
  • A file restore cannot undo effects elsewhere, such as a sent request or a changed database.
Python Stand-in: what a file checkpoint can and cannot undo

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

This stand-in is not the real mechanism. It shows the principle: actions outside your files need prevention, because restoring files does not undo them.

Larger work

The documentation also describes Projects, in which a coordinating agent plans a larger job and hands parts to other agents. More agents means more output to review. Start with one agent, and scale up only when you can still verify the result.

Supervise a run

You do not have to stare at the screen, but you should know the signs that a run needs you:

  • It edits files outside the area you named.
  • It installs a package you did not expect.
  • The same test fails again and again while the changes grow.
  • It starts changing tests or configuration to make errors disappear.
  • It asks to run a command with effects outside the project.

When you see one, stop the run. Read the diff so far, and decide whether to keep any of it. Then restart with a sharper instruction, such as "Do not install packages. If you need one, explain why and wait."

At the end, do not rely on the final report alone. A report can say that something was tested when only part of it was. Compare it with the evidence: the commands that actually ran, their output and the diff.

Common mistakes

  • Giving several unrelated goals at once.
  • Giving no way to check success.
  • Letting a stuck agent retry for a long time.
  • Relying on checkpoints instead of commits.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Which three things make up an agent in the documentation?

    The agent combines instructions, tools and the selected model.
  2. 2. What can a checkpoint restore?

    Checkpoints cover files. External effects are not undone.
  3. 3. Why add a stop-and-ask condition to a task?

    You name the cases where the agent should not decide alone.

Summary

  • The agent loops through choosing, acting and observing with tools.
  • State a goal, context, constraints, a check and when to stop.
  • You can stop, queue or steer while it works.
  • Checkpoints restore files only; use Git too.

Next: Plan Mode in Cursor

Seu progresso fica salvo neste navegador. Não precisa de conta.