Xây dựng các tác nhân được quản lý

Các tác nhân được quản lý trên Gemini API cho phép bạn mở rộng tác nhân Antigravity bằng các hướng dẫn, kỹ năng và dữ liệu của riêng mình. Bạn có thể tuỳ chỉnh tác nhân cùng dòng tại thời điểm tương tác hoặc lưu cấu hình dưới dạng tác nhân được quản lý mà bạn gọi theo mã nhận dạng.

Tuỳ chỉnh tác nhân Antigravity

Cách nhanh nhất để tạo tác nhân tuỳ chỉnh là truyền cấu hình cùng dòng trong khi tạo một lượt tương tác mới mà không cần bước đăng ký. Bạn có thể mở rộng tác nhân theo 3 cách:

  • Hướng dẫn hệ thống: Truyền văn bản cùng dòng thông qua system_instruction để định hình hành vi.
  • Công cụ: Ghi đè các công cụ mặc định (Thực thi mã, Tìm kiếm, Ngữ cảnh URL), đăng ký các máy chủ MCP từ xa hoặc xác định các hàm tuỳ chỉnh (Gọi hàm).
  • Tệp và kỹ năng: Gắn các tệp như AGENTS.mdSKILL.md vào môi trường.

Sau đây là ví dụ về cách truyền cả 3 cùng dòng:

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    agent="antigravity-preview-05-2026",
    input="Analyze the Q1 revenue data and create a slide deck.",
    system_instruction="You are a data analyst. Always include visualizations and export results as PDF.",        
    environment={
        "type": "remote",
        "sources": [
            {
                "type": "inline",
                "target": ".agents/AGENTS.md",
                "content": "Always use matplotlib for charts. Include a summary table in every report.",
            },
            {
                "type": "inline",
                "target": ".agents/skills/slide-maker/SKILL.md",
                "content": "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results.",
            },
        ],
    },
)

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: "Analyze the Q1 revenue data and create a slide deck.",
    system_instruction: "You are a data analyst. Always include visualizations and export results as PDF.",        
    environment: {
        type: "remote",
        sources: [
            {
                type: "inline",
                target: ".agents/AGENTS.md",
                content: "Always use matplotlib for charts. Include a summary table in every report.",
            },
            {
                type: "inline",
                target: ".agents/skills/slide-maker/SKILL.md",
                content: "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results.",
            },
        ],
    },
}, { 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": "Analyze the Q1 revenue data and create a slide deck.",
    "system_instruction": "You are a data analyst. Always include visualizations and export results as PDF.",
    "environment": {
        "type": "remote",
        "sources": [
            {
                "type": "inline",
                "target": ".agents/AGENTS.md",
                "content": "Always use matplotlib for charts. Include a summary table in every report."
            },
            {
                "type": "inline",
                "target": ".agents/skills/slide-maker/SKILL.md",
                "content": "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results."
            }
        ]
    }
}'

Mọi thứ đều được xác định tại thời điểm tương tác. Không cần đăng ký trước. Hệ thống tác nhân Antigravity cung cấp thời gian chạy (thực thi mã, quản lý tệp, truy cập web) và các lớp cấu hình của bạn ở trên cùng.

Công cụ và hướng dẫn hệ thống

Bạn có thể tuỳ chỉnh hành vi và khả năng của tác nhân cho một lượt tương tác cụ thể bằng các tham số system_instructiontools.

  • Hướng dẫn hệ thống: Sử dụng tham số system_instruction để truyền văn bản cùng dòng định hình hành vi của tác nhân. Đây là cách lý tưởng để điều chỉnh nhanh chóng theo từng lệnh gọi. system_instructionAGENTS.md là các tham số bổ sung; cả hai đều áp dụng khi có mặt.
  • Công cụ: Theo mặc định, tác nhân Antigravity có quyền truy cập vào code_execution, google_search, và url_context. Bạn có thể ghi đè danh sách này bằng cách truyền tham số tools tại thời điểm tương tác. Bạn cũng có thể đăng ký các máy chủ MCP từ xa hoặc xác định các hàm tuỳ chỉnh (gọi hàm) để kết nối tác nhân với các API và cơ sở dữ liệu của riêng bạn. Để biết thông tin chi tiết đầy đủ về các công cụ có sẵn, hãy xem bài viết Tác nhân Antigravity: Các công cụ được hỗ trợ.

