Antigravity SDK 推出本地 AI 模型支持
英文标题:Introducing Support for Local AI Models in the Antigravity SDK
Google 宣布 Antigravity SDK 新增本地工作流支持,首批可通过 Google AI Edge 的 LiteRT 运行 Gemma 4 26B A4B。开发者可在完全离线的环境中运行具备 Agent 能力的本地模型,从而降低 API 成本、提升隐私保护并增强离线可用性。官方建议使用显存或统一内存超过 24GB 的设备,并提供了本地模型导入和 Python 示例。SDK 还支持云端模型负责规划、本地模型执行任务的混合编排模式;在官方演示中,97.2%的 Token 在本地离线处理。
146.2 KB
80.2 KB
116.9 KB
19.5 KB
中文

今天,我们宣布 Antigravity SDK 已支持覆盖广泛本地模型和执行选项的本地工作流,首批支持通过 Google AI Edge 的 LiteRT 运行 Gemma 4 26B A4B。
Antigravity SDK 使开发者能够构建与 Google Antigravity 相同的 Agent 能力。借助这项新支持,你可以通过本地模型完全离线地启用 Agent 辅助。我们针对 LiteRT 和 Gemma 4 26B 优化了这一工作流,可高效利用本地 GPU 和 RAM,进一步放大本地设备的能力。
为什么要在本地运行 Agent?
本地模型执行可为 Agent 体验带来多项优势:
- **成本效率:**无需 API 成本或速率限制,即可执行本地 Agent 工作流。
- **隐私:**让代码和请求完全保留在本地设备中,适合面临严格数据隐私要求或合规限制企业环境的开发者。
- **离线韧性:**即使在无法获得持续稳定网络连接的环境中,也能顺畅执行 Agent 工作流。
- **混合工作流:**结合 Token 效率更高的本地流程与云端流程,在需要时仍可使用规模更大、能力更强的模型,从而实现最高效率。
以下是开始使用的方法:(我们建议使用显存或统一内存超过 24GB 的设备。)
创建虚拟环境:
python python3 -m venv .venv source .venv/bin/activate
安装 Antigravity SDK 和 LiteRT-LM,并下载 Gemma 4 26B A4B:
python pip install google-antigravity litert-lm
litert-lm import
--from-huggingface-repo=litert-community/gemma-4-26B-A4B-it-litert-lm
gemma-4-26B-A4B-it-gpu.litertlm
gemma4-26b
在你的目录中创建一个名为 agy_sample.py **的文件。**将以下内容粘贴到该文件中。
python import asyncio import os from google.antigravity import Agent, LiteRTAgentConfig from google.antigravity.hooks import policy
UPDATE: Point to the locally downloaded model from the previous step (litert-lm import ...)
MODEL_PATH = os.path.expanduser("~/.litert-lm/models/gemma4-26b/model.litertlm")
async def main(): print(f"Using local LiteRT model: {MODEL_PATH}. Please wait for local inference to complete. This could take several minutes.")
config = LiteRTAgentConfig(model_path=MODEL_PATH).lightweight() async with Agent(config) as agent: response = await agent.chat("What files are in the current directory?") async for token in response: print(token, end="", flush=True)
if name == "main": asyncio.run(main())
混合编排:云端架构师与设备端执行团队协同
在许多情况下,我们发现,“架构师—构建者”(Architect-Builder)模式是将云端模型规模优势与本地模型优势相结合的绝佳方式。在下方采用更新后 Antigravity SDK 构建的混合演示视频中,云端架构师(Gemini 3.8 Flash)充当规划者和协调者,而本地的 Gemma 4 26B 实例集群则完全在设备端承担繁重工作。
当任务是审计并修补三个存在漏洞的模块(auth.py、billing.py 和 database.py)时,该工作流保持严格的数据隐私,同时使我们能够最大化 Token 使用效率:
- **不上传代码:**Gemini 3.8 Flash 仅根据文件名和任务描述规划策略、拆解工作——只消耗 95 个云端 Token,且源代码从未离开设备。
- **自主本地攻防流程:**本地 Gemma 4 26B 模型接管本地 GPU,执行对抗式审计循环:复现安全漏洞、编写候选修复方案、评判补丁,以及通过回归测试套件进行验证。
- **显著的成本和隐私优势:**在这次录制的运行中,全部 Token 的 97.2%(3,322 个 Token)在本地离线运行,未调用云端 API;在确保专有代码完全安全地保留于设备端的同时,交付经过完整验证、测试全部通过的补丁。
查看此处的示例项目,可运行内置的三文件攻防流程,或将其指向你自己的 Python 模块和测试套件。
[视频/嵌入内容:您的浏览器不支持播放该视频]
无需 Token 的本地实用工具:CLI 资源监控器
搭配 Gemma 4 26B A4B 的 Antigravity SDK 在构建实用系统工具方面表现出色。在这个示例中,Agent 构建了一个可在终端中运行、实时更新的资源监控器。只需一个提示词,Agent 就会自主编写使用 psutil 和 rich 库来跟踪 CPU 与内存使用情况的 Python 脚本,生成必要的 requirements.txt 文件,甚至测试生成的代码以确保其正常工作——整个过程均完全在本地设备上运行,并使用 Gemma 4 26B。
[视频/嵌入内容:您的浏览器不支持播放该视频]
使用 Gemma 4 26B 在设备端生成的基于 Python 的 CLI 资源监控器工具
## cli_resource_monitor.py
python import asyncio import os from google.antigravity import Agent, LiteRTAgentConfig from google.antigravity.hooks import policy
UPDATE: Your prompt
PROMPT = "Build a command-line interface tool using the psutil and rich libraries that displays a live-updating terminal dashboard. It should show CPU usage, memory consumption, and a sorted table of the top 5 most memory-intensive processes. Save the script as 'monitor.py' and create a 'requirements.txt' file. Test that it works."
UPDATE: Point to the locally imported LiteRT-LM model path
MODEL_PATH = os.path.expanduser("~/.litert-lm/models/gemma4-26b/model.litertlm")
UPDATE: Give AGY-SDK a workspace to write files
WORKING_DIR = os.path.expanduser("~/agy-test")
os.makedirs(WORKING_DIR, exist_ok=True) os.chdir(WORKING_DIR)
async def main(): print(f"Using local LiteRT model: {MODEL_PATH}. Please wait for local inference to complete. This could take several minutes.")
config = LiteRTAgentConfig( model_path=MODEL_PATH, workspaces=[WORKING_DIR], policies=[policy.allow_all()], ).lightweight()
async with Agent(config) as agent: response = await agent.chat(PROMPT) async for token in response: print(token, end="", flush=True)
if name == "main": asyncio.run(main())
Antigravity SDK 还通过 LocalOpenAIAgentConfig 为 Ollama、LM Studio 或 vLLM 等任何兼容 OpenAI 的服务器提供无缝、即插即用的支持。这让你能够灵活试验不同的本地推理后端,同时保持 Agent 编排、工具和工作流完全不变。
请参阅 Antigravity Python SDK README 中的说明,开始使用本地 AI;并通过 LiteRT 了解如何在边缘端高效运行模型。欢迎通过 Antigravity Python SDK 的 GitHub Issue Tracker 分享反馈和功能请求。我们期待看到你构建的成果!
致谢:Abhi Patel、Ander Dobo、Ben Miles、Cormac Brick、Ian Ballantyne、Jingxiao Zheng、Jonathan Reay、Kimish Patel、Lu Wang、Marissa Ikonomidis、Matthias Grundmann、Olivier Lacombe、Omar Sanseviero、Rishika Sinha、Rody Davis、Taylor Mullen、Tyler Mullen、Wai Hon Law、Xiaoming Hu、Xu Chen、Yu-hui Chen
English / 原文

