Skip to main content

Google Antigravity SDK for building AI agents

Project description

Google Antigravity SDK

The Google Antigravity SDK is a Python SDK for building AI agents powered by Antigravity and Gemini. It provides a secure, scalable, and stateful infrastructure layer that abstracts the agentic loop, letting you focus on what your agent does rather than how it runs.

Installation

pip install google-antigravity

[!IMPORTANT] The Google Antigravity SDK relies on a compiled runtime binary that is included in the platform-specific wheels published to PyPI. Cloning this repository alone is not sufficient to run the SDK. Always install from PyPI with pip install google-antigravity to obtain the binary.

Quickstart

Get started by running one of the examples/, such as the hello_world example with:

export GEMINI_API_KEY="your_api_key_here"
python ./examples/getting_started/hello_world.py

Concepts

Simple Agent

The Agent class is the easiest way to get started. It manages the full lifecycle — binary discovery, tool wiring, hook registration, and policy defaults — behind a single async context manager.

The system_instructions parameter is optional.

import asyncio
from google.antigravity import Agent, LocalAgentConfig

async def main():
    config = LocalAgentConfig(
        system_instructions="You are an expert assistant for codebase navigation.",
        # api_key="your_api_key_here",
    )
    async with Agent(config) as agent:
        response = await agent.chat("What files are in the current directory?")
        print(await response.text())

async def run():
    await main()

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

Streaming Responses

To stream agent output in real-time (e.g., for fluid UI or console applications), simply iterate over the ChatResponse object using an async for loop. The stream wrapper natively yields conversational str text tokens as they arrive, with zero network overhead:

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

async def main():
    config = LocalAgentConfig()
    async with Agent(config) as agent:
        # Returns instantly — does not block
        response = await agent.chat("Write a short poem about space.")
        
        async for token in response:
            sys.stdout.write(token)
            sys.stdout.flush()
        print()

asyncio.run(main())

Sugared Thoughts & Tool Call Streams (Advanced)

For more complex use cases, you can also stream internal model reasoning/thinking or intercept tool call dispatches in real-time using dedicated async stream properties:

# 1. Stream reasoning/thinking deltas
async for thought in response.thoughts:
    show_thinking_bubble(thought)

# 2. Stream strongly-typed ToolCall events
async for call in response.tool_calls:
    show_executing_spinner(call.name)

By default, Agent runs in read-only mode for safety. Pass capabilities=CapabilitiesConfig() to enable all tools (including writes).

Interactive Loop

from google.antigravity import Agent, LocalAgentConfig, CapabilitiesConfig
from google.antigravity.utils.interactive import run_interactive_loop

config = LocalAgentConfig(
    # api_key="your_api_key_here",
    capabilities=CapabilitiesConfig(),
)
async with Agent(config) as agent:
    await run_interactive_loop(agent)

Advanced Usage with Conversation

For full control over the connection lifecycle, use Conversation with a ConnectionStrategy directly. Conversation is a stateful session that accumulates step history, provides a chat() convenience method, and exposes state introspection:

import asyncio
from google.antigravity.connections.local import LocalConnectionStrategy
from google.antigravity.conversation.conversation import Conversation
from google.antigravity.tools.tool_runner import ToolRunner
from google.antigravity.types import GeminiConfig

async def main():
    tool_runner = ToolRunner()
    strategy = LocalConnectionStrategy(
        tool_runner=tool_runner,
        # gemini_config=GeminiConfig(api_key="your_api_key_here"),
    )
    
    async with Conversation.create(strategy) as conversation:
        # High-level: one-call send + collect
        response = await conversation.chat("What files are here?")
        print(await response.text())
        
        # Step history accumulates automatically
        print(f"Total steps: {len(conversation.history)}")
        print(f"Turns: {conversation.turn_count}")
        print(f"Last response: {conversation.last_response}")
        
        # Low-level: streaming steps
        await conversation.send("Tell me more.")
        async for step in conversation.receive_steps():
            if step.is_complete_response:
                print(step.content)

asyncio.run(main())

Features

Multimodal Ingestion