Tuỳ chỉnh dựa trên tệp

Cấu trúc thư mục của tác nhân

Mặc dù bạn có thể truyền cấu hình cùng dòng, nhưng bạn nên sắp xếp các tệp của tác nhân trong một thư mục có cấu trúc. Điều này giúp bạn dễ dàng quản lý, kiểm soát phiên bản và gắn vào môi trường của tác nhân.

Thư mục dự án tác nhân điển hình có dạng như sau:

my-agent/
├── AGENTS.md        # Instructions on how the agent should operate
├── skills/          # Custom skills (subfolders and SKILL.md files)
│   └── slide-maker/
│       └── SKILL.md
└── workspace/       # Initial data files and knowledge

Thời gian chạy Antigravity sẽ quét .agents/ (và gốc của môi trường) để tìm các tệp này.

AGENTS.md

Tác nhân sẽ tự động tải .agents/AGENTS.md (hoặc /.agents/AGENTS.md) từ môi trường dưới dạng hướng dẫn hệ thống khi khởi động. Sử dụng AGENTS.md cho các định nghĩa về nhân vật dài, hướng dẫn chi tiết và hướng dẫn mà bạn muốn kiểm soát phiên bản cùng với mã của mình.

Gắn AGENTS.md bằng nguồn cùng dòng:

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    agent="antigravity-preview-05-2026",
    input="Analyze the Q1 revenue data and create a report.",
    system_instruction="You are a data analyst. Always include visualizations and export results as PDF.",
    environment={
        "type": "remote",
        "sources": [
            {
                "type": "inline",
                "target": ".agents/AGENTS.md",
                "content": "Always use matplotlib for charts. Include a summary table in every report.",
            },
        ],
    },
)

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: "Analyze the Q1 revenue data and create a report.",
    system_instruction: "You are a data analyst. Always include visualizations and export results as PDF.",
    environment: {
        type: "remote",
        sources: [
            {
                type: "inline",
                target: ".agents/AGENTS.md",
                content: "Always use matplotlib for charts. Include a summary table in every report.",
            },
        ],
    },
}, { 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": "Analyze the Q1 revenue data and create a report.",
      "system_instruction": "You are a data analyst. Always include visualizations and export results as PDF.",
      "environment": {
          "type": "remote",
          "sources": [
              {
                  "type": "inline",
                  "target": ".agents/AGENTS.md",
                  "content": "Always use matplotlib for charts. Include a summary table in every report."
              }
          ]
      }
  }'

Kỹ năng: SKILL.md

Kỹ năng là các tệp mở rộng khả năng của tác nhân. Đặt các tệp này trong .agents/skills/<skill-name>/SKILL.md và hệ thống sẽ tự động phát hiện và đăng ký các tệp này.

.agents/
├── AGENTS.md
└── skills/
    └── slide-maker/
        └── SKILL.md

Gắn một kỹ năng bằng nguồn cùng dòng:

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    agent="antigravity-preview-05-2026",
    input="Create a presentation about our Q1 results.",
    system_instruction="You create presentations from data.",
    environment={
        "type": "remote",
        "sources": [
            {
                "type": "inline",
                "target": ".agents/skills/slide-maker/SKILL.md",
                "content": "---\nname: slide-maker\ndescription: Create HTML slide decks\n---\n# Slide Maker\n\nWhen asked to create a presentation:\n1. Analyze the input data\n2. Create an HTML slide deck with reveal.js\n3. Save to /workspace/output/slides.html",
            },
        ],
    },
)

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: "Create a presentation about our Q1 results.",
    system_instruction: "You create presentations from data.",
    environment: {
        type: "remote",
        sources: [
            {
                type: "inline",
                target: ".agents/skills/slide-maker/SKILL.md",
                content: "---\nname: slide-maker\ndescription: Create HTML slide decks\n---\n# Slide Maker\n\nWhen asked to create a presentation:\n1. Analyze the input data\n2. Create an HTML slide deck with reveal.js\n3. Save to /workspace/output/slides.html",
            },
        ],
    },
}, { 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": "Create a presentation about our Q1 results.",
      "system_instruction": "You create presentations from data.",
      "environment": {
          "type": "remote",
          "sources": [
              {
                  "type": "inline",
                  "target": ".agents/skills/slide-maker/SKILL.md",
                  "content": "---\nname: slide-maker\ndescription: Create HTML slide decks\n---\n# Slide Maker\n\nWhen asked to create a presentation:\n1. Analyze the input data\n2. Create an HTML slide deck with reveal.js\n3. Save to /workspace/output/slides.html"
              }
          ]
      }
  }'

