L'agent Antigravity est un agent géré à usage général sur l'API Gemini. Un seul appel d'API vous donne accès à un agent qui raisonne, exécute du code, gère des fichiers et navigue sur le Web dans votre propre bac à sable Linux sécurisé, hébergé par Google.
Il est optimisé par Gemini 3.6 Flash et utilise le même harnais que l'IDE Antigravity. Vous pouvez configurer le modèle Gemini sous-jacent à l'aide de agent_config. Disponible via l'API Interactions et Google AI Studio.
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="Read Hacker News, summarize the top 10 stories, and save the results as a PDF.",
environment="remote",
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Read Hacker News, summarize the top 10 stories, and save the results as a PDF.",
environment: "remote",
}, { timeout: 300000 });
console.log(interaction.output_text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "Read Hacker News, summarize the top 10 stories, and save the results as a PDF.",
"environment": "remote"
}'
Capacités
Chaque appel peut provisionner un bac à sable Linux et démarrer une boucle d'utilisation d'outil. L'agent planifie, agit, observe les résultats et répète l'opération jusqu'à ce que la tâche soit terminée.
- Exécution de code : exécutez des commandes Bash, Python et Node.js. Installez des packages, exécutez des tests et créez des applications.
- Gestion des fichiers : lire, écrire, modifier, rechercher et lister les fichiers dans le bac à sable. Les fichiers sont conservés d'une interaction à l'autre.
- Accès au Web : recherche Google et récupération d'URL pour les données.
- Compression du contexte : compression automatique du contexte (déclenchée à environ 135 000 jetons) pour prendre en charge les sessions longues et multitours sans perdre le contexte ni atteindre les limites de jetons.
Pour en savoir plus sur l'utilisation multi-tours et le streaming, consultez le guide de démarrage rapide.
Outils compatibles
Par défaut, l'agent a accès à code_execution, google_search et url_context. Les outils du système de fichiers sont activés automatiquement lorsque vous spécifiez le paramètre environment. Vous pouvez également définir des fonctions personnalisées pour connecter l'agent à vos propres API et outils. Il vous suffit de spécifier le paramètre tools lorsque vous personnalisez ou limitez l'ensemble par défaut, ou lorsque vous ajoutez des fonctions personnalisées.
| Outil | Valeur du type | Description |
|---|---|---|
| Exécution du code | code_execution |
Exécutez des commandes shell (bash, Python, Node) avec capture stdout/stderr. |
| Recherche Google | google_search |
Rechercher sur le Web public |
| Contexte de l'URL | url_context |
Récupérer et lire des pages Web |
| Système de fichiers | (activé via environment) |
Lire, écrire, modifier, rechercher et lister des fichiers dans le bac à sable. Le système active automatiquement ces outils lorsque vous définissez environment. |
| Fonctions personnalisées | function |
Définissez des fonctions personnalisées que l'agent peut demander à exécuter. Consultez Appel de fonction. |
| Serveur MCP distant | mcp_server |
Enregistrez des serveurs MCP (Model Context Protocol) externes en tant qu'outils. Consultez Serveurs MCP. |
Vous pouvez intercepter et valider l'exécution des outils code_execution et filesystem directement dans le bac à sable à distance à l'aide de crochets synchrones.
Pour limiter l'agent à des outils spécifiques, ne transmettez que ceux dont vous avez besoin :
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="Search for the latest AI research papers on reasoning and summarize them.",
environment="remote",
tools=[
{"type": "google_search"},
{"type": "url_context"},
],
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Search for the latest AI research papers on reasoning and summarize them.",
environment: "remote",
tools: [
{ type: "google_search" },
{ type: "url_context" },
],
}, { timeout: 300000 });
console.log(interaction.output_text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "Search for the latest AI research papers on reasoning and summarize them.",
"environment": "remote",
"tools": [
{"type": "google_search"},
{"type": "url_context"}
]
}'
Entrée multimodale
L'agent Antigravity est compatible avec les entrées multimodales. Pour le moment, seules les entrées text et image sont acceptées. Les images doivent être fournies sous forme de chaînes encodées en base64 intégrées (data).
Python
import base64
from google import genai
client = genai.Client()
with open("path/to/chart.png", "rb") as f:
image_bytes = f.read()
interaction_inline = client.interactions.create(
agent="antigravity-preview-05-2026",
input=[
{"type": "text", "text": "Analyze this chart and summarize the trends."},
{
"type": "image",
"data": base64.b64encode(image_bytes).decode("utf-8"),
"mime_type": "image/png",
},
],
environment="remote",
)
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
const client = new GoogleGenAI({});
const base64Image = fs.readFileSync("path/to/chart.png", { encoding: "base64" });
const interactionInline = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: [
{ type: "text", text: "Analyze this chart and summarize the trends." },
{
type: "image",
data: base64Image,
mime_type: "image/png",
},
],
environment: "remote",
}, { timeout: 300000 });
REST
BASE64_IMAGE=$(base64 -w0 /path/to/chart.png)
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d "{
\"agent\": \"antigravity-preview-05-2026\",
\"input\": [
{\"type\": \"text\", \"text\": \"Analyze this chart and summarize the trends.\"},
{
\"type\": \"image\",
\"mime_type\": \"image/png\",
\"data\": \"$BASE64_IMAGE\"
}
],
\"environment\": \"remote\"
}"
Appel de fonction
L'appel de fonction vous permet de connecter l'agent Antigravity à des API et des bases de données externes en définissant des outils personnalisés que l'agent peut appeler. Pour en savoir plus sur les concepts généraux, consultez Appel de fonction avec l'API Gemini.
L'exemple suivant illustre une interaction en deux tours. L'agent demande d'abord un appel de fonction get_weather personnalisé, que le client exécute et dont il renvoie le résultat au deuxième tour.
Python
from google import genai
client = genai.Client()
# 1. Define the custom function
get_weather_tool = {
"type": "function",
"name": "get_weather",
"description": "Gets the current weather for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and country, e.g. San Francisco, USA",
}
},
"required": ["location"],
},
}
# 2. Call the agent with the custom tool (Turn 1)
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="What is the weather in Tokyo?",
environment="remote",
tools=[
{"type": "code_execution"}, # Enable default code execution
get_weather_tool, # Add custom function
],
)
# Check if the agent requested a function call
if interaction.status == "requires_action":
# Find function calls that do not have a matching function result.
# Filesystem tools (like write_file) are also represented as function calls
# but are executed automatically by the environment.
executed_calls = {step.call_id for step in interaction.steps if step.type == "function_result"}
pending_calls = [step for step in interaction.steps if step.type == "function_call" and step.id not in executed_calls]
if pending_calls:
fc_step = pending_calls[0]
print(f"Function to call: {fc_step.name} (ID: {fc_step.id})")
print(f"Arguments: {fc_step.arguments}")
# 3. Execute the function locally (simulated get_weather()) and send the result back (Turn 2)
function_result = {
"temperature": 23,
"unit": "celsius"
}
final_interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
previous_interaction_id=interaction.id, # Reference the interaction ID
environment=interaction.environment_id,
input=[
{
"type": "function_result",
"name": fc_step.name,
"call_id": fc_step.id,
"result": function_result,
}
],
)
print(final_interaction.output_text)
# Output: The current weather in Tokyo, Japan is 23°C (Celsius).
else:
print("No pending function calls.")
else:
print(f"Interaction completed with status: {interaction.status}")
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// 1. Define the custom function
const get_weather_tool = {
type: "function",
name: "get_weather",
description: "Gets the current weather for a given location.",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and country, e.g. San Francisco, USA",
},
},
required: ["location"],
},
};
// 2. Call the agent with the custom tool (Turn 1)
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "What is the weather in Tokyo?",
environment: "remote",
tools: [
{ type: "code_execution" },
get_weather_tool,
],
}, { timeout: 300000 });
if (interaction.status === "requires_action") {
// Find function calls that do not have a matching function result.
// Filesystem tools (like write_file) are also represented as function calls
// but are executed automatically by the environment.
const executedCalls = new Set(
interaction.steps
.filter(s => s.type === "function_result")
.map(s => s.call_id)
);
const pendingCalls = interaction.steps.filter(
s => s.type === "function_call" && !executedCalls.has(s.id)
);
if (pendingCalls.length > 0) {
const fcStep = pendingCalls[0];
console.log(`Function to call: ${fcStep.name} (ID: ${fcStep.id})`);
// 3. Execute the function locally (simulated get_weather()) and send the result back (Turn 2)
const functionResult = {
temperature: 23,
unit: "celsius"
};
const finalInteraction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
previous_interaction_id: interaction.id, // Reference the interaction ID
environment: interaction.environment_id,
input: [
{
type: "function_result",
name: fcStep.name,
call_id: fcStep.id,
result: functionResult,
}
],
}, { timeout: 300000 });
console.log(finalInteraction.output_text);
} else {
console.log("No pending function calls.");
}
} else {
console.log(`Interaction completed with status: ${interaction.status}`);
}
REST
# 1. Turn 1: Request function call
RESPONSE=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "What is the weather in Tokyo?",
"environment": "remote",
"tools": [
{"type": "code_execution"},
{
"type": "function",
"name": "get_weather",
"description": "Gets the current weather for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}
]
}')
# Extract interaction ID, environment ID, and call ID (requires jq)
INTERACTION_ID=$(echo $RESPONSE | jq -r '.id')
ENVIRONMENT_ID=$(echo $RESPONSE | jq -r '.environment_id')
CALL_ID=$(echo $RESPONSE | jq -r '.steps[] | select(.type=="function_call") | .id')
# 2. Turn 2: Send function result back using variables
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d "{
\"agent\": \"antigravity-preview-05-2026\",
\"previous_interaction_id\": \"$INTERACTION_ID\",
\"environment\": \"$ENVIRONMENT_ID\",
\"input\": [
{
\"type\": \"function_result\",
\"name\": \"get_weather\",
\"call_id\": \"$CALL_ID\",
\"result\": {
\"temperature\": 23,
\"unit\": \"celsius\"
}
}
]
}"
Serveurs MCP
Vous pouvez connecter l'agent Antigravity à des outils externes en enregistrant des serveurs MCP (Model Context Protocol) distants. L'agent est compatible avec les serveurs MCP distants via HTTP en flux continu.
Lorsque vous enregistrez un serveur MCP, vous devez spécifier les champs suivants dans le tableau tools :
| Champ | Type | Obligatoire | Description |
|---|---|---|---|
type |
chaîne | Oui | doit être "mcp_server" |
name |
chaîne | Oui | Identifiant unique du serveur. Doit être strictement en minuscules et alphanumérique (correspondant à ^[a-z0-9_-]+$). |
url |
chaîne | Oui | URL du point de terminaison du serveur MCP distant. |
headers |
objet | Non | En-têtes personnalisés (par exemple, pour l'authentification) envoyés avec les requêtes. |
allowed_tools |
tableau | Non | Liste des noms d'outils pouvant être exécutés. Si cette option est omise, tous les outils sont autorisés. |
Python
from google import genai
client = genai.Client()
# Register a remote HTTP MCP server
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="What is the weather in Tokyo?",
environment="remote",
tools=[{
"type": "mcp_server",
"name": "weather", # Must be lowercase
"url": "https://gemini-api-demos.uc.r.appspot.com/mcp"
}]
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "What is the weather in Tokyo?",
environment: "remote",
tools: [{
type: "mcp_server",
name: "weather", // Must be lowercase
url: "https://gemini-api-demos.uc.r.appspot.com/mcp"
}]
}, { timeout: 300000 });
console.log(interaction.output_text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "What is the weather in Tokyo?",
"environment": "remote",
"tools": [{
"type": "mcp_server",
"name": "weather",
"url": "https://gemini-api-demos.uc.r.appspot.com/mcp"
}]
}'
Sélection du modèle
Pour antigravity-preview-05-2026, le modèle par défaut est Gemini 3.6 Flash (gemini-3.6-flash). Si vous omettez agent_config, l'agent utilise gemini-3.6-flash par défaut.
Vous pouvez configurer le modèle Gemini sous-jacent à l'aide de agent_config pour optimiser la vitesse, le coût ou la capacité de raisonnement.
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="Summarize the key differences between functional and object-oriented programming.",
environment="remote",
agent_config={
"type": "antigravity",
"model": "gemini-3.5-flash-lite",
},
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Summarize the key differences between functional and object-oriented programming.",
environment: "remote",
agent_config: {
type: "antigravity",
model: "gemini-3.5-flash-lite",
},
}, { timeout: 300000 });
console.log(interaction.output_text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "Summarize the key differences between functional and object-oriented programming.",
"environment": "remote",
"agent_config": {
"type": "antigravity",
"model": "gemini-3.5-flash-lite"
}
}'
Les valeurs acceptées pour agent_config.model sont les suivantes :
| Modèle | Valeur dans agent_config.model |
Description |
|---|---|---|
| Gemini 3.6 Flash (par défaut) | gemini-3.6-flash |
Modèle équilibré par défaut pour le raisonnement, le codage et l'utilisation d'outils. |
| Gemini 3.5 Flash | gemini-3.5-flash |
Modèle Flash de génération précédente pour les workflows agentiques généraux. |
| Gemini 3.5 Flash-Lite | gemini-3.5-flash-lite |
Modèle léger optimisé pour les tâches à faible latence et sensibles aux coûts. |
Lorsque vous créez un agent géré avec agents.create, vous configurez le modèle exactement de la même manière en transmettant base_agent et agent_config. Notez que vous ne pouvez pas remplacer le modèle au moment de l'interaction pour un agent géré créé avec agents.create. Le modèle est verrouillé sur ce qui a été défini lors de la création de l'agent. Cela garantit un comportement prévisible des appels d'outils, un débogage cohérent et le respect des limites de sécurité.
Personnaliser l'agent
Vous pouvez étendre l'agent Antigravity en personnalisant ses instructions, ses outils et son environnement. L'agent prend en charge une approche de personnalisation native du système de fichiers : vous pouvez monter des fichiers tels que AGENTS.md pour les instructions et les compétences sous .agents/skills/ directement dans le bac à sable, ou transmettre la configuration en ligne au moment de l'interaction. Vous pouvez itérer sur votre configuration en ligne, puis l'enregistrer en tant qu'agent géré lorsque vous êtes prêt.
Pour en savoir plus sur la création d'agents personnalisés, consultez Créer des agents gérés.
Exécution en arrière-plan
Les tâches d'agent qui impliquent un raisonnement en plusieurs étapes, l'exécution de code ou des opérations sur des fichiers peuvent prendre plusieurs minutes. Utilisez background=True pour exécuter l'interaction de manière asynchrone. L'API renvoie immédiatement un ID d'interaction que vous interrogez jusqu'à ce que l'état soit completed ou failed.
Python
import time
from google import genai
client = genai.Client()
# 1. Start the interaction in the background
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="Run a complex analysis on the repository.",
environment="remote",
background=True,
)
print(f"Interaction started in background: {interaction.id}")
# 2. Poll for completion
while interaction.status == "in_progress":
time.sleep(5)
interaction = client.interactions.get(id=interaction.id)
if interaction.status == "completed":
print(interaction.output_text)
else:
print(f"Finished with status: {interaction.status}")
JavaScript
import { GoogleGenAI