Guide
AI Coding Workflow for Python
A Python AI coding workflow should name the runtime, dependency boundary, test command and style convention before the agent writes code. When something fails, hand the agent the real traceback instead of a description of it. Agents write plausible Python, so review imports, edge cases, typing and behavior before you accept it.

On this page
- What does a reviewable agent task look like?
- How should a team run each agent task?
- What should you keep after the run?
- What's the fastest debug loop in a Python notebook?
- Why does my import fail in the notebook but not the shell?
- Which part of the standard workflow doesn't work in a notebook?
- Why does the runtime line matter more in Python than in other stacks?
- How long can a Python debugging session run before it degrades?
What does a reviewable agent task look like?
Give the agent one named task, only the context it needs and a check you can rerun. A task shaped this way produces a diff small enough to review and a result you can repeat.
- Move
- Start with a bounded task
- Use this when
- You have a named owner, target files and a clear done state
- Proof to save
- Issue, files, checks and owner are named
- Move
- Give the agent context
- Use this when
- The repo has patterns the agent must follow
- Proof to save
- Prompt cites files, errors and constraints
- Move
- Review the diff
- Use this when
- The task changes production code
- Proof to save
- Changed files, test output and risks are visible
| Move | Use this when | Proof to save |
|---|---|---|
| Start with a bounded task | You have a named owner, target files and a clear done state | Issue, files, checks and owner are named |
| Give the agent context | The repo has patterns the agent must follow | Prompt cites files, errors and constraints |
| Review the diff | The task changes production code | Changed files, test output and risks are visible |
Each move leaves proof that a reviewer can check later.
Each move fails in its own way. Without a boundary, the agent edits files you never meant to open, and the diff becomes hard to read. Thin context fails more quietly: the code compiles and the tests pass, but the change ignores patterns the rest of the repo follows. Without a check you can rerun, you are taking the agent's word that the work is done.
Asking for a plan before the agent writes code is the easiest step to skip. It means a short wait while nothing visible happens, and the price of skipping it shows up later, in review.
If the plan names files you didn't expect, you learn that before any code exists. If it names the right files, you have a list to check the diff against. Once four hundred lines of diff are on screen, changing the approach means throwing that work away.
Interactive widget. Tab through its controls; the result updates in the panel below as you change them.
Pick your role, stack and task type before you write a prompt.
This is covered hands-on in Cursor First Hour — 4 short Units, free to read.
How should a team run each agent task?
The habit that matters most for a team is leaving a trail the next reviewer can follow. The steps below keep the prompt and its proof attached to the change.
- 1Pick one real backlog item with a clear owner and expected result.
- 2Add only the context the agent needs: files, failing output, constraints and done state.
- 3Ask for a plan before code when the task touches more than one file.
- 4Run checks that match the risk: unit test, typecheck, visual pass or review checklist.
- 5Capture the prompt, diff, result and reviewer note so the workflow can be repeated.
Match the effort to the change. A one-file fix needs a clear done state and a typecheck, and a plan adds little. A change across several files is where a plan pays for itself, and where the check should include tests and a reviewer who knows that code.
What should you keep after the run?
Keep whatever lets someone rerun the work or pick it up later. A finished task is the merged code plus a short trail that shows how it got there.
- The prompt or plan that shaped the work.
- The files changed and the reason each file changed.
- The command, screenshot or review note that proved the result.
- The rule, checklist or template you would reuse next time.
The last item pays off over time. A rule or template saved from one good run means the next run starts from what already worked, not from a blank prompt.
What's the fastest debug loop in a Python notebook?
Hand the agent exactly what you ran. Copy the failing cell or its error output and use Add to Chat, so Cursor sees the real code and the real traceback instead of your paraphrase. The presenter of Cursor's data-science webinar called it the most effective habit for finding where an issue happens. Terminal errors work the same way: copy the error, add it to chat and ask. You can't always copy a notebook's rendered output straight into Cursor, so copy the whole cell instead.
We always say at Cursor that like context is king.
Why does my import fail in the notebook but not the shell?
The cause is almost always the environment. A common case is pandas import could not be resolved or matplotlib not installed, because the package is installed in your system Python but not in the virtual environment the notebook uses. Add the error to chat, and the agent finds the root cause, installs the package into the virtual environment and checks the import itself. When the presenter set up the environment, Cursor asked whether to install into a virtual environment or the project, and the presenter chose the virtual environment.
Pandas exists in my system Python, but not in my virtual environment, which is what the notebook is using... because Python is such a popular language, a lot of the models have been trained on Python.
Which part of the standard workflow doesn't work in a notebook?
The check step. In Cursor's data-science webinar, the agent wrote and edited notebook cells well but couldn't reliably run them, so the presenter ran the cells by hand. Any workflow that ends with "run the check and read the output" assumes the agent can close its own loop, and in that notebook it couldn't.
That changes the size of the task you should hand over. If you are the one running cells, a ten-cell rewrite means ten manual runs before you know whether any of it worked. So the done state has to name the cell you will run and what you expect to see when you run it.
The presenter thought someone might have built an MCPModel Context Protocol. A standard that lets an AI agent pull in context from outside the repo, like Jira tickets or internal docs. Press Enter for the full definition. server that runs cells, but hadn't found one. Plan the loop around running cells by hand.
Why does the runtime line matter more in Python than in other stacks?
Because two of the first errors you hit come from the environment, not the logic. One is the notebook import failure above. The other is a hard-coded path that a notebook brings with it from the machine it was written on. Neither is a logic mistake, but both show up as errors in your code.
So state the interpreter first, and choose it on purpose instead of taking the default. A virtual environment keeps the notebook's dependencies reproducible, and choosing it up front prevents the same import error the next time someone opens the file.
In the webinar, a "no such file or directory" failure turned out to be a path hard-coded from wherever the notebook was first written. Agent modeCursor's full-capability mode: the AI can read the codebase, write and edit files, move them and run terminal commands. Contrast with Ask mode, which is read-only. Press Enter for the full definition. rewrote the path to detect whether it was running locally or in the original location, and to resolve it relative to the notebook.
How long can a Python debugging session run before it degrades?
Watch the context ring next to your prompt input. In the same webinar, the presenter saw a slower agent and weaker answers once the window passed roughly 70 to 80%.
Notebook debugging gets there faster than service work, because every traceback and every cell you hand over adds up. The habit that makes the debug loop work, handing over the real cell and the real traceback instead of your description of them, is the same habit that fills the window. So add only the context the agent needs: the failing cell and its traceback, not the cells around it.
Frequently asked questions
Who is this guide for?
Python backend, data and automation teams, including people who debug in notebooks.
What should I do next?
Write the interpreter, test command and dependency boundary into your next prompt. When something fails, add the failing cell or traceback to chat exactly as it ran, and name the cell you will run to check the fix.
Why does an import fail in my notebook but work in the shell?
The notebook and the shell are running different interpreters. The package is installed in your system Python but not in the virtual environment the notebook uses. Add the error to chat, and the agent can install the package into that environment and check the import.
What should I paste into chat when Python code fails?
The failing cell or the terminal error, exactly as it ran, so the agent sees the real code and the real traceback. If you can't copy a notebook's rendered output, copy the whole cell. Leave out the cells around it, because every traceback adds to the context window.
Can Cursor run notebook cells for me?
Plan as if it can't. In Cursor's data-science webinar, the agent wrote and edited notebook cells well, but the presenter ran the cells by hand. Make the done state name the cell you will run and the output you expect to see.
Sources & last verified
- Cursor agent best practices
- Cursor Learn: working with agents
- Cursor Learn: context
- Cursor docs: prompting agents
Cursor ships frequently. Facts verified against primary sources on October 28, 2026.