Skip to content

Antigravity agent for ADK

Supported in ADKPython v2.3.0Experimental

Run a Google Antigravity SDK agent inside your Agent Development Kit (ADK) application as a native agent node. The AntigravityAgent class wraps a configured google.antigravity.AgentConfig as a standard ADK BaseAgent, delegating each turn to the Antigravity SDK runner and streaming trajectory steps back as ADK events recorded in your session.

Experimental:

The Antigravity agent feature is an experimental release. It may have limitations and is not recommended for production use.

AntigravityAgent vs. ManagedAgent

Use AntigravityAgent when you want to wrap an Antigravity SDK configuration, such as LocalAgentConfig, with local workspaces, tool-approval policies, and client-side tools. To connect to a server-hosted managed agent over the Managed Agents API instead, see Managed agents.

Use cases

  • Workspace-scoped coding and file tasks: Run a local Antigravity SDK agent that reads and writes files in configured workspace directories while streaming events through the ADK Runner and ADK Web.
  • Hybrid multi-agent systems: Delegate hands-on coding tasks from an ADK LlmAgent to an AntigravityAgent, or attach ADK sub_agents to an AntigravityAgent root so the Antigravity model can invoke them as client-side tools.
  • Deterministic workflows: Combine an AntigravityAgent with other ADK nodes inside a Workflow to separate planning from workspace file execution.

Prerequisites

  • Python 3.11 or later.
  • ADK Python v2.3.0 or later. Use v2.7.0 or later for mode="single_turn" and Workflow node support, and v2.12.0 or later for model thinking parts and client-side tool function_response events.
  • A Gemini API key exported as GEMINI_API_KEY, which the Antigravity SDK uses to call models:
export GEMINI_API_KEY="your-api-key"

Installation

Install ADK Python with the antigravity extra to include the google-antigravity package and its required Protobuf runtime:

pip install "google-adk[antigravity]"

Use with agent

Create a LocalAgentConfig with your instructions, workspace directories, policies, and trajectory storage directory, then wrap it in AntigravityAgent as your ADK root_agent:

import os

from google.adk.labs.antigravity import AntigravityAgent
from google.antigravity import LocalAgentConfig
from google.antigravity import types as antigravity_types
from google.antigravity.hooks import policy

# Create local workspace and trajectory directories.
workspace = os.path.abspath("./sandbox")
trajectories = os.path.abspath("./trajectories")
os.makedirs(workspace, exist_ok=True)
os.makedirs(trajectories, exist_ok=True)

# 1. Configure the Antigravity SDK agent.
sdk_config = LocalAgentConfig(
    system_instructions=(
        "You are a helpful local workspace assistant. Write and edit files "
        "inside the allowed workspace using absolute paths."
    ),
    workspaces=[workspace],
    policies=[
        # Approve built-in file tools explicitly; the local harness denies
        # any tool that no policy approves.
        *[
            policy.allow(tool.value)
            for tool in antigravity_types.BuiltinTools.file_tools()
        ],
        # Scope file operations to the configured workspace directory.
        *policy.workspace_only([workspace]),
    ],
    # Persist trajectories to a stable directory for multi-turn continuity.
    save_dir=trajectories,
)

# 2. Wrap the Antigravity SDK config as a standalone ADK root agent.
root_agent = AntigravityAgent(
    name="antigravity_assistant",
    description="Runs an Antigravity SDK agent inside ADK.",
    config=sdk_config,
)

Configure policies and multi-turn persistence

On every turn, AntigravityAgent constructs and enters a fresh Antigravity SDK Agent, resumes the conversation ID stored in ADK session state, sends the latest user prompt, and translates each streamed Step into standard ADK Event objects, covering model text responses, model thinking parts, function calls, function responses, and turn token usage metadata. When you enable SSE streaming in your run configuration, the wrapper also emits incremental thinking and text deltas as partial events. When the turn finishes, the wrapper exits the Antigravity SDK Agent so no live harness process stays open between turns.

Two configuration choices determine whether a local AntigravityAgent behaves reliably across turns and tool calls:

  • Set a stable save_dir for multi-turn sessions: When you use LocalAgentConfig without save_dir, the Antigravity SDK creates a fresh temporary directory on every connection, so subsequent turns cannot find the previous conversation to resume. Set save_dir to a persistent directory for multi-turn conversations, or set mode="single_turn" if you want independent turns.
  • Explicitly approve tools alongside policy.workspace_only(): The local Antigravity harness denies any tool call that no policy explicitly approves. Because policy.workspace_only() adds scoped deny rules rather than allow rules, pair it with policy.allow(...) for built-in tools, such as BuiltinTools.file_tools(), and any client-side tools your agent needs.

