Google Antigravity SDK: The Ultimate Guide

Learn how to build your first autonomous AI agent.

← Back to Dashboard

Prerequisites

Before you start coding, ensure your environment is set up:

Step 1: The "Hello World" Agent

The easiest way to get started is to build a basic agent that responds to a single prompt.

from google.antigravity import Agent, LocalAgentConfig

async def main():
    # Initialize the agent with local configuration
    async with Agent(LocalAgentConfig()) as agent:
        # Send a prompt to the agent
        response = await agent.chat("Hello, World! Who are you?")
        
        # Await and print the final response text
        print(await response.text())

import asyncio
asyncio.run(main())

Step 2: Streaming Responses and Thoughts

For a more interactive experience, you can stream the agent's response token-by-token. You can also stream the agent's internal "thoughts".

from google.antigravity import Agent, LocalAgentConfig

async def main():
    async with Agent(LocalAgentConfig()) as agent:
        response = await agent.chat("Explain quantum physics in 2 sentences.")
        
        # Stream the agent's internal reasoning
        print("Thinking: ", end="")
        async for thought in response.thoughts:
            print(thought, end="", flush=True)
            
        print("\n\nFinal Answer: ", end="")
        
        # Stream the final output
        async for token in response:
            print(token, end="", flush=True)

import asyncio
asyncio.run(main())

Step 3: Multi-Agent Systems (Subagents)

The true power of Antigravity is giving your agent the ability to spawn its own "subagents" to delegate tasks.

from google.antigravity import Agent, LocalAgentConfig, types

async def main():
    # Explicitly enable subagent capabilities
    config = LocalAgentConfig(
        capabilities=types.CapabilitiesConfig(
            enable_subagents=True, 
        )
    )

    async with Agent(config) as agent:
        # The agent will recognize it needs a subagent to fulfill this complex request
        response = await agent.chat("Spawn a subagent to write a python script that calculates the fibonacci sequence.")
        print(await response.text())

import asyncio
asyncio.run(main())