Today, we’re announcing that the Antigravity SDK supports local workflows across a wide range of local models and execution options, featuring initial support for Gemma 4 26B A4B using Google AI Edge’s LiteRT.
The Antigravity SDK enables developers to build with the same agentic capabilities that power Google Antigravity. With this new support you can enable agentic assistance via local models completely offline. We’ve optimized this workflow for LiteRT and Gemma 4 26B, efficiently using the local GPU and RAM in order to further amplify what your local machine is capable of delivering!
Why run agents locally?
Local model execution offers several advantages for agentic experiences:
- Cost efficiency: Execute local agentic workflows without API costs or rate limits.
- Privacy: Keep your code and requests entirely on your local machine, ideal for developers navigating strict data privacy requirements or compliance-restricted corporate environments.
- Offline resiliency: Execute your agentic workflows seamlessly, even in environments where a consistent or stable internet connection is unavailable.
- Hybrid workflows: Combine token-efficient local processes with cloud-based ones to maximize efficiency while retaining access to larger, more powerful models when needed.
Here is how you can get started: (We recommended a machine with >24GB VRAM or unified memory).
Create a virtual environment:
python3 -m venv .venv
source .venv/bin/activate
Python
Install Antigravity SDK and LiteRT-LM, and download Gemma 4 26B A4B:
pip install google-antigravity litert-lm
litert-lm import \
--from-huggingface-repo=litert-community/gemma-4-26B-A4B-it-litert-lm \
gemma-4-26B-A4B-it-gpu.litertlm \
gemma4-26b
Python
In your directory, create a file called agy_sample.py. Paste the following contents into it.
import asyncio
import os
from google.antigravity import Agent, LiteRTAgentConfig
from google.antigravity.hooks import policy
# UPDATE: Point to the locally downloaded model from the previous step (litert-lm import ...)
MODEL_PATH = os.path.expanduser("~/.litert-lm/models/gemma4-26b/model.litertlm")
async def main():
print(f"Using local LiteRT model: {MODEL_PATH}. Please wait for local inference to complete. This could take several minutes.")
config = LiteRTAgentConfig(model_path=MODEL_PATH).lightweight()
async with Agent(config) as agent:
response = await agent.chat("What files are in the current directory?")
async for token in response:
print(token, end="", flush=True)
if __name__ == "__main__":
asyncio.run(main())
Python
Hybrid Orchestration: Cloud Architect Meets On-Device Workforce
In many cases we see that an Architect-Builder pattern is a great way of combining cloud model scale with local model advantages. In the hybrid demo video below, built with the updated Antigravity SDK, a cloud architect (Gemini 3.8 Flash) acts as the planner and conductor, while a local swarm of Gemma 4 26B instances handles the heavy lifting entirely on-device.
When tasked with auditing and patching three vulnerable modules (auth.py, billing.py, and database.py), the workflow maintains strict data privacy and allows us to make the most of our token utilization:
- No code uploaded: Gemini 3.8 Flash plans the strategy and decomposes the work based purely on filenames and task descriptions - spending just 95 cloud tokens without any source code ever leaving the machine.
- Autonomous local gauntlet: Local Gemma 4 26B models take over on the local GPU to execute an adversarial audit loop: reproducing security vulnerabilities, authoring candidate fixes, critiquing patches, and validating against regression test suites.
- Massive cost and privacy wins: In this recorded run, 97.2% of all tokens (3,322 tokens) run locally and offline without calling a cloud API, delivering fully verified, green patches while keeping proprietary code completely secure on-device.
Check out the example project here to run the built-in 3-file gauntlet or point it at your own Python modules and test suite.
Sorry, your browser doesn't support playback for this video
Token Free Local Utilities: CLI Resource Monitor
The Antigravity SDK with Gemma 4 26B A4B excels at building practical system utilities. In this example, the agent built a live-updating resource monitor that runs in the terminal. Given a single prompt, the agent autonomously writes a Python script that uses the psutil and rich libraries to track CPU and memory usage, generates the necessary requirements.txt file, and even tests the resulting code to ensure it works - all running entirely on your local machine and using Gemma 4 26B.
Sorry, your browser doesn't support playback for this video
A Python based CLI Resource Monitor tool generated on-device with Gemma 4 26B
## cli_resource_monitor.py
import asyncio
import os
from google.antigravity import Agent, LiteRTAgentConfig
from google.antigravity.hooks import policy
# UPDATE: Your prompt
PROMPT = "Build a command-line interface tool using the psutil and rich libraries that displays a live-updating terminal dashboard. It should show CPU usage, memory consumption, and a sorted table of the top 5 most memory-intensive processes. Save the script as 'monitor.py' and create a 'requirements.txt' file. Test that it works."
# UPDATE: Point to the locally imported LiteRT-LM model path
MODEL_PATH = os.path.expanduser("~/.litert-lm/models/gemma4-26b/model.litertlm")
# UPDATE: Give AGY-SDK a workspace to write files
WORKING_DIR = os.path.expanduser("~/agy-test")
os.makedirs(WORKING_DIR, exist_ok=True)
os.chdir(WORKING_DIR)
async def main():
print(f"Using local LiteRT model: {MODEL_PATH}. Please wait for local inference to complete. This could take several minutes.")
config = LiteRTAgentConfig(
model_path=MODEL_PATH,
workspaces=[WORKING_DIR],
policies=[policy.allow_all()],
).lightweight()
async with Agent(config) as agent:
response = await agent.chat(PROMPT)
async for token in response:
print(token, end="", flush=True)
if __name__ == "__main__":
asyncio.run(main())
Python
The Antigravity SDK also offers seamless, plug-and-play support for any OpenAI-compatible server such as Ollama, LM Studio, or vLLM via LocalOpenAIAgentConfig. This gives you the flexibility to experiment with different local inference backends while keeping your agent orchestration, tools, and workflows completely unchanged.
Get started with local AI by checking the instructions on the Antigravity Python SDK README, and learn more about how you can run models efficiently on the edge using LiteRT. Please share your feedback and feature requests on the Antigravity Python SDK GitHub Issue Tracker. We look forward to seeing what you build!
Acknowledgements: Abhi Patel, Ander Dobo, Ben Miles, Cormac Brick, Ian Ballantyne, Jingxiao Zheng, Jonathan Reay, Kimish Patel, Lu Wang, Marissa Ikonomidis, Matthias Grundmann, Olivier Lacombe, Omar Sanseviero, Rishika Sinha, Rody Davis, Taylor Mullen, Tyler Mullen, Wai Hon Law, Xiaoming Hu, Xu Chen, Yu-hui Chen