Because AntigravityAgent stores the conversation ID in session state through state_delta events keyed by the agent's name, run your agent through the ADK Runner to retain conversation continuity across turns. Keying by agent name also lets two AntigravityAgent instances in the same ADK session maintain separate Antigravity conversations.

Advanced applications

You can compose AntigravityAgent with standard ADK agents in three ways: as a sub-agent under an ADK coordinator, as a root agent with ADK sub_agents, or as a node in an ADK Workflow.

Delegate tasks to an Antigravity sub-agent

When you want an ADK LlmAgent to handle general conversation and delegate coding or file-editing tasks to an Antigravity SDK agent, set mode="single_turn" on the AntigravityAgent and add it to the parent agent's sub_agents list. Setting mode="single_turn" allows the parent LlmAgent to expose the AntigravityAgent as an inline tool that accepts a request string. Each call runs as an independent Antigravity conversation without forwarding ADK session history, so you do not need to set save_dir.

import os

from google.adk.agents import Agent
from google.adk.labs.antigravity import AntigravityAgent
from google.antigravity import LocalAgentConfig
from google.antigravity import types as antigravity_types
from google.antigravity.hooks import policy

workspace = os.path.abspath("./workspace")
os.makedirs(workspace, exist_ok=True)

sdk_config = LocalAgentConfig(
    system_instructions=(
        "You are a coding assistant working in a scratch workspace. "
        "Write requested files using absolute paths and summarize your changes."
    ),
    workspaces=[workspace],
    policies=[
        *[
            policy.allow(tool.value)
            for tool in antigravity_types.BuiltinTools.file_tools()
        ],
        *policy.workspace_only([workspace]),
    ],
)

# Set mode="single_turn" to allow adoption under an ADK parent agent.
code_writer = AntigravityAgent(
    name="code_writer",
    description=(
        "Writes and edits code files in a scratch workspace. Pass a "
        "complete, self-contained description of the coding task."
    ),
    config=sdk_config,
    mode="single_turn",
)

root_agent = Agent(
    name="coordinator",
    model="gemini-flash-latest",
    description="Answers general questions and delegates coding tasks.",
    instruction=(
        "Answer general questions yourself. When the user wants code "
        "written or files edited on disk, delegate a complete task "
        "description to code_writer and summarize the result."
    ),
    sub_agents=[code_writer],
)

Attach ADK sub-agents to an Antigravity root

When you want an AntigravityAgent root to consult specialized ADK agents and their tools while working in a local workspace, pass those agents in sub_agents. The AntigravityAgent class bridges each child onto the Antigravity SDK config.tools list as a client-side tool named after the child, accepting a single request string. Each invocation runs the child in an isolated Runner with an in-memory session and returns its final text to the Antigravity model, recording the tool call and function_response in the parent ADK session.

Follow three rules when attaching ADK sub_agents:

  • Provide a clear description on every child: The Antigravity model reads the child's description to decide when to call the bridged tool. An empty description raises a ValueError.
  • Use unique names: Child names must be unique among siblings and must not collide with any tool already present in config.tools, or initialization raises a ValueError.
  • Approve each child in local policies: Because the local Antigravity harness denies any tool that no policy approves, add policy.allow(child.name) to policies so the harness can invoke the bridged sub-agent tool.
import os

from google.adk.agents import Agent
from google.adk.labs.antigravity import AntigravityAgent
from google.antigravity import LocalAgentConfig
from google.antigravity import types as antigravity_types
from google.antigravity.hooks import policy


def get_current_time(city: str) -> dict[str, str]:
    """Returns the current time for a city."""
    return {"status": "success", "report": f"The time in {city} is 12:00 PM."}


time_assistant = Agent(
    name="time_assistant",
    model="gemini-flash-latest",
    description=(
        "Returns the current time for a city. Call this for any "
        "time-related question."
    ),
    instruction="Answer time questions by calling get_current_time.",
    tools=[get_current_time],
)

workspace = os.path.abspath("./workspace")
trajectories = os.path.abspath("./trajectories")
os.makedirs(workspace, exist_ok=True)
os.makedirs(trajectories, exist_ok=True)