Các kỹ năng được tải từ .agents/skills//.agents/skills/ đều được tự động phát hiện.

Tạo tác nhân được quản lý

Sau khi lặp lại cấu hình, bạn có thể tạo cấu hình đó dưới dạng tác nhân được quản lý bằng agents.create. Điều này cho phép bạn gọi tác nhân theo mã nhận dạng mà không cần lặp lại cấu hình mỗi lần.

Từ nguồn

Chỉ định base_agent, id, system_instructionbase_environment bằng nguồn. Nền tảng này cung cấp một hộp cát mới với các tệp của bạn trên mỗi lệnh gọi. Xem phần Môi trường để biết các loại nguồn có sẵn (Git, GCS, cùng dòng).

Python

from google import genai

client = genai.Client()

agent = client.agents.create(
    id="data-analyst",
    base_agent="antigravity-preview-05-2026",
    system_instruction="You are a data analyst. Always include visualizations and export results as PDF.",
    base_environment={
        "type": "remote",
        "sources": [
            {
                "type": "inline",
                "target": ".agents/AGENTS.md",
                "content": "Always use matplotlib for charts. Include a summary table in every report.",
            },
            {
                "type": "inline",
                "target": ".agents/skills/slide-maker/SKILL.md",
                "content": "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results.",
            },
            {
                "type": "repository",
                "source": "https://github.com/my-org/analysis-templates",
                "target": "/workspace/templates",
            },
        ],
    },
)

print(f"Created agent: {agent.id}")

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const agent = await client.agents.create({
    id: "data-analyst",
    base_agent: "antigravity-preview-05-2026",
    system_instruction: "You are a data analyst. Always include visualizations and export results as PDF.",
    base_environment: {
        type: "remote",
        sources: [
            {
                type: "inline",
                target: ".agents/AGENTS.md",
                content: "Always use matplotlib for charts. Include a summary table in every report.",
            },
            {
                type: "inline",
                target: ".agents/skills/slide-maker/SKILL.md",
                content: "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results.",
            },
            {
                type: "repository",
                source: "https://github.com/my-org/analysis-templates",
                target: "/workspace/templates",
            },
        ],
    },
});

console.log(`Created agent: ${agent.id}`);

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/agents" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "id": "data-analyst",
    "base_agent": "antigravity-preview-05-2026",
    "system_instruction": "You are a data analyst. Always include visualizations and export results as PDF.",
    "base_environment": {
        "type": "remote",
        "sources": [
            {
                "type": "inline",
                "target": ".agents/AGENTS.md",
                "content": "Always use matplotlib for charts. Include a summary table in every report."
            },
            {
                "type": "inline",
                "target": ".agents/skills/slide-maker/SKILL.md",
                "content": "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results."
            },
            {
                "type": "repository",
                "source": "https://github.com/my-org/analysis-templates",
                "target": "/workspace/templates"
            }
        ]
    }
}'

Từ môi trường hiện có (phân nhánh)

Lặp lại với tác nhân Antigravity cơ sở cho đến khi môi trường phù hợp (đã cài đặt các gói, tệp ở đúng vị trí), sau đó phân nhánh thành tác nhân được quản lý.

Python

from google import genai

client = genai.Client()

# Step 1: set up the environment interactively
interaction = client.interactions.create(
    agent="antigravity-preview-05-2026",
    input="Install pandas, matplotlib, and seaborn. Create an analysis template at /workspace/template.py.",
    environment="remote",
)

# Step 2: fork that environment into a managed agent

