Integrating Gemma 4 Into Antigravity — A for Offline and Air-Gapped AI Development
With Apache 2.0–licensed Gemma 4, you can now run Antigravity's agent experience inside confidential or offline projects. Here is the full implementation walkthrough — Ollama/vLLM wiring, Architect/Builder prompt tuning, and production gotchas.
Confidential projects, systems handling medical data, the unreliable wifi at a customer's office — there are plenty of contexts where you'd love to use Antigravity but its default cloud-only setup gets in the way. The standard configuration assumes Gemini 3 Pro in the cloud, which limits adoption anywhere data isn't allowed to leave the org.
Since Gemma 4 shipped under Apache 2.0 in April 2026, that has started to change. Run Gemma 4 26B A4B (or the 31B Dense variant) locally or on-prem, point Antigravity at it, and you can bring the agent experience to high-confidentiality work.
This post is a detailed walkthrough of integrating Gemma 4 with Antigravity, including the actual config files. I'll cover Architect and Builder prompt tuning specifically for Gemma 4, plus the gotchas I'd want someone to flag before I went to production.
The three integration patterns
There are three ways to wire Antigravity to Gemma 4, each with its own tradeoffs. Pick before you start coding.
Pattern A: Replace everything with local.
Simplest, suited to air-gapped environments. Both Architect and Builder model endpoints get fully redirected from Gemini API to your Gemma 4 server.
Pattern B: Route by task type.
Light tasks to local Gemma 4, heavy tasks (deep research, long-form generation) to Gemini API. Balances cost and security.
Pattern C: Sensitivity-based dynamic routing.
Detect whether request data contains confidential content; only route confidential requests to local Gemma 4. Required for internal SaaS or enterprise customer-data systems.
We'll build Pattern A first, then extend toward B and C.
Step 1: Stand up the Gemma 4 inference server
To call Gemma 4 from Antigravity you need an OpenAI-compatible endpoint in front of it. In my testing, Antigravity is most stable against vLLM or Ollama's OpenAI-compatible mode.
http://localhost:11434/v1/chat/completions is now an OpenAI-compatible API.
For air-gapped deployment, run ollama pull on a connected machine first, then carry the entire ~/.ollama/models/ directory across via USB or a secure transfer channel. Gemma 4 26B A4B at Q4_K_M is ~15 GB; the 31B Dense at Q4_K_M is ~20 GB.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦Drop-in Antigravity config that wires up Gemma 4 via an OpenAI-compatible endpoint
✦Architect and Builder prompt templates tuned specifically for Gemma 4
✦Reference architecture for air-gapped multi-developer deployments
✦Hybrid routing pattern that mixes local Gemma 4 with Gemini 3 by data sensitivity
Secure payment via Stripe · Cancel anytime
✦
Unlock This Article
Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.
The split that matters: 31B Dense ("deep") for the Architect, 26B A4B ("default") for the Builder. Architect work is requirement decomposition and design judgment, where the higher-reasoning Dense model wins. Builder work is mostly implementation, where the MoE 26B's faster responses keep iteration tight.
apiKey is unused by Ollama, but Antigravity's OpenAI-compatible client rejects empty strings, so a placeholder is required.
Step 3: Tune the Architect prompt for Gemma 4
Compared to Gemini 3, Gemma 4 is weaker at filling in implicit assumptions. Architect prompts need to be more explicit.
System prompt template I use:
You are the Antigravity Architect agent. You are running on a local LLM (Gemma 4),so follow these constraints strictly.## Output format1. Restate the requirement (one paragraph summarizing the user's request).2. Three design options (numbered list).3. Pros, cons for each option.4. Recommended option with confidence level (high/medium/low).5. If confidence is medium or low, list the additional information you need as explicit questions.## Critical constraints- Decisions must rest only on stated information, not on guesses.- Mark any technology choices the user did not specify as "speculative."- Address only one requirement per response.- Decisions that depend on existing code must cite filename and line number.## Forbidden- Vague justifications like "in general" or "in most cases."- Conclusions presented without showing the reasoning.- Producing fewer or more than three design options.
Gemini 3 fills in gaps gracefully without this level of formatting, but Gemma 4 outputs drift unless format is explicit. The friction is real, but the upside is dramatically more predictable output — usually the better tradeoff for production use.
Step 4: Tune the Builder prompt for Gemma 4
The Builder takes the Architect's design and writes code. Strict constrained-optimization framing is what works best with Gemma 4:
You are the Antigravity Builder agent. Implement code based on the Architect's design.## Inputs- Architect's design (from the prior turn).- File list (specified by the user).- Existing code (verified via the file-read tool when needed).## Output format1. Implementation approach (one paragraph mapping back to the Architect's design).2. List of files to change with one-line summaries.3. Diff-format changes per file.4. Test plan (impact on existing tests, new tests proposed).## Constraints (must hold)- Read the actual code before proposing changes.- For unknown types or functions, ask rather than guess.- Keep changes per file at or under 150 lines.- If a change would exceed that, propose splitting into multiple sessions.## Forbidden- Proposals that rewrite large portions of existing code.- Implementations without tests.- Leaving TODO comments in lieu of finishing the work.
The 150-line per-file cap exists specifically because Gemma 4's long-form generation isn't yet as steady as Gemini 3's. Pushing larger changes into split sessions naturally produces healthier commit granularity.
Reference architecture for air-gapped deployments
For confidential projects you may need to run Antigravity + Gemma 4 fully isolated from the network. Suggested topology:
[Developer workstation]
│
│ Local network only
▼
[Inference server (DGX Spark / RTX 4090 box)]
├─ Ollama server (port 11434)
├─ Gemma 4 26B A4B (Builder)
└─ Gemma 4 31B Dense (Architect)
The key idea: separate the inference server from each developer's workstation. When multiple developers share a project, you don't have to put a GPU in every machine; cost and maintenance go down significantly.
In an air-gapped setup, decide your model-update operations early. The teams I know run a quarterly cycle — bring the latest Gemma version in via a secure channel, run a regression suite against the project's evaluation dataset, then deploy.
Implementing the Pattern C hybrid router
For sensitivity-based dynamic routing, the pragmatic approach is a thin proxy in front of Antigravity. Build it on Cloudflare Workers or a small FastAPI service: classify each request and route to local Gemma 4 or Gemini API accordingly.
# Sensitivity-routing pseudocodedef route_request(messages: list[dict]) -> str: full_text = "\n".join(m["content"] for m in messages) # Confidential-keyword detection if any(kw in full_text for kw in CONFIDENTIAL_KEYWORDS): return "local-gemma4" # Patient ID / card number / PII patterns if re.search(r"\b\d{4}-\d{4}-\d{4}-\d{4}\b", full_text): return "local-gemma4" # Filename-based classification if any("internal" in m.get("metadata", {}).get("file", "") for m in messages): return "local-gemma4" return "gemini-api"
With this proxy in front of Antigravity, every Architect or Builder call gets routed automatically.
Three operational gotchas before going to production
Latency variance. Gemma 4 31B Dense locally can swing from 10 to 30 seconds per response. Antigravity's UI is tuned to Gemini API timing, so longer responses can be marked as timeouts. Bump the Antigravity timeout to 60+ seconds.
Context window limits. Gemma 4's effective context is shorter than Gemini 3's (think 8K–32K in practice). Architect sessions that pull in many files can overflow context. I cap file references at ten per session as an operational rule.
Regression testing on every model update. Gemma 4 will keep iterating. Each version bump deserves a quality check on representative tasks for your use case. Save 10–20 reference tasks and re-run them on every version bump — the bare minimum for stable operation.
Closing thought
Until recently, "use Antigravity on confidential work" wasn't a realistic ask. Gemma 4 is breaking that wall down.
Replacing Gemini 3 entirely is still difficult, but Patterns B and C let you balance confidentiality with the agent experience for real. Operating local LLMs has its own discipline, but once you absorb it, Antigravity's applicable surface widens dramatically.
Suggested first step: spend a day running Pattern A on whatever your strongest local hardware is (M3 Max or better, RTX 4090 or better). The Architect output will be more usable than you expect. From there, evolve toward Patterns B or C as your operational requirements demand. That's the lowest-friction on-ramp into local-Antigravity I've found.
Share
Thank You for Reading
Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.