sdk_config = LocalAgentConfig(
    system_instructions=(
        "You are a local workspace assistant. Consult time_assistant for "
        "time questions and write requested files inside the workspace."
    ),
    workspaces=[workspace],
    policies=[
        # Approve the bridged ADK sub-agent tool by name.
        policy.allow(time_assistant.name),
        *[
            policy.allow(tool.value)
            for tool in antigravity_types.BuiltinTools.file_tools()
        ],
        *policy.workspace_only([workspace]),
    ],
    save_dir=trajectories,
)

root_agent = AntigravityAgent(
    name="local_assistant",
    description=(
        "Runs an Antigravity SDK agent that writes workspace files and "
        "consults an ADK sub-agent."
    ),
    config=sdk_config,
    sub_agents=[time_assistant],
)

Run an Antigravity agent in a Workflow

When you want to separate planning from file generation in a deterministic pipeline, wire an LlmAgent and an AntigravityAgent as nodes in an ADK Workflow. Each node's text output becomes the next node's input. Because Workflow connects nodes with edges rather than sub_agents, you do not need mode="single_turn" to avoid parent-adoption errors. However, set mode="single_turn" for single-shot workflow runs so each run starts cleanly without requiring a persistent save_dir.

import os

from google.adk import Workflow
from google.adk.agents import Agent
from google.adk.labs.antigravity import AntigravityAgent
from google.antigravity import LocalAgentConfig
from google.antigravity import types as antigravity_types
from google.antigravity.hooks import policy

planner = Agent(
    name="planner",
    model="gemini-flash-latest",
    description="Turns a build request into a concrete file specification.",
    instruction=(
        "Turn the user's request into a numbered list of files to create "
        "and what each file should contain. Output only the spec."
    ),
)

workspace = os.path.abspath("./workspace")
os.makedirs(workspace, exist_ok=True)

sdk_config = LocalAgentConfig(
    system_instructions=(
        "You are a coding agent. Implement the received specification by "
        "writing files into your workspace using absolute paths, then "
        "summarize the files you created."
    ),
    workspaces=[workspace],
    policies=[
        *[
            policy.allow(tool.value)
            for tool in antigravity_types.BuiltinTools.file_tools()
        ],
        *policy.workspace_only([workspace]),
    ],
)

builder = AntigravityAgent(
    name="builder",
    description="Implements a specification by writing files to the workspace.",
    config=sdk_config,
    mode="single_turn",
)

root_agent = Workflow(
    name="antigravity_workflow",
    edges=[("START", planner, builder)],
)

Configuration options

Configure AntigravityAgent with the following fields in addition to the standard BaseAgent fields (name, description, and sub_agents):

Option Type Default Description
config AgentConfig Required The google.antigravity.AgentConfig, typically LocalAgentConfig, defining the Antigravity SDK agent's instructions, workspaces, tools, policies, and storage. Excluded from serialization.
mode Literal['single_turn'] \| None None Composition mode when you use the agent under an ADK parent agent. Set to 'single_turn' to expose the agent as an inline tool on a parent LlmAgent; leave as None for a standalone root agent. Frozen after construction.

Limitations

  • Root-only unless mode="single_turn": Because the Antigravity harness owns its own conversation loop, adding an AntigravityAgent as a sub-agent of an ADK parent raises a ValueError unless you set mode="single_turn" at construction. This restriction applies only when AntigravityAgent has an ADK parent; attaching ADK sub_agents beneath an AntigravityAgent does not require mode.
  • Sub-agent isolation and root resolution: Bridged ADK sub_agents run in fresh in-memory sessions and return only their final text, excluding code-execution output and executable code parts. In a three-level tree where an LlmAgent delegates to an AntigravityAgent with mode="single_turn" that has its own child, ADK's root_agent still resolves to the outermost agent, which exposes ADK transfer tools to the child's model. Keep children of an AntigravityAgent leaf-like, or set disallow_transfer_to_parent=True and disallow_transfer_to_peers=True on each child.
  • No concurrent turns in one session: Running two turns of the same ADK session concurrently is undefined because both turns open the same stored Antigravity conversation.
  • Missing local conversation history: If the stored conversation directory does not exist when resuming a multi-turn local session, AntigravityAgent clears the stored conversation ID and raises a RuntimeError. The next turn starts a new conversation, and you cannot recover prior turns.
  • Runner required for state persistence: Conversation continuity across turns relies on the ADK Runner applying state_delta events to session state.

Additional resources