Antigravity agent for ADK¶
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
Runnerand ADK Web. - Hybrid multi-agent systems: Delegate hands-on coding tasks from an ADK
LlmAgentto anAntigravityAgent, or attach ADKsub_agentsto anAntigravityAgentroot so the Antigravity model can invoke them as client-side tools. - Deterministic workflows: Combine an
AntigravityAgentwith other ADK nodes inside aWorkflowto 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"andWorkflownode support, and v2.12.0 or later for model thinking parts and client-side toolfunction_responseevents. - A Gemini API key exported as
GEMINI_API_KEY, which the Antigravity SDK uses to call models:
Installation¶
Install ADK Python with the antigravity extra to include the
google-antigravity package and its required Protobuf runtime:
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_dirfor multi-turn sessions: When you useLocalAgentConfigwithoutsave_dir, the Antigravity SDK creates a fresh temporary directory on every connection, so subsequent turns cannot find the previous conversation to resume. Setsave_dirto a persistent directory for multi-turn conversations, or setmode="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. Becausepolicy.workspace_only()adds scoped deny rules rather than allow rules, pair it withpolicy.allow(...)for built-in tools, such asBuiltinTools.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
descriptionon every child: The Antigravity model reads the child'sdescriptionto decide when to call the bridged tool. An emptydescriptionraises aValueError. - 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 aValueError. - Approve each child in local policies: Because the local Antigravity
harness denies any tool that no policy approves, add
policy.allow(child.name)topoliciesso 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 anAntigravityAgentas a sub-agent of an ADK parent raises aValueErrorunless you setmode="single_turn"at construction. This restriction applies only whenAntigravityAgenthas an ADK parent; attaching ADKsub_agentsbeneath anAntigravityAgentdoes not requiremode. - Sub-agent isolation and root resolution: Bridged ADK
sub_agentsrun 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 anLlmAgentdelegates to anAntigravityAgentwithmode="single_turn"that has its own child, ADK'sroot_agentstill resolves to the outermost agent, which exposes ADK transfer tools to the child's model. Keep children of anAntigravityAgentleaf-like, or setdisallow_transfer_to_parent=Trueanddisallow_transfer_to_peers=Trueon 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,
AntigravityAgentclears the stored conversation ID and raises aRuntimeError. 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
Runnerapplyingstate_deltaevents to session state.
Additional resources¶
- Managed agents: Connect to server-hosted managed agents through the Managed Agents API instead of running a local Antigravity SDK harness.
- Environment Toolset: Give standard ADK
LlmAgentinstances local or sandboxed shell and file tools. - Graph-based agent workflows: Build deterministic multi-agent
graphs using the ADK
WorkflowAPI. - Standalone Antigravity agent sample: A game-developer agent writing self-contained HTML files to a local workspace.
- Antigravity as an ADK sub-agent sample:
An ADK
LlmAgentcoordinator delegating coding tasks to asingle_turnAntigravityAgent. - Antigravity with an ADK sub-agent sample:
An
AntigravityAgentroot consulting a bridged ADKLlmAgenttool. - Antigravity in an ADK Workflow sample:
A two-node
Workflowchaining an ADK planner into anAntigravityAgentbuilder.