Pass rich multimedia file attachments (images, videos, audio, and documents) to the agent alongside textual instruction prompt lists.

You can attach assets directly using content classes (perfect for in-memory bytes) or conveniently from a filesystem path (which automatically resolves types and guesses MIME formats):

from google.antigravity import Agent, LocalAgentConfig
from google.antigravity.types import Image, from_file

config = LocalAgentConfig(system_instructions="You are an expert software architect.")
async with Agent(config) as agent:
    # 1. Flat filesystem shortcut (automatically resolves as types.Document)
    pdf_spec = from_file("spec.pdf")
    
    # 2. Direct constructor instantiation (perfect for in-memory raw bytes)
    chart_image = Image(
        data=b"raw_png_bytes_here", 
        mime_type="image/png", 
        description="Architecture blueprint"
    )
    
    # Send a mixed list of text instructions and content classes
    prompt = [
        "Analyze this chart against the specification and list three security vulnerabilities:",
        chart_image,
        pdf_spec
    ]
    response = await agent.chat(prompt)
    print(await response.text())

Custom Tools

Register Python functions as tools that the agent can call:

def get_weather(city: str) -> str:
    """Returns the current weather for a city."""
    return f"It's sunny in {city}."

config = LocalAgentConfig(
    tools=[get_weather],
)
async with Agent(config) as agent:
    response = await agent.chat("What's the weather in Tokyo?")

MCP Integration

Connect to external MCP servers and expose their tools to the agent:

from google.antigravity import Agent, LocalAgentConfig
from google.antigravity.types import McpStdioServer

config = LocalAgentConfig(
    mcp_servers=[McpStdioServer(name="my_server", command="npx", args=["my-mcp-server"])],
)
async with Agent(config) as agent:
    response = await agent.chat("Use the MCP tools to help me.")

Hooks and Policies

Control agent behavior with a declarative policy system:

from google.antigravity import Agent, LocalAgentConfig, CapabilitiesConfig
from google.antigravity.hooks.policy import deny, allow, ask_user, enforce
from google.antigravity.utils.interactive import run_interactive_loop

policies = [
    deny("*"),                          # Block all tools by default
    allow("view_file"),                 # Allow reading files
    ask_user("run_command", handler=my_handler),  # Ask before running commands
]

config = LocalAgentConfig(
    capabilities=CapabilitiesConfig(),
    policies=policies,
)
async with Agent(config) as agent:
    await run_interactive_loop(agent)

Triggers

Run background tasks that react to external events and push messages into the agent:

from google.antigravity import Agent, LocalAgentConfig
from google.antigravity.triggers import every
from google.antigravity.utils.interactive import run_interactive_loop

async def check_status(ctx):
    await ctx.send("Check the deployment status.")

config = LocalAgentConfig(
    triggers=[every(60, check_status)],
)
async with Agent(config) as agent:
    await run_interactive_loop(agent)

Architecture

The SDK follows a three-layer architecture:

Layer Purpose Key Classes
Layer 1 — Simplified High-level, batteries-included entry point Agent
Layer 2 — Session Stateful session with history and convenience methods Conversation, ChatResponse, Step, ToolCall, AgentConfig, HookRunner, ToolRunner, TriggerRunner
Layer 3 — Adapter Transport and backend abstraction Connection, ConnectionStrategy, LocalConnection

Component Documentation

For more detailed documentation on specific components, see:

  • Agent — High-level, batteries-included entry point.
  • Connections — Transport and backend abstraction.
  • Conversation — Stateful session management.
  • Hooks — Agent lifecycle interception and policies.
  • MCP — Model Context Protocol integration.
  • Tools — In-process tool execution.
  • Triggers — Background tasks and external events.

License

Apache License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

google_antigravity-0.1.2-py3-none-win_arm64.whl (31.4 MB view details)

Uploaded Python 3Windows ARM64

google_antigravity-0.1.2-py3-none-win_amd64.whl (34.7 MB view details)

Uploaded Python 3Windows x86-64

