Tác nhân Antigravity

Tác nhân Antigravity là một tác nhân được quản lý đa năng trên Gemini API. Một lệnh gọi API duy nhất sẽ cung cấp cho bạn một tác nhân có khả năng suy luận, thực thi mã, quản lý tệp và duyệt web trong hộp cát Linux bảo mật của riêng bạn, do Google lưu trữ.

Công cụ này dựa trên Gemini 3.6 Flash và sử dụng cùng một cơ chế như Antigravity IDE. Bạn có thể định cấu hình mô hình Gemini cơ bản bằng cách sử dụng agent_config. Có trong Interactions APIGoogle 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"
}'

Tính năng

Mỗi lệnh gọi có thể cung cấp một hộp cát Linux và bắt đầu một vòng lặp sử dụng công cụ. Tác nhân lập kế hoạch, hành động, quan sát kết quả và lặp lại cho đến khi hoàn thành nhiệm vụ.

  • Thực thi mã: Chạy các lệnh Bash, Python và Node.js. Cài đặt gói, chạy kiểm thử, tạo ứng dụng.
  • Quản lý tệp: Đọc, ghi, chỉnh sửa, tìm kiếm và liệt kê các tệp trong hộp cát. Các tệp vẫn tồn tại trong các lượt tương tác.
  • Quyền truy cập vào web: Google Tìm kiếm và tìm nạp URL để lấy dữ liệu.
  • Nén bối cảnh: Tự động nén bối cảnh (kích hoạt ở khoảng 135.000 mã thông báo) để hỗ trợ các phiên kéo dài nhiều lượt mà không làm mất bối cảnh hoặc vượt quá giới hạn mã thông báo.

Hãy xem phần Bắt đầu nhanh để biết cách sử dụng nhiều lượt và phát trực tuyến.

Các công cụ được hỗ trợ

Theo mặc định, tác nhân có quyền truy cập vào code_execution, google_searchurl_context. Các công cụ hệ thống tệp sẽ tự động được bật khi bạn chỉ định tham số environment. Bạn cũng có thể xác định các hàm tuỳ chỉnh để kết nối tác nhân với các API và công cụ của riêng mình. Bạn chỉ cần chỉ định tham số tools khi tuỳ chỉnh hoặc hạn chế bộ mặc định, hoặc khi thêm các hàm tuỳ chỉnh.

Công cụ Giá trị loại Mô tả
Thực thi mã code_execution Chạy các lệnh shell (bash, Python, Node) với tính năng ghi lại stdout/stderr.
Google Tìm kiếm google_search Tìm kiếm trên web công khai.
Bối cảnh từ URL url_context Tìm nạp và đọc các trang web.
Hệ thống tệp (được bật thông qua environment) Đọc, ghi, chỉnh sửa, tìm kiếm và liệt kê các tệp trong hộp cát. Hệ thống sẽ tự động bật các công cụ này khi bạn đặt environment.
Hàm tuỳ chỉnh function Xác định các hàm tuỳ chỉnh mà tác nhân có thể yêu cầu thực thi. Xem phần Gọi hàm.
Máy chủ MCP từ xa mcp_server Đăng ký các máy chủ Giao thức ngữ cảnh mô hình (MCP) bên ngoài dưới dạng công cụ. Xem phần Máy chủ MCP.

Bạn có thể chặn và xác thực việc thực thi công cụ code_executionfilesystem ngay trong hộp cát từ xa bằng cách sử dụng Hooks đồng bộ.

Để giới hạn tác nhân ở những công cụ cụ thể, hãy chỉ truyền những công cụ bạn cần:

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"}
    ]
}'

Thông tin đầu vào đa phương thức

Tác nhân Antigravity hỗ trợ nhiều phương thức nhập. Hiện tại, chúng tôi chỉ hỗ trợ đầu vào textimage. Bạn phải cung cấp hình ảnh dưới dạng chuỗi được mã hoá base64 cùng dòng (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\"
}"

Gọi hàm

Tính năng gọi hàm cho phép bạn kết nối tác nhân Antigravity với các API và cơ sở dữ liệu bên ngoài bằng cách xác định các công cụ tuỳ chỉnh mà tác nhân có thể gọi. Để biết các khái niệm chung, hãy xem phần Gọi hàm bằng Gemini API.

Ví dụ sau đây minh hoạ một lượt tương tác gồm 2 lượt. Trước tiên, tác nhân yêu cầu một lệnh gọi hàm get_weather tuỳ chỉnh, sau đó máy khách thực thi lệnh gọi hàm đó và trả về kết quả trong lượt thứ hai.

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"