So Agent mode is the default mode that's typically
selected when you open a new chat, at least at the point of time where I'm
recording this. And Agent mode is basically an enhanced version of the
mode because in this mode, it'll not just analyze your code
and answer questions, but instead, it will also
actively edit your code. You can always revert those changes and
you'll see in detail what was changed, but it will make
changes. So if I open a new chat by clicking the
plus here or using the shortcut, and I say analyze
this demo.py file and identify
potential improvements, despite my
prompt, it will actually not just identify
also try to implement them because that's implied if you're in Agent
mode, that you wanna make changes to your code.
And of course, I could have therefore also worded this
about my intent and say, "Analyze this demo file,
identify potential improvements, and
implement those improvements." But that's technically not needed.
You just still might wanna do this to be very sure that it will
actually edit your code. You
could also include more detailed instructions like, "Keep the
overall code clean and simple and avoid
unnecessary abstractions." Because depending on your
project and the kind of change you're requesting, the AI might wander
off and come up with unnecessary complex solutions, so
adding extra instructions or constraints like this can make sense.
But I'll get back to my cursor prompting guide a little bit later
anyways. So for now, I'll just hit enter.
Again, it'll find this file because it knows
It analyzes this file, it reads it, it then thinks about it,
and then it goes ahead, makes a plan, and will then also
edit the code. So here we go. It's now editing demo.py as you
can see here. And then once it's done, if I shrink
that, well, it's not fully done yet. Now it's done.
It gives me a summary here telling me what it did, so which
improvements were implemented through which I can read.
But as you see here in the code file, there's a lot of red and
green here because it will actually show you what was
removed, this code was removed, for example, and what was
added. So in this case, it removed the old
function and replaced it with a new one that has a
comment here and that most importantly has error
handling, handling file-related errors.
And it added something like this to all these functions.
It also added a main function then to give me a nice menu
which allows me to choose which option I wanna go for, write,
append, and edit the code for executing this main
execute this file. And what you can do now in this mode
go through these changes either by scrolling or by clicking
these arrows here. That will get you to the right
place. And then for each change, you can undo it or
keep it, depending on what you wanna do.
Or you can keep them all or undo them
all. You can also make edits here. So if I want to add
a third parameter here, like the mode, which by default should be
W for write, for example, I can do that.
You can edit this and if you would click keep now, your
edit is also kept. So you can make edits
to these suggested changes. You don't just have to either accept or
reject them, you can tweak them as well.
That's very important and that's something many people miss.
Now here I'll get rid of the mode, therefore this brings me back into this
mode, but I'll still keep this. Now this adjusted
originally suggested version. But I don't wanna do this for all these
blocks. I'm happy with the overall changes,
here or also here. Keep
all, undo all. The difference is that certain
changes might affect multiple files.
Here, it's all just in one file, but later we'll see examples
with multiple files and then here you would be undoing or
accepting for that one file in which you currently are.
Whereas here on the right, you always undo or accept changes for
all the files that were added. But here it's only one file, so it's the
same. Therefore, I'll accept all the changes for all files
clicking this button over here.