google_antigravity-0.1.2-py3-none-manylinux_2_17_x86_64.whl (35.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

google_antigravity-0.1.2-py3-none-manylinux_2_17_aarch64.whl (32.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

google_antigravity-0.1.2-py3-none-macosx_11_0_arm64.whl (30.0 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file google_antigravity-0.1.2-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for google_antigravity-0.1.2-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 40cc33c30469008ee3f78e6cc8130cff9ad4e1d66c0a82b59740965a901d8b62
MD5 ae45333d22b5a1d19b2f70731ddee8ab
BLAKE2b-256 4fc40acbd66d9150f25ab693c3bfa14d440c48fa1e6dd32cdfe243f901cc1b61

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_antigravity-0.1.2-py3-none-win_arm64.whl:

Publisher: google-antigravity-py@oss-exit-gate-prod.iam.gserviceaccount.com

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.
  • Statement: Publication detail:
    • Token Issuer: https://accounts.google.com
    • Service Account: google-antigravity-py@oss-exit-gate-prod.iam.gserviceaccount.com

File details

Details for the file google_antigravity-0.1.2-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for google_antigravity-0.1.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 000fc0d3c0ef35551c7fc683a090ff2a61a20c5fedaad4d5e482239499d63207
MD5 184ef1ca4de10597302f4b641c1668c1
BLAKE2b-256 77e4d51b1003c03a2acb35919bf1e681974ec584f4354d3529bcaa79856d3c1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_antigravity-0.1.2-py3-none-win_amd64.whl:

Publisher: google-antigravity-py@oss-exit-gate-prod.iam.gserviceaccount.com

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.
  • Statement: Publication detail:
    • Token Issuer: https://accounts.google.com
    • Service Account: google-antigravity-py@oss-exit-gate-prod.iam.gserviceaccount.com

File details

Details for the file google_antigravity-0.1.2-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for google_antigravity-0.1.2-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 5e7a7d88f3f6401b8efbf45477184874c60e387990e9ddb52686aad0da0be5f2
MD5 7eaa798c63e7a0e89e206f0f27be4a85
BLAKE2b-256 73af36b933c23f9114c58185ea18c7c12ab40e862f06a3074bdcc6ab6208fcc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_antigravity-0.1.2-py3-none-manylinux_2_17_x86_64.whl:

Publisher: google-antigravity-py@oss-exit-gate-prod.iam.gserviceaccount.com

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.
  • Statement: Publication detail:
    • Token Issuer: https://accounts.google.com
    • Service Account: google-antigravity-py@oss-exit-gate-prod.iam.gserviceaccount.com

File details

Details for the file google_antigravity-0.1.2-py3-none-manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for google_antigravity-0.1.2-py3-none-manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 e888b2aa0b39d4526eb4add020c6bd5c1a2bfc8e4a3e5c228fc1698af2de4011
MD5 3486d9837aab6e765bf8317005e4a721
BLAKE2b-256 cab0a2cd625471f365601f45315b21ec02c4f9499180c00a88544bb88be567ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_antigravity-0.1.2-py3-none-manylinux_2_17_aarch64.whl:

Publisher: google-antigravity-py@oss-exit-gate-prod.iam.gserviceaccount.com

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.
  • Statement: Publication detail:
    • Token Issuer: https://accounts.google.com
    • Service Account: google-antigravity-py@oss-exit-gate-prod.iam.gserviceaccount.com

File details

Details for the file google_antigravity-0.1.2-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for google_antigravity-0.1.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 129f370b44320aefc00999ccf7c97418cd40252c5d3c07c3569843224500ffc5
MD5 b39d0175907b2e106c1daeaeb44013dd
BLAKE2b-256 03d5c6dc9b06d8248059c4ebba3489f620be1e53b03528f822c0fcf9b2dcc1bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_antigravity-0.1.2-py3-none-macosx_11_0_arm64.whl:

Publisher: google-antigravity-py@oss-exit-gate-prod.iam.gserviceaccount.com

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.
  • Statement: Publication detail:
    • Token Issuer: https://accounts.google.com
    • Service Account: google-antigravity-py@oss-exit-gate-prod.iam.gserviceaccount.com

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page