Skip to content
Quickstart - Antigravity SDKsdkAntigravity SDKAntigravity SDKQuickstart - Antigravity SDK Antigravity SDK Antigravity SDKAntigravity SDK

Install google-antigravity and build a working Python agent in a few minutes. By the end of this guide, you run single-turn and multi-turn conversations, stream tokens and model thoughts, scope an agent to a project workspace, and launch an interactive terminal session.

  • Python 3.10 or later (3.10 through 3.13 classifiers are published on PyPI). Use a dedicated virtual environment.
  • One model backend:
    • A Gemini API key from Google AI Studio (used in the steps below).
    • Gemini Enterprise Agent Platform (formerly Vertex AI) using an API key or Application Default Credentials. See Authentication.
    • A local model checkpoint with LiteRT or a local OpenAI-compatible server (no API key required). See Local models.

Install the google-antigravity package from PyPI using your preferred Python package manager:

python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install google-antigravity

Install extra packages only when you use the corresponding features:

PackageInstall commandWhen you need it
google-antigravity[otel]pip install "google-antigravity[otel]"Export OpenTelemetry spans (opentelemetry-api and opentelemetry-sdk) with google.antigravity.utils.otel.get_otel_hooks(). See Observability, evals, and errors.
litert-lmpip install litert-lmRun .litertlm checkpoints on-device with LiteRTAgentConfig (use litert-lm >= 0.19.1 for on-device vision). See Local models.
watchfilespip install watchfilesWatch filesystem paths with triggers.on_file_change(). See Lifecycle hooks and triggers.

Export your Gemini API key so LocalAgentConfig picks it up automatically:

export GEMINI_API_KEY="your_api_key_here"

On Windows PowerShell, run $env:GEMINI_API_KEY = "your_api_key_here". For Gemini Enterprise Agent Platform (Express Mode and Standard Mode with ADC), custom endpoints, or offline execution, see Authentication.

Save the following script as hello_agent.py and run it with python hello_agent.py. Agent acts as an async context manager that starts localharness, executes your turn against the default model (gemini-4-hydrogen), and shuts the session down cleanly on exit:

import asyncio
from google.antigravity import Agent, LocalAgentConfig


async def main() -> None:
    config = LocalAgentConfig(
        system_instructions="You are a concise codebase assistant.",
    )
    async with Agent(config) as agent:
        response = await agent.chat("Summarize README.md in three bullets.")
        print(await response.text())


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

See hello_world.py in the SDK repository for the canonical starter script.

Every agent.chat() call inside the same async with Agent(config) block shares a stateful Conversation, preserving prior prompts, tool outputs, and model responses across turns:

import asyncio
from google.antigravity import Agent, LocalAgentConfig


async def main() -> None:
    async with Agent(LocalAgentConfig()) as agent:
        first = await agent.chat("Read hello_agent.py and explain how it works.")
        print("Turn 1:", await first.text())

        second = await agent.chat("Suggest one error-handling improvement for it.")
        print("Turn 2:", await second.text())

        print(f"Completed {agent.conversation.turn_count} turns.")


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

To save a conversation to disk and resume it in a later process using save_dir and conversation_id, see Sessions and context.

await agent.chat(...) returns a lazy ChatResponse immediately without waiting for generation to finish. Iterate over response to stream text tokens as they arrive, and iterate over response.thoughts to inspect model reasoning deltas. Each cursor buffers independently, so you can consume them sequentially or concurrently with asyncio.gather():

import asyncio
import sys
from google.antigravity import Agent, LocalAgentConfig


async def main() -> None:
    async with Agent(LocalAgentConfig()) as agent:
        response = await agent.chat(
            "Compare asyncio.TaskGroup and asyncio.gather in three bullets."
        )

        async def print_thoughts() -> None:
            header_printed = False
            async for thought in response.thoughts:
                if not header_printed:
                    print("[thought] ", end="", file=sys.stderr, flush=True)
                    header_printed = True
                print(thought, end="", file=sys.stderr, flush=True)
            if header_printed:
                print(file=sys.stderr, flush=True)

        async def print_text() -> None:
            async for token in response:
                print(token, end="", flush=True)

        await asyncio.gather(print_thoughts(), print_text())
        print()


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

To also stream response.tool_calls, low-level response.chunks, or multimodal attachments, see Streaming and multimodal.

Configure workspaces, environment, and default safety

Section titled “Configure workspaces, environment, and default safety”

By default, LocalAgentConfig sets workspaces to [os.getcwd()], enables the standard built-in tools, restricts workspace path operations (file and directory tools, run_command working directories, and workflow scripts) to the configured workspace directories (along with app_data_dir, configured skills_paths, and the OS temporary directory), and applies policy.confirm_run_command(). Without a confirmation handler, policy.confirm_run_command() allows workspace file operations and other built-in tools while denying shell execution (run_command).

Pass explicit workspaces (relative paths and ~ are resolved automatically) and optional env overrides (merged onto os.environ for localharness and run_command) to scope where and how the agent runs:

import asyncio
from google.antigravity import Agent, LocalAgentConfig, policy


async def main() -> None:
    config = LocalAgentConfig(
        workspaces=["~/projects/my-service"],
        env={"APP_ENV": "development"},
        # Explicit equivalent of the LocalAgentConfig default:
        policies=policy.confirm_run_command(),
    )
    async with Agent(config) as agent:
        response = await agent.chat(
            "Inspect pyproject.toml and summarize the runtime dependencies."
        )
        print(await response.text())


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

The SDK does not install a standalone CLI binary, but it includes run_interactive_loop() in google.antigravity.utils.interactive for local development and debugging. The helper sets AgentBehavior.INTERACTIVE, registers AskQuestionHook, and automatically upgrades unconditional run_command deny rules (including the default policy.confirm_run_command()) and handler-less policy.auto() rules to prompt for y/n confirmation in your terminal:

import asyncio
from google.antigravity import (
    AgentBehavior,
    BuiltinTools,
    CapabilitiesConfig,
    LocalAgentConfig,
)
from google.antigravity.utils.interactive import run_interactive_loop


async def main() -> None:
    config = LocalAgentConfig(
        workspaces=["."],
        capabilities=CapabilitiesConfig(
            agent_behavior=AgentBehavior.INTERACTIVE,
            # Opt into ask_question so the agent can ask clarifying questions
            enabled_tools=[*BuiltinTools.default(), BuiltinTools.ASK_QUESTION],
        ),
    )
    await run_interactive_loop(config)


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

Type exit or quit (or press Ctrl + C) to end the session.

  • Authentication: Configure Gemini API keys, Gemini Enterprise Agent Platform (Express Mode and Standard ADC), custom gateways, and SDK environment variables.
  • Models and configuration: Select models with ModelTarget, tune ThinkingLevel and ServiceTier, apply .lightweight() or .eval(), and review every LocalAgentConfig field.
  • Local models: Run offline agents with Gemma 4 on LiteRT or local OpenAI-compatible servers.
  • Tools and skills: Register custom Python functions and load SKILL.md or inline skills.
  • Policies and sandboxing: Define declarative tool policies, conditional predicates, and OS command sandboxing.
  • API reference: Browse all exported classes, decorators, enums, and error types.