
Start pair programming with Gemini

Yesterday Google released in preview Gemini Code Assist agent mode for VS Code powered by Gemini CLI.
Gemini code Assist agent mode enables an agentic flow in Gemini Code Assist chat in VS Code, it adds to the existing Code Assist capabilities (such as code generation, completion, understanding, transformation) the ability to perform complex tasks involving multiple steps in autonomy, directly creating or modifying multiple files, and directly running commands and code.
Gemini Code Assist agent mode also supports integration with MCP servers to extend agent abilities, and using context files to provide rules, style guides or any other additional context to the agent.
Check this page of the documentation for all the details.
In this article you will see an example of using Gemini Code Assist Agent mode with an existing application to generate documentation, add new functionality and generate and run unit tests.
- Clone the example app repository in your workstation. This is an example fictitious online bank application written in Python and using Flask and SQLAlchemy. The example app allows users to register, login, create bank accounts, make transactions (deposits or transfers) and list transactions for each account.
git clone https://github.com/ggalloro/gemini-bank.git
cd gemini-bank
- Open VS Code, and open the gemini-bank folder
- Open the Gemini Code Assist panel and click the Agent toggle to enter agent mode as shown below:
Generate a README file
- The repo doesn’t contain a readme file, let’s ask Gemini to generate one, type a prompt like this in the chat panel:
Generate a README.md file for this application that explains the application
functionalities, structure and how an user can run and use it
- The Gemini Code Assist agent will start to analyze the repository files to create the readme file. The agent uses embedded tools to read and write files and execute commands. For tool requests that modify the file system, or perform mutating operations on any resources, Gemini will ask you for permission to allow the operation before running it, in some cases you can choose to allow the operation only for one time or to always allow a tool to execute a specific operation in the current chat as in the pwd example below (you can also enable Yolo mode to always allow all agent actions):
- When Gemini completes the operation it will prompt you to review, accept or reject changes with a prompt similar to the one in the picture below.
- Click View Changes to review the README file content, it should provide info on the application, if you are happy with the content, save and close the diff file and click Accept. You will get the README.md file in the root of your repo.
Add a new function to your app
- Open the readme file and follow the steps described in it to run the application locally. The steps will typically involve the creation of a virtual environment, installation of dependencies and running the app using the command listed below in a terminal:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python app.py
- The readme file should also describe an usage flow to register a new user, login, create a new account and make transactions. Try to do that to get an idea of how the app works. You will see that you have a single button pointing to a single form to make transactions that can be of type “Deposit” or “Transfer”: the former allows you to “virtually” deposit money on your account, the latter to transfer money outside your account (but without specifying where):
- You want to improve this behavior and split the transaction function to 2 different ones each with a different route and form in order to allow money transfers to other bank users. Try to do that with the following prompt:
I want to split transactions in 2 different functions and routes:
1 - deposit where an user deposits money on one of his accounts,
2 - payment: where the user transfer money to another internal user
or to an external user.
In case of transfer to an internal user, the form should present a dropdown menu
with the account number and the account owner name
- Gemini will describe the plan to implement the changes you requested as shown below:
- Gemini will then start to implement changes, and ask you to View/Accept/Reject as done before for the readme file
- You can “blindly” accept the changes or click View Changes, review the changes, save and close the diff file and Accept them.
- Gemini will do the same for all the files requiring a change and will ask your permission if it needs to run commands that change or delete files.
- Gemini will inform you when all the changes are complete, check that now you can choose from the 2 transaction types (restart the application if has been stopped):
- To see the payment form destination dropdown populated you need to register at least a 2nd user and create an account for her:
- The above pictures are examples from an execution, your results may vary. If you get any issue, error, the result is not satisfying or you simply want to further improve it, just submit a prompt to Gemini asking that. One thing you can do, for example, is customizing the transaction description with the following prompt:
Can you change the code so when a payment is made to a destination account,
the transaction recorded in the destination account has a description like
"payment from "sender account owner" with description:
"original description written by the sender account owner"
- You will get a flow similar to the previous ones with requests to review/accept changes and ask for permissions to execute commands if needed. Follow the same process for any further improvement or change you want to make.
Generate and run unit tests
- Now that you have your app documented and with the functions you want, let’s implement (and run) some unit tests, try the following prompt:
Generate unit tests for all the application functions and run them to verify
that everything works as expected. Keep tests code so i can run them myself.
- Gemini will display the plan and propose changes as done before.
- After it creates all the needed files, it will ask permission to run tests and execute them
- If it will get any error, Gemini will try to find the cause and implement the needed changes autonomously to get to successful tests, as in the example shown below, this is an interactive process that will end once Gemini will be able to run the tests successfully:
- Once Gemini will get the tests to run successfully it will complete the task and instruct you on how to run the tests yourself as in the picture below:
You saw how to use Gemini Code Assist agent mode to generate documentation, add new functionality and generate and run unit tests. These were just some some basic things to do as your first steps, there are more advanced things you can do to get more productive such as creating and using context files to set rules and guidelines on how Gemini agent mode should behave or setting up MCP servers so that your agent can interact with other systems.
Source Credit: https://medium.com/google-cloud/first-steps-with-gemini-code-assist-agent-mode-8d467840e32d?source=rss—-e52cf94d98af—4