The connections package provides the abstraction layer for interacting with
agent backends. It decouples the higher-level SDK components (like
Conversation and Agent) from the specific transport and process
management details of where the agent is running.
Connection is an abstract base class that represents a live session with an
agent backend. Layer 2 APIs depend ONLY on this interface.
Key methods and properties:
send(prompt, **kwargs): Sends a prompt to the agent.receive_steps(): An async iterator that yieldsStepobjects as they are completed by the agent.disconnect(): Disconnects the session and releases resources.cancel(): Cancels the current turn.is_idle: Property indicating if the connection is idle.conversation_id: Property returning the conversation identifier.
ConnectionStrategy is an abstract base class for establishing a Connection.
It handles process management, transport setup, authentication, and health
checking specific to a backend type.
Key methods:
connect(): Returns the establishedConnection.__aenter__()and__aexit__(): Support for use as an async context manager to manage the backend lifecycle.
AgentConfig is an abstract base class for agent configuration. Each
ConnectionStrategy defines a concrete subclass with the config fields it needs
(e.g., LocalAgentConfig for LocalConnectionStrategy).
Key methods:
create_strategy(tool_runner, hook_runner): Abstract method that creates theConnectionStrategyfor this config.
Each connection strategy lives in its own sub-package under connections/.
A strategy's sub-package co-locates its implementation, config, proto bindings,
and tests:
connections/
├── connection.py # ABCs: Connection, ConnectionStrategy, AgentConfig
├── connection_test.py
├── README.md
└── local/ # LocalConnection strategy
├── __init__.py # Re-exports public API
├── local_connection.py # LocalConnection, LocalConnectionStrategy
├── local_connection_config.py # LocalAgentConfig
├── local_connection_test.py
└── localharness_pb2.py # Proto bindings for the local harness
When adding a new connection strategy, create a new sub-package following this
pattern. For example, a remote connection strategy would go in
connections/remote_connection/.
LocalConnection (and its corresponding LocalConnectionStrategy) connects to
a Go-based local harness.
- Transport: It uses WebSockets to communicate with the Go harness.
- Protocol: It communicates using protobuf messages (
OutputEvent,InputEvent,StepUpdate, etc.) serialized to JSON. - Config:
LocalAgentConfiginlocal_connection_config.py. - Features:
- Handles tool calls by executing them via
ToolRunnerand sending results back. - Handles question requests from the harness and dispatches them via
HookRunner(interaction hooks). - Dispatches session start/end and turn hooks.
- Supports loading skills from specified paths via
skills_paths. - Supports overriding the application data directory for generated artifacts and media via
app_data_dir.
- Handles tool calls by executing them via
from google.antigravity.connections.local import LocalConnectionStrategy
from google.antigravity.types import GeminiAPIEndpoint, ModelConfig, ModelType
strategy = LocalConnectionStrategy(
binary_path="/path/to/localharness",
models=[
ModelConfig(
name="gemini-3.5-flash",
types=[ModelType.TEXT],
endpoint=GeminiAPIEndpoint(api_key="..."),
)
],
skills_paths=["/path/to/skills"],
)
async with strategy:
connection = strategy.connect()
await connection.send("Hello")
async for step in connection.receive_steps():
print(step)connection.py: DefinesConnection,ConnectionStrategy, andAgentConfiginterfaces.local/: Local harness connection strategy package.local_connection.py: ImplementsLocalConnectionandLocalConnectionStrategy.local_connection_config.py: ImplementsLocalAgentConfig.localharness_pb2.py: Generated protobuf bindings.