Tricks to make Antigravity do EXACTLY what you want

Video thumbnail

I want to share a couple of tricks and considerations so that Google Antigravity (or any coding AI) generates exactly what you are looking for when you need to implement specific functionalities. These tips serve me daily, and I am sure they will help you too.

1. Context: The difference between authenticated users and visitors

Imagine I want to add a new functionality to my academy application. In it, you can see paid courses (where the user must be authenticated) and free material (where it is not necessary).

This is a critical point:

  • With authentication: I can save progress in the database using the user's ID.
  • Without authentication: I don't know who the user is, so the logic changes completely.

Knowing this situation, I evaluate my code. Currently, I handle the payment and authentication logic, but I have left a space (an else) specifically for free content. This is where I want to manage progress locally.

️ How to write the suggested "Prompt"

To prevent the AI from inventing solutions I don't want, I follow this outline:

  • Provide context: I explain the problem and the current situation.
  • Give clear guidelines: I indicate the technical solution I prefer. In this case, I ask it to use LocalStorage as persistent browser storage.

The browser has several types of storage (Cookies, IndexedDB, etc.), but I prefer LocalStorage for its simplicity. You can see what is stored by inspecting your browser in the Application > Local Storage tab.

The Relative URL and Exact Location trick

To prevent the AI from getting lost in a sea of files (as happens in large Laravel projects), I use two vital tricks:

  1. Copy the relative path: Right-click on your file and select "Copy Relative Path". Paste it into the chat so the AI knows exactly where to work.
  2. Point out the code block: I give it the exact piece of code where I want the implementation. For example, I tell it to look for the watch that monitors the classIndex and sectionIndex properties to update the progress locally if the resource is free.

Modularization and Best Practices (Pinia and Vue)

To prevent the AI from "spitting out" all the code into a single file, I give it modularization instructions. In my case, I use Pinia to handle the state.

The AI generated a local function to save progress given the courseID, the section, and the class, but delegated the storage logic to a separate file managed by Pinia. This keeps the code clean and professional. If your request is too general, the AI will tend to do everything locally, which is difficult to maintain.

Comparison: Challenges in Flutter and Global Configurations

When you request global changes (like setting up payments in a Flutter app), precision is even more important. If the prompt is too vague, errors can occur:

  • Obsolete versions: AI usually installs old plugins. I indicate the exact version or explicitly ask for the latest version.
    • I told it exactly which version I wanted it to install.
  • Forgotten files: In a Flutter project, the AI modified the pubspec.yaml but forgot the AndroidManifest.xml. Without the permissions in the latter, the functionality simply doesn't work.
    • The prompt was to add the in_app_purchase package to make purchases through Google Play in a Flutter project, which requires adding the <uses-permission android:name="com.android.vending.BILLING" /> permission—an operation it did NOT do until I asked a second time.

If you don't dictate exactly which files to touch, the harmony of the project is lost and the code becomes unmanageable. Since, when starting multiple conversations, the AI often does NOT evaluate the ENTIRE project and might skip some existing implementations, adding redundancy and changing the programming style. That is why it is important to make specific changes indicating exactly what you want it to do and for YOU to verify those changes.

The Ideal Workflow: Test and Sync

What I like most about tools like Antigravity is that they mark exactly which lines changed in yellow (if you use Git). My workflow is as follows:

  1. Analyze: I review the yellow change markers.
  2. Execute and Test: I verify that it is functionally OK.
  3. Sync: If the change is correct, I run git add, git commit, and git push.
  4. Revert if necessary: If something goes wrong, I use the git reset --hard command to return to the previous state and try again.

Summary: Give it context, give it the relative URL of the file, review specific changes, and constantly sync with Git.

A practical guide to Google Antigravity: How to pass effective and accurate prompts based on EXACTLY what you want the Agent to generate.

I agree to receive announcements of interest about this Blog.

Andrés Cruz

ES En español