agent = client.agents.create(
    id="my-data-analyst",
    base_agent="antigravity-preview-05-2026",
    system_instruction="You are a data analyst. Use the template at /workspace/template.py for all reports.",
    base_environment=interaction.environment_id,
)

print(f"Forked agent successfully: {agent.id}")

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    agent: "antigravity-preview-05-2026",
    input: "Install pandas, matplotlib, and seaborn. Create an analysis template at /workspace/template.py.",
    environment: "remote",
}, { timeout: 300000 });

const agent = await client.agents.create({
    id: "my-data-analyst",
    base_agent: "antigravity-preview-05-2026",
    system_instruction: "You are a data analyst. Use the template at /workspace/template.py for all reports.",
    base_environment: interaction.environment_id,
});

console.log(`Forked agent successfully: ${agent.id}`);

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": "Install pandas, matplotlib, and seaborn. Create an analysis template at /workspace/template.py.",
      "environment": "remote"
  }'

Với các quy tắc mạng

Bạn có thể khoá quyền truy cập исходящий hoặc chèn thông tin đăng nhập khi lưu tác nhân được quản lý. Để biết lược đồ danh sách cho phép đầy đủ, mẫu thông tin đăng nhập và ký tự đại diện, hãy xem phần Môi trường: Cấu hình mạng.

Ví dụ sau đây tạo tác nhân issue-resolver chỉ có thể truy cập vào GitHub và PyPI, với thông tin đăng nhập được chèn cho GitHub:

Python

from google import genai

client = genai.Client()

agent = client.agents.create(
    id="issue-resolver",
    base_agent="antigravity-preview-05-2026",
    system_instruction="You resolve GitHub issues. Clone the repo, find the bug, write the fix, run the tests, and open a PR.",
    base_environment={
        "type": "remote",
        "sources": [
            {
                "type": "repository",
                "source": "https://github.com/my-org/backend",
                "target": "/workspace/repo",
            }
        ],
        "network": {
            "allowlist": [
                {
                    "domain": "api.github.com",
                    "transform": {
                        "Authorization": "Basic YOUR_BASE64_TOKEN"
                    },
                },
                {"domain": "pypi.org"},
            ]
        },
    },
)

print(f"Created issue-resolver agent successfully: {agent.id}")

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const agent = await client.agents.create({
    id: "issue-resolver",
    base_agent: "antigravity-preview-05-2026",
    system_instruction: "You resolve GitHub issues. Clone the repo, find the bug, write the fix, run the tests, and open a PR.",
    base_environment: {
        type: "remote",
        sources: [
            {
                type: "repository",
                source: "https://github.com/my-org/backend",
                target: "/workspace/repo",
            }
        ],
        network: {
            allowlist: [
                {
                    domain: "api.github.com",
                    transform: {
                        "Authorization": "Basic YOUR_BASE64_TOKEN"
                    },
                },
                { domain: "pypi.org" },
            ]
        }
    },
});

console.log(`Created issue-resolver agent successfully: ${agent.id}`);

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/agents" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -d '{
      "id": "issue-resolver",
      "base_agent": "antigravity-preview-05-2026",
      "system_instruction": "You resolve GitHub issues. Clone the repo, find the bug, write the fix, run the tests, and open a PR.",
      "base_environment": {
          "type": "remote",
          "sources": [
              {
                  "type": "repository",
                  "source": "https://github.com/my-org/backend",
                  "target": "/workspace/repo"
              }
          ],
          "network": {
              "allowlist": [
                  {
                      "domain": "api.github.com",
                      "transform": {
                          "Authorization": "Basic YOUR_BASE64_TOKEN"
                      }
                  },
                  {"domain": "pypi.org"}
              ]
          }
      }
  }'

Gọi tác nhân

Gọi tác nhân được quản lý bằng mã nhận dạng tác nhân bằng cách tạo một lượt tương tác mới. Mỗi lệnh gọi sẽ phân nhánh môi trường cơ sở, vì vậy, mỗi lần chạy đều bắt đầu từ đầu.

Python

result = client.interactions.create(
    agent="data-analyst",
    input="Analyze Q1 revenue data from /workspace/templates/sample.csv and create a slide deck.",
    environment="remote",
)

print(result.output_text)

JavaScript

const result = await client.interactions.create({
    agent: "data-analyst",
    input: "Analyze Q1 revenue data from /workspace/templates/sample.csv and create a slide deck.",
    environment: "remote",
}, { timeout: 300000 });

console.log(result.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": "data-analyst",
      "input": "Analyze Q1 revenue data from /workspace/templates/sample.csv and create a slide deck.",
      "environment": "remote"
  }'

Đối với các cuộc trò chuyện nhiều lượt và phát trực tiếp, hãy xem phần Bắt đầu nhanh. Các mẫu previous_interaction_idenvironment tương tự áp dụng cho các tác nhân được quản lý.

Các tác nhân được quản lý cũng hỗ trợ thực thi và huỷ trong nền. Để biết thông tin chi tiết và ví dụ về mã, hãy xem bài viết Tác nhân Antigravity: Thực thi trong nền.

Ghi đè cấu hình khi gọi

Bạn có thể ghi đè cấu hình mạng system_instruction, toolsenvironment mặc định của tác nhân khi tạo một lượt tương tác. Điều này cho phép bạn sửa đổi hành vi, khả năng hoặc thông tin đăng nhập của tác nhân cho một lần chạy cụ thể mà không thay đổi định nghĩa tác nhân đã lưu trữ.

Ghi đè hướng dẫn hệ thống và công cụ

Python

result = client.interactions.create(
    agent="data-analyst",
    input="Analyze Q1 revenue data, but do not create a slide deck. Just output a summary table.",
    system_instruction="You are a data analyst. Focus ONLY on summary tables. Ignore default instructions about slides.",
    tools=[{"type": "code_execution"}], # Override to only use code execution
    environment="remote",
)
print(result.output_text)

JavaScript

const result = await client.interactions.create({
    agent: "data-analyst",
    input: "Analyze Q1 revenue data, but do not create a slide deck. Just output a summary table.",
    system_instruction: "You are a data analyst. Focus ONLY on summary tables. Ignore default instructions about slides.",
    tools: [{ type: "code_execution" }], // Override to only use code execution
    environment: "remote",
}, { timeout: 300000 });

console.log(result.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": "data-analyst",
      "input": "Analyze Q1 revenue data, but do not create a slide deck. Just output a summary table.",
      "system_instruction": "You are a data analyst. Focus ONLY on summary tables. Ignore default instructions about slides.",
      "tools": [{"type": "code_execution"}],
      "environment": "remote"
  }'

Ghi đè cấu hình mạng (làm mới thông tin đăng nhập)

Nếu tác nhân được quản lý của bạn có thông tin đăng nhập mạng được tích hợp vào base_environment, bạn có thể ghi đè các thông tin đăng nhập đó tại thời điểm gọi để làm mới mã thông báo đã hết hạn hoặc xoay vòng khoá API. Truyền đối tượng environment bằng cấu hình network mới. Các quy tắc mạng mới sẽ thay thế hoàn toàn các quy tắc trước đó cho lượt tương tác đó. Các nguồn của môi trường cơ sở (tệp, kho lưu trữ) được giữ nguyên.

Python

# Invoke the agent with a fresh token, overriding the base_environment credentials
result = client.interactions.create(
    agent="issue-resolver",
    input="Fix issue #42 and open a PR.",
    environment={
        "type": "remote",
        "network": {
            "allowlist": [
                {
                    "domain": "api.github.com",
                    "transform": {
                        "Authorization": "Bearer ghp_REFRESHED_TOKEN"
                    },
                },
                {"domain": "pypi.org"},
            ]
        },
    },
)

print(result.output_text)

JavaScript

// Invoke the agent with a fresh token, overriding the base_environment credentials
const result = await client.interactions.create({
    agent: "issue-resolver",
    input: "Fix issue #42 and open a PR.",
    environment: {
        type: "remote",
        network: {
            allowlist: [
                {
                    domain: "api.github.com",
                    transform: {
                        "Authorization": "Bearer ghp_REFRESHED_TOKEN"
                    },
                },
                { domain: "pypi.org" },
            ]
        },
    },
}, { timeout: 300000 });

console.log(result.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": "issue-resolver",
      "input": "Fix issue #42 and open a PR.",
      "environment": {
          "type": "remote",
          "network": {
              "allowlist": [
                  {
                      "domain": "api.github.com",
                      "transform": {
                          "Authorization": "Bearer ghp_REFRESHED_TOKEN"
                      }
                  },
                  {"domain": "pypi.org"}
              ]
          }
      }
  }'

Quản lý nhân viên hỗ trợ

Bạn có thể liệt kê, lấy và xoá tác nhân.

Liệt kê tác nhân

Python

agents = client.agents.list()
for a in agents.agents:
    print(f"{a.id}: {a.description}")

JavaScript

const agents = await client.agents.list();
if (agents.agents) {
    for (const a of agents.agents) {
        console.log(`${a.id}: ${a.description}`);
    }
}

REST

curl -X GET "https://generativelanguage.googleapis.com/v1beta/agents" \
  -H "x-goog-api-key: $GEMINI_API_KEY"

Lấy tác nhân

Python

agent = client.agents.get(id="data-analyst")
print(agent)

JavaScript

const agent = await client.agents.get("data-analyst");
console.log(agent);

REST

curl -X GET "https://generativelanguage.googleapis.com/v1beta/agents/data-analyst" \
  -H "x-goog-api-key: $GEMINI_API_KEY"

Xoá tác nhân

Việc xoá sẽ loại bỏ cấu hình. Các môi trường và lượt tương tác hiện có do tác nhân tạo sẽ không bị ảnh hưởng.

Python

client.agents.delete(id="data-analyst")

JavaScript

await client.agents.delete("data-analyst");

REST

curl -X DELETE "https://generativelanguage.googleapis.com/v1beta/agents/data-analyst" \
  -H "x-goog-api-key: $GEMINI_API_KEY"

Tài liệu tham khảo về định nghĩa tác nhân

Trường Loại Bắt buộc Mô tả
id chuỗi Giá trị nhận dạng riêng biệt của tác nhân. Dùng để gọi tác nhân.
description chuỗi Không Mô tả về tác nhân mà con người đọc được.
base_agent chuỗi Mã nhận dạng tác nhân cơ sở (ví dụ: antigravity-preview-05-2026).
system_instruction chuỗi Không Lời nhắc hệ thống xác định hành vi và nhân vật.
tools mảng Không Các công cụ mà tác nhân có thể sử dụng. Nếu bị bỏ qua, giá trị mặc định là code_execution, google_searchurl_context. Các công cụ được hỗ trợ bao gồm code_execution, google_search, url_context, mcp_server và các định nghĩa function tuỳ chỉnh.
base_environment chuỗi hoặc đối tượng Không "remote", environment_id hoặc đối tượng cấu hình có sourcesnetwork. Xem phần Môi trường.

Quy trình lặp lại

  1. Nguyên mẫu với tác nhân Antigravity cơ sở. Truyền hướng dẫn hệ thống và nguồn môi trường cùng dòng. Kiểm thử hướng dẫn, kỹ năng và thiết lập môi trường một cách tương tác.
  2. Ổn định môi trường. Cài đặt các gói, gắn nguồn, xác minh mọi thứ hoạt động.
  3. Duy trì dưới dạng tác nhân được quản lý bằng cách tạo tác nhân mới, từ nguồn hoặc bằng cách phân nhánh môi trường.
  4. Cập nhật định nghĩa tác nhân. Thay đổi hướng dẫn hệ thống, hoán đổi kỹ năng hoặc thêm nguồn. Lần gọi tiếp theo sẽ chọn cấu hình mới.

Các điểm hạn chế

  • Xem trước trạng thái: Các tác nhân được quản lý đang ở chế độ xem trước. Các tính năng và lược đồ có thể thay đổi.
  • Tác nhân cơ sở: Chỉ antigravity-preview-05-2026 được hỗ trợ dưới dạng base_agent.
  • Không có tính năng kiểm soát phiên bản: Tính năng kiểm soát phiên bản và khôi phục tác nhân chưa được cung cấp.
  • Không có tính năng lồng tác nhân phụ: Tính năng uỷ quyền cho tác nhân phụ chưa được hỗ trợ.
  • Bạn có thể có tối đa 1000 tác nhân được quản lý.

Bước tiếp theo