# Antigravity (/agent-os/multi-framework/antigravity)



`AntigravityAgent` wraps [Managed Agents in the Gemini API](https://ai.google.dev/gemini-api/docs/managed-agents-quickstart) so a Google-managed,
sandboxed agent can be served through AgentOS. A single API call spins up a secure Linux environment where the agent
plans, executes code, searches the web, and reads/writes files. AgentOS handles sessions, streaming, and the UI.

Save the following as `antigravity_agent.py`. After the Install step, start it with `python antigravity_agent.py`. Later snippets are alternatives or fragments using the same imports.

```python
from agno.agents.antigravity import AntigravityAgent
from agno.db.sqlite import SqliteDb
from agno.os import AgentOS

agent = AntigravityAgent(name="Antigravity")

agent_os = AgentOS(
    agents=[agent],
    db=SqliteDb(db_file="tmp/agentos.db"),
)
app = agent_os.get_app()

if __name__ == "__main__":
    agent_os.serve(app="antigravity_agent:app", reload=True)
```

## Install [#install]

```bash
uv pip install "agno[os]"
export GEMINI_API_KEY=...
```

## Parameters [#parameters]

| Parameter                   | Type         | Default                         | Description                                                              |
| --------------------------- | ------------ | ------------------------------- | ------------------------------------------------------------------------ |
| `name`                      | `str`        | `None`                          | Display name for the agent.                                              |
| `id`                        | `str`        | `None`                          | Unique identifier. Auto-generated from `name` if unset.                  |
| `api_key`                   | `str`        | `None`                          | Gemini API key. Falls back to `GEMINI_API_KEY`.                          |
| `base_url`                  | `str`        | Gemini v1beta                   | API base URL.                                                            |
| `agent`                     | `str`        | `"antigravity-preview-05-2026"` | Base agent identifier sent to the API, or a custom agent name.           |
| `sources`                   | `List[Dict]` | `None`                          | GCS / repository / inline sources to seed the sandbox on the first turn. |
| `custom_agent_name`         | `str`        | `None`                          | Register/invoke a named custom agent instead of the base agent.          |
| `custom_agent_instructions` | `str`        | `None`                          | System instructions for the custom agent definition.                     |
| `custom_agent_description`  | `str`        | `None`                          | Description for the custom agent definition.                             |
| `timeout`                   | `int`        | `600`                           | Per-request timeout in seconds.                                          |
| `db`                        | `BaseDb`     | `None`                          | Database for session persistence. Required for cross-turn sandbox reuse. |

## Concepts [#concepts]

### Sessions and environment persistence [#sessions-and-environment-persistence]

Each interaction provisions a managed Linux sandbox and returns an `environment_id`. When a `db` is configured,
`AntigravityAgent` persists that id (and the previous interaction id) in the session, so subsequent turns with the
same `session_id` request reuse of that sandbox. Reuse is subject to provider retention: [inactive environments expire after seven days](https://ai.google.dev/gemini-api/docs/agent-environment#limitations), and an expired environment ID returns `404`.

Without a `db`, every turn provisions a fresh sandbox (no cross-turn reuse).

```python
from agno.agents.antigravity import AntigravityAgent
from agno.db.sqlite import SqliteDb

agent = AntigravityAgent(name="Antigravity", db=SqliteDb(db_file="tmp/antigravity.db"))

agent.print_response("Write a file notes.txt containing 'hello'.", session_id="s1")
agent.print_response("Read notes.txt back to me.", session_id="s1")  # same sandbox
```

### Seeding the environment with sources [#seeding-the-environment-with-sources]

Pass `sources` to preload files into the sandbox before the agent runs. Three source types are supported:
inline content, Google Cloud Storage, and Git repositories.

```python
agent = AntigravityAgent(
    name="Antigravity",
    sources=[
        {"type": "inline", "content": "agno is an agent framework", "target": "/workspace/about.txt"},
        # {"type": "gcs", "source": "gs://my-bucket/data/", "target": "/data"},
        # {"type": "repository", "source": "https://github.com/user/repo", "target": "/repo"},
    ],
)
```

The [provider source limits](https://ai.google.dev/gemini-api/docs/agent-environment#limitations) are 1 MB per inline file and 2 MB total. Agno's directory helper still applies its own 75 KB per-file limit and skips larger or binary files.

### Custom agents [#custom-agents]

Register the custom agent through the [provider's current registration API](https://ai.google.dev/gemini-api/docs/managed-agents-quickstart), then pass its existing ID to Agno:

```python
agent = AntigravityAgent(name="Haiku Bot", agent="your_registered_agent_id")
agent.print_response("Topic: autumn.")
```

<Warning>
  The current `ensure_custom_agent()` helper sends `name` and `instructions`, while the provider registration contract uses `id` and `system_instruction`. Automatic custom registration is an upstream compatibility dependency; use a provider-registered ID until the adapter is aligned. The base agent example above does not use this helper.
</Warning>

### Defining an agent from a directory [#defining-an-agent-from-a-directory]

`from_agent_directory` builds an agent from a local folder following the Managed Agents layout:
`agent.yaml` (id, base\_agent, description, system\_instruction), `AGENTS.md` (overrides
`system_instruction`), `workspace/` (mounted at the sandbox root), and `skills/` (mounted under
`/.agents/skills/`). The default `register=True` calls the registration helper described above. Use `register=False` to inspect a local definition without registration; this does not create a usable remote custom agent.

Create `my-agent/agent.yaml` first:

```yaml
id: my-haiku-agent
base_agent: antigravity-preview-05-2026
system_instruction: Answer with a haiku.
```

```python
from agno.agents.antigravity import AntigravityAgent

agent = AntigravityAgent.from_agent_directory("./my-agent", register=False)
print(agent.custom_agent_name)
```

Register the definition through the provider API before invoking that custom ID.

### Downloading an environment snapshot [#downloading-an-environment-snapshot]

Pull the sandbox filesystem (after a run modified it) as a tar archive.

```python
agent = AntigravityAgent(name="Antigravity", db=SqliteDb(db_file="tmp/antigravity.db"))
agent.print_response("Create /workspace/report.md", stream=False, session_id="s1")
agent.download_environment_snapshot("snapshot.tar", session_id="s1")
```

## Examples [#examples]

<CardGroup cols="2">
  <Card title="AgentOS deployment" icon="server" href="https://github.com/agno-agi/agno/blob/main/cookbook/frameworks/antigravity/antigravity_session_agentos.py">
    Serve an Antigravity agent through AgentOS with persisted sessions.
  </Card>

  <Card title="Standalone usage" icon="play" href="https://github.com/agno-agi/agno/blob/main/cookbook/frameworks/antigravity/antigravity_basic.py">
    Call the agent directly with `.run()` and `.print_response()`.
  </Card>

  <Card title="Sessions" icon="comments" href="https://github.com/agno-agi/agno/blob/main/cookbook/frameworks/antigravity/antigravity_session.py">
    Reuse the sandbox across turns with `session_id`.
  </Card>

  <Card title="Environment sources" icon="folder-tree" href="https://github.com/agno-agi/agno/blob/main/cookbook/frameworks/antigravity/antigravity_sources.py">
    Preload files into the sandbox from inline / GCS / repo sources.
  </Card>

  <Card title="Custom agents" icon="id-badge" href="https://github.com/agno-agi/agno/blob/main/cookbook/frameworks/antigravity/antigravity_custom_agent.py">
    Register and invoke a named custom agent.
  </Card>

  <Card title="Agent from a directory" icon="folder-open" href="https://github.com/agno-agi/agno/blob/main/cookbook/frameworks/antigravity/antigravity_from_agent_directory.py">
    Define an agent from `agent.yaml` + `AGENTS.md` + `workspace/` + `skills/`.
  </Card>

  <Card title="Environment snapshot" icon="file-zipper" href="https://github.com/agno-agi/agno/blob/main/cookbook/frameworks/antigravity/antigravity_snapshot.py">
    Download the sandbox filesystem as a tar archive.
  </Card>
</CardGroup>

## Developer Resources [#developer-resources]

* [Cookbook examples](https://github.com/agno-agi/agno/tree/main/cookbook/frameworks/antigravity)
* [Antigravity as a tool](/tools/toolkits/others/antigravity)
