$git clone https://github.com/google-antigravity/antigravity-sdk-pythonThe 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.
| 1 | # Google Antigravity SDK |
| 2 | |
| 3 | The Google Antigravity SDK is a Python SDK for building AI agents powered by |
| 4 | Antigravity and Gemini. It provides a secure, scalable, and stateful |
| 5 | infrastructure layer that abstracts the agentic loop, letting you focus on what |
| 6 | your agent *does* rather than how it runs. |
| 7 | |
| 8 | ## Installation |
| 9 | |
| 10 | ```sh |
| 11 | pip install google-antigravity |
| 12 | ``` |
| 13 | |
| 14 | > [!IMPORTANT] |
| 15 | > The Google Antigravity SDK relies on a compiled runtime binary that is |
| 16 | > included in the platform-specific wheels published to |
| 17 | > [PyPI](https://pypi.org/project/google-antigravity/). **Cloning this |
| 18 | > repository alone is not sufficient to run the SDK.** Always install from |
| 19 | > PyPI with `pip install google-antigravity` to obtain the binary. |
| 20 | |
| 21 | ## Quickstart |
| 22 | |
| 23 | Get started by running one of the [`examples/`](examples/), such as the |
| 24 | `hello_world` example with: |
| 25 | |
| 26 | ```sh |
| 27 | export GEMINI_API_KEY="your_api_key_here" |
| 28 | python ./examples/getting_started/hello_world.py |
| 29 | ``` |
| 30 | ## Gemini Enterprise Agent Platform (formerly Vertex AI) |
| 31 | |
| 32 | To use the SDK with Gemini Enterprise Agent Platform (formerly Vertex AI), |
| 33 | configure `LocalAgentConfig` with `vertex=True` and specify your GCP `project` |
| 34 | and `location`. |
| 35 | |
| 36 | By default, the SDK uses Application Default Credentials (ADC) for |
| 37 | authentication. |
| 38 | |
| 39 | ```python |
| 40 | from google.antigravity import Agent, LocalAgentConfig |
| 41 | |
| 42 | config = LocalAgentConfig( |
| 43 | vertex=True, |
| 44 | project="your-gcp-project", |
| 45 | location="us-central1", |
| 46 | ) |
| 47 | |
| 48 | async with Agent(config) as agent: |
| 49 | response = await agent.chat("Hello!") |
| 50 | print(await response.text()) |
| 51 | ``` |
| 52 | |
| 53 | Alternatively, you can leave these fields unset in `LocalAgentConfig` and |
| 54 | export the environment variables instead: |
| 55 | |
| 56 | ```sh |
| 57 | # Either GOOGLE_GENAI_USE_VERTEXAI or GOOGLE_GENAI_USE_ENTERPRISE enable Vertex. |
| 58 | export GOOGLE_GENAI_USE_VERTEXAI=True |
| 59 | export GOOGLE_CLOUD_PROJECT="your-gcp-project" |
| 60 | export GOOGLE_CLOUD_LOCATION="us-central1" |
| 61 | ``` |
| 62 | |
| 63 | Explicit kwargs always take precedence over env vars. |
| 64 | |
| 65 | Ensure you have authenticated locally before running the agent: |
| 66 | |
| 67 | ```sh |
| 68 | gcloud auth application-default login |
| 69 | ``` |
| 70 | |
| 71 | ## Concepts |
| 72 | |
| 73 | ### Simple Agent |
| 74 | |
| 75 | The `Agent` class is the easiest way to get started. It manages the full |
| 76 | lifecycle — binary discovery, tool wiring, hook registration, and policy |
| 77 | defaults — behind a single async context manager. |
| 78 | |
| 79 | The `system_instructions` parameter is optional. |
| 80 | |
| 81 | ```python |
| 82 | import asyncio |
| 83 | from google.antigravity import Agent, LocalAgentConfig |
| 84 | |
| 85 | async def main(): |
| 86 | config = LocalAgentConfig( |
| 87 | system_instructions="You are an expert assistant for codebase navigation.", |
| 88 | # api_key="your_api_key_here", |
| 89 | ) |
| 90 | async with Agent(config) as agent: |
| 91 | response = await agent.chat("What files are in the current directory?") |
| 92 | print(await response.text()) |
| 93 | |
| 94 | async def run(): |
| 95 | await main() |
| 96 | |
| 97 | if __name__ == "__main__": |
| 98 | asyncio.run(run()) |
| 99 | ``` |
| 100 | |
| 101 | ### Streaming Responses |
| 102 | |
| 103 | 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: |
| 104 | |
| 105 | ```python |
| 106 | import asyncio |
| 107 | import sys |
| 108 | from google.antigravity import Agent, LocalAgentConfig |
| 109 | |
| 110 | async def main(): |
| 111 | config = LocalAgentConfig() |
| 112 | async with Agent(config) as agent: |
| 113 | # Returns instantly — does not block |
| 114 | response = await agent.chat("Write a short poem about space.") |
| 115 | |
| 116 | async for token in response: |
| 117 | sys.stdout.write(token) |
| 118 | sys.stdout.flush() |
| 119 | print() |
| 120 | |
| 121 | asyncio.run(main()) |
| 122 | ``` |
| 123 | |
| 124 | ### Sugared Thoughts & Tool Call Streams (Advanced) |
| 125 | |
| 126 | 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: |
| 127 | |
| 128 | ```python |
| 129 | # 1. Stream reasoning/thinking deltas |
| 130 | async for thought in response.thoughts: |
| 131 | show_thinking_bubble(thought) |
| 132 | |
| 133 | # 2. Stream strongly-typed ToolCall events |
| 134 | async for call in response.tool_calls: |
| 135 | s |