Skip to content

The Google Antigravity SDK is a Python SDK for building autonomous AI agents powered by Antigravity and Gemini. It provides a secure, stateful runtime harness that handles tool execution, context management, safety policies, and subagent delegation.

If you’re looking for the managed cloud REST/gRPC API instead of the local Python SDK runtime, see the Gemini API Antigravity Agent documentation.

Install the SDK package using pip and configure your API key to get started:

pip install google-antigravity

Set your Gemini API key in your environment:

export GEMINI_API_KEY="your_api_key_here"

Initialize an Agent and start a conversation:

import asyncio
from google.antigravity import Agent, LocalAgentConfig

async def main():
    config = LocalAgentConfig()
    async with Agent(config) as agent:
        response = await agent.chat("What files are in the current directory?")
        print(await response.text())

if __name__ == "__main__":
    asyncio.run(main())

To connect the SDK to Gemini Enterprise Agent Platform (formerly Vertex AI), set vertex=True in LocalAgentConfig alongside your GCP project and location:

from google.antigravity import Agent, LocalAgentConfig

config = LocalAgentConfig(
    vertex=True,
    project="your-gcp-project",
    location="us-central1",
)

async with Agent(config) as agent:
    response = await agent.chat("Hello!")
    print(await response.text())

Environment variables are also supported:

export GOOGLE_GENAI_USE_VERTEXAI=True
export GOOGLE_CLOUD_PROJECT="your-gcp-project"
export GOOGLE_CLOUD_LOCATION="us-central1"
gcloud auth application-default login

The Agent class manages binary discovery, tool execution, and session lifecycles behind an async context manager.

For example, you can configure an agent with custom system instructions to interact using a specific persona:

import asyncio
from google.antigravity import Agent, LocalAgentConfig

async def main():
    config = LocalAgentConfig(
        system_instructions=(
            "You are a helpful pirate assistant. Speak like a pirate."
        ),
    )
    async with Agent(config) as agent:
        response = await agent.chat("Explain the repository layout.")
        print(await response.text())

if __name__ == "__main__":
    asyncio.run(main())

Explore the guides below to learn more about building and customizing agents with the Python SDK:

  • Personas: Customize agent identity using templated or custom system instructions.
  • Tools & skills: Register custom Python functions, use built-in tools, and load skills.
  • MCP: Connect external Model Context Protocol (MCP) servers to your agents.
  • Policies: Enforce explicit tool execution policies and interactive approval flows.
  • Subagents: Build multi-agent systems using dynamic self-cloning or static subagents.
  • Structured output: Handle multimodal input, stream model thoughts, and validate output.
  • Lifecycle & hooks: Manage background event triggers, session persistence, and custom hooks.

You can find full, runnable Python scripts for each SDK feature in the getting_started directory on GitHub: