chore: import upstream snapshot with attribution
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
# Workspace the agent writes generated games into at runtime.
|
||||
game_repo/
|
||||
# Conversation trajectories persisted across turns.
|
||||
trajectories/
|
||||
@@ -0,0 +1,82 @@
|
||||
# Antigravity SDK Game Developer Agent
|
||||
|
||||
## Overview
|
||||
|
||||
This sample wraps a pre-configured [Google Antigravity SDK](https://pypi.org/project/google-antigravity/)
|
||||
agent as a native ADK agent using `AntigravityAgent`, configured as a
|
||||
**game developer** that writes small, runnable browser games into the
|
||||
`game_repo/` workspace as single self-contained HTML files. Each turn is
|
||||
delegated to the Antigravity
|
||||
runner, and its trajectory steps (model text, tool calls, and tool responses)
|
||||
are streamed back as standard ADK events recorded in the session.
|
||||
|
||||
`AntigravityAgent` must be used as a **standalone root agent** (the SDK currently
|
||||
only supports local mode). See the
|
||||
[package README](../../../../src/google/adk/labs/antigravity/README.md)
|
||||
for the full setup, limitations, and API details.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Install the SDK: `pip install "google-adk[antigravity]"`
|
||||
- Set a Gemini API key: `export GEMINI_API_KEY="your-api-key"`
|
||||
(required by the Antigravity SDK, which drives the model)
|
||||
|
||||
The agent writes generated games into a `game_repo/` directory and persists
|
||||
conversation trajectories (for cross-turn resumption) into a `trajectories/`
|
||||
directory, both next to `agent.py` and created automatically on import.
|
||||
|
||||
## Sample Inputs
|
||||
|
||||
- `Create a playable Snake game.`
|
||||
|
||||
The agent writes a self-contained HTML implementation into `game_repo/` (e.g.
|
||||
`game_repo/snake.html`, with inline CSS and JavaScript) using the built-in
|
||||
`create_file` tool, then explains how to open it in a browser.
|
||||
|
||||
- `Create a 2-player turn-based Artillery game with adjustable angle and power.`
|
||||
|
||||
The agent writes another self-contained HTML game (e.g.
|
||||
`game_repo/artillery.html`) with canvas rendering and projectile physics.
|
||||
|
||||
- `Create a Brick Breaker game.`
|
||||
|
||||
The agent writes a self-contained HTML implementation (e.g.
|
||||
`game_repo/brick_breaker.html`) with a paddle, ball, and breakable bricks.
|
||||
|
||||
## Graph
|
||||
|
||||
Each turn, the wrapper delegates to the SDK agent's local Go harness and maps
|
||||
the trajectory steps it streams back into ADK events:
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
Runner[ADK Runner] -->|prompt| Wrapper[AntigravityAgent]
|
||||
Wrapper -->|send| SDK[Antigravity SDK Agent]
|
||||
SDK -->|local mode| Harness[Go localharness]
|
||||
Harness -->|steps| SDK
|
||||
SDK -->|steps| Wrapper
|
||||
Wrapper -->|ADK events| Runner
|
||||
```
|
||||
|
||||
## How To
|
||||
|
||||
The wrapper takes a `google.antigravity.LocalAgentConfig` via the `config`
|
||||
argument:
|
||||
|
||||
```python
|
||||
root_agent = AntigravityAgent(
|
||||
name="antigravity_game_developer",
|
||||
description="...",
|
||||
config=_sdk_config,
|
||||
)
|
||||
```
|
||||
|
||||
The SDK agent enables its built-in file tools by default; the
|
||||
`policy.workspace_only([...])` policy keeps all file reads and writes contained
|
||||
to `game_repo/`. Internally, `AntigravityAgent._run_async_impl` deep-copies the
|
||||
config per turn (the SDK's `AsyncExitStack` is single-use), enters a fresh SDK
|
||||
`Agent`, sends the latest user prompt, and converts each streamed Step into ADK
|
||||
events.
|
||||
|
||||
The root-only restriction is enforced at construction time: giving the agent
|
||||
`sub_agents`, or adopting it under a parent agent, raises a `ValueError`.
|
||||
@@ -0,0 +1,64 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Game-developer agent that writes browser games as self-contained HTML.
|
||||
|
||||
Wraps a Google Antigravity SDK agent as an ADK agent. See the package README
|
||||
for setup and details.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from google.adk.labs.antigravity import AntigravityAgent
|
||||
from google.antigravity import LocalAgentConfig
|
||||
from google.antigravity.hooks import policy
|
||||
|
||||
# 1. Configure the Google Antigravity SDK game-developer agent. The
|
||||
# workspace-scoped policy lets it create and edit files inside the game_repo
|
||||
# workspace (built-in file tools are allowed there) while keeping writes
|
||||
# contained.
|
||||
_sample_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
_workspace = os.path.join(_sample_dir, "game_repo")
|
||||
_trajectories = os.path.join(_sample_dir, "trajectories")
|
||||
os.makedirs(_workspace, exist_ok=True)
|
||||
os.makedirs(_trajectories, exist_ok=True)
|
||||
_sdk_config = LocalAgentConfig(
|
||||
system_instructions="""\
|
||||
You are a senior web game developer. You build small, runnable games on request \
|
||||
as a single self-contained HTML file with inline CSS and JavaScript (no external \
|
||||
assets or third-party dependencies). Write the HTML file into the allowed \
|
||||
workspace using a clean absolute filesystem path.
|
||||
|
||||
Build the file incrementally: first create it with a minimal skeleton (HTML \
|
||||
structure, canvas, and empty script), then add CSS and the game logic over a \
|
||||
few substantial edits. Group each edit around a complete feature (e.g. all \
|
||||
styling, then rendering, then input handling) rather than many tiny changes, \
|
||||
but do not attempt to write the entire game in one step.
|
||||
|
||||
After the file is complete, briefly explain how to play it (open the .html file \
|
||||
in a browser).""",
|
||||
workspaces=[_workspace],
|
||||
policies=[*policy.workspace_only([_workspace])],
|
||||
save_dir=_trajectories,
|
||||
)
|
||||
|
||||
# 2. Wrap the SDK config as a standalone ADK root agent.
|
||||
root_agent = AntigravityAgent(
|
||||
name="antigravity_game_developer",
|
||||
description=(
|
||||
"Builds small, runnable games inside the game_repo workspace via the"
|
||||
" Antigravity SDK."
|
||||
),
|
||||
config=_sdk_config,
|
||||
)
|
||||
Reference in New Issue
Block a user