I asked for an App Router page one night and got back import { useRouter } from "next/router" at the top. Nothing crashed — but App Router wants next/navigation, and the agent had slipped back into Pages Router habits. Over the last month this has been my single most common "almost-but-not-quite" moment with the agent.
The reason isn't mysterious. AI models have a training cutoff; libraries keep shipping. Antigravity has built-in web fetching and document tools, but unless you nudge the agent toward fresh sources, it will default to whatever it remembers from training. Here I want to walk through the three mechanisms I actually use day to day to keep the agent honest about library versions. Not a grand framework — just things you can drop in tomorrow.
A quick reframe: it's not "doesn't know," it's "doesn't recall"
Before getting to the techniques, one observation that changed how I think about this.
The Gemini family inside Antigravity, and Claude when you bridge it in, usually did see fairly recent documentation during training. The trouble is that once a few outdated snippets land in the conversation, the model anchors on them. The problem is less "the model doesn't know" and more "the conversation never gave it a reason to recall." Reframed that way, the fix becomes obvious: drop a fresh source into the conversation so the model has no choice but to lean on it.
Mechanism 1: Pipe in versioned official docs through Context7 MCP
The first piece I reach for is Context7 MCP, maintained by Upstash. Ask for a library and it returns the matching slice of official documentation through MCP, ready for the model to consume.
Here is how I register it (the config file location varies by version, so follow your settings screen):
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp"],
"env": {}
}
}
}Once it's wired up, you add use context7 to the end of your prompt, and it pulls the relevant docs in the background. To pin a target, write a library ID such as /vercel/next.js in the prompt; the call syntax can change, so check the Context7 README for the current form. The model then treats the docs as part of the conversation. I like that it doesn't break my flow — no separate browser tab, no copying snippets back and forth.
One example of the flow (actual replies vary):
You: Write the smallest possible example of reading a cookie on the server with the Next.js App Router. use context7
Agent: (Context7 pulls the cookies() reference)
→ Returns code that awaits the async cookies() API
For deeper setup, I wrote up the full configuration at Hooking Antigravity to Context7 MCP for Always-Fresh Library Docs.
Two things to watch
- Not every library is indexed by Context7. Smaller packages may not be available
- If you don't state a version, Context7 returns what it considers "latest." That's not always what you mean, so I also write the target version in the prompt itself
Mechanism 2: Hand the agent the official URL directly
When Context7 doesn't cover what I need, my fallback is almost embarrassingly simple: paste the documentation URL straight into the prompt. Antigravity's agent recognizes URLs and will read them with its browser tooling when you hand them over.
Read https://nextjs.org/docs/app/api-reference/functions/cookies and update src/lib/auth.ts to follow the v16 async API.
That single line is enough to make the agent fetch the page, and then refactor the file to match. The trick is to be specific about the goal before the URL. If you only say "read this," you tend to get a long-winded summary back. State what you want changed first, then paste the link.
I lean on this whenever I'm writing release notes or update posts for one of my apps. For example, when iOS 26 dropped, I would paste Apple Developer's "What's New in iOS 26" page and ask the agent to summarize it in plain language. Faster than trawling through it myself.
Pitfall: keep it to one or two URLs
In practice, dropping five or more URLs into the same prompt scatters the agent's attention. Bound the scope too — "focus on chapter 3 of this page" — and the answers stay sharp.
Mechanism 3: Pin the project's current state in AGENTS.md
The third lever is the quietest but most effective: put a short AGENTS.md at the project root that spells out the dependency versions and the APIs you do not want used.
# AGENTS.md
## This project's environment
- Next.js: 16.0.x (App Router only — no Pages Router)
- React: 19.0.x (Server Components by default; minimal `use client`)
- Tailwind: v4 line
- TypeScript: 5.6 or higher
## Do not use
- `next/router` in the App Router (use `next/navigation`)
- `fetch` inside `useEffect` (do it in Server Components instead)
- `getServerSideProps` / `getStaticProps` (replace with App Router equivalents)
## Code generation rules
- Use the `@/` import prefix
- End every file with one trailing blank line
- Top-level await is allowed in async modulesAntigravity picks this file up as workspace instructions (conditions for it being applied are laid out in Troubleshooting AGENTS.md not being applied). The practical payoff is that you stop having to type "use Next.js 16, please" every single session. I treat AGENTS.md as the project's CV — the first thing I update when I bump a major version.
If it doesn't seem to apply, start with the troubleshooting steps in the link above.
How I actually combine them — my current default
These three pieces aren't alternatives to each other; they play different roles. My default split looks like this:
| Situation | Reach for | Why |
|---|---|---|
| Routine feature work | AGENTS.md (Mechanism 3) | Version pins alone are usually enough |
| Adopting a new library | Context7 MCP (Mechanism 1) | Pulling docs first saves rework |
| Major version bump | Official URL (Mechanism 2) | The agent reads the release notes directly |
| Obscure error | URL plus stack trace | Narrows things better than either alone |
Because Mechanism 3 quietly does the heavy lifting, I reach for the other two less often than you might expect. Conversely, projects that don't have an AGENTS.md force the model to guess from scratch every time, and the rate at which it falls back to old APIs noticeably climbs.
A small habit that pays off
When I'm in the middle of a long session and start to feel the agent drifting toward older patterns, I do one of two things. Either I open AGENTS.md and add a single line that captures whatever it just got wrong (so the same drift doesn't repeat tomorrow), or I paste the relevant doc URL once mid-conversation to re-anchor the context. Both take less than thirty seconds and usually rescue the rest of the session. The cost of not doing it is rewriting the same code two or three times, which is the slow leak that erodes the productivity gains of an AI IDE in the first place.
Writing a rule isn't the same as having it followed
At first I wrote the do-not-use list into AGENTS.md and felt done. It didn't go well. Late in a long session the same next/router crept back in. What's written and what's honored are different things.
Now I check the staged diff once before committing:
# Flag banned imports in staged changes (keep the pattern in sync with AGENTS.md)
git diff --cached -U0 -- 'src/app/**' \
| grep -nE '^\+.*(from "next/router"|getServerSideProps|getStaticProps)' \
&& echo "NG: banned API found" || echo "OK"When it fires, I add that line to the "mistakes" list in AGENTS.md. A rule only works once it comes with a check. The script is a few lines, and it has caught most of what I would have missed.
One thing to do today
Thanks for reading this far. You don't need all three pieces at once. The highest-return investment, by a clear margin, is just writing an AGENTS.md.
Open a project, drop an AGENTS.md at the root, and copy five or six lines from your package.json dependencies listing the major libraries and their versions. That single change measurably reduces the chance the agent quietly retreats to an older API tomorrow. Context7 and URL pasting can join later, on the day you actually need them.