ساخت نمایندگان مدیریت‌شده

عامل‌های مدیریت‌شده در رابط برنامه‌نویسی کاربردی Gemini به شما امکان می‌دهند دستورالعمل‌ها، مهارت‌ها و یک محیط را در یک عامل قابل استفاده مجدد دسته‌بندی کنید که می‌توانید آن را با شناسه فراخوانی کنید. یک بررسی‌کننده کد، یک تحلیلگر داده یا یک ربات استقرار را یک بار تعریف کنید و بدون نیاز به پیکربندی مجدد، آن را از هر کلاینتی فراخوانی کنید.

پایتون


from google import genai

client = genai.Client()

agent = client.agents.create(
    id="code-reviewer",
    base_agent="antigravity-preview-05-2026",
    system_instruction="You are a senior code reviewer. Check every file for bugs, style issues, and security vulnerabilities.",
    base_environment={
        "type": "remote",
        "sources": [
            {
                "type": "repository",
                "source": "https://github.com/my-org/backend",
                "target": "/workspace/repo",
            }
        ],
    },
)

result = client.interactions.create(
    agent="code-reviewer",
    input="Review the latest changes in /workspace/repo/src and file a summary.",
    environment="remote",
)
print(result.output_text)

جاوا اسکریپت

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

const client = new GoogleGenAI({});

const agent = await client.agents.create({
    id: "code-reviewer",
    base_agent: "antigravity-preview-05-2026",
    system_instruction: "You are a senior code reviewer. Check every file for bugs, style issues, and security vulnerabilities.",
    base_environment: {
        type: "remote",
        sources: [
            {
                type: "repository",
                source: "https://github.com/my-org/backend",
                target: "/workspace/repo",
            }
        ],
    },
});

const result = await client.interactions.create({
    agent: "code-reviewer",
    input: "Review the latest changes in /workspace/repo/src and file a summary.",
    environment: "remote",
}, { timeout: 300000 });

console.log(result.output_text);

استراحت

curl -X POST "https://generativelanguage.googleapis.com/v1beta/agents" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-d '{
    "id": "code-reviewer",
    "base_agent": "antigravity-preview-05-2026",
    "system_instruction": "You are a senior code reviewer. Check every file for bugs, style issues, and security vulnerabilities.",
    "base_environment": {
        "type": "remote",
        "sources": [
            {
                "type": "repository",
                "source": "https://github.com/my-org/backend",
                "target": "/workspace/repo"
            }
        ]
    }
}'

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-d '{
    "agent": "code-reviewer",
    "input": "Review the latest changes in /workspace/repo/src and file a summary.",
    "environment": "remote"
}'

ایجاد یک عامل مدیریت‌شده

یک عامل مدیریت‌شده، یک base_agent ، یک system_instruction ، یک base_environment و tools در یک پیکربندی واحد که شما با شناسه فراخوانی می‌کنید، ترکیب می‌کند. مهار عامل Antigravity زمان اجرا را فراهم می‌کند. در هر فراخوانی، پلتفرم base_environment را به یک sandbox جدید با تمام قابلیت‌های base_agent (اجرای کد، مدیریت فایل، دسترسی به وب) منشعب می‌کند.

شما می‌توانید یک عامل را از منابعی مانند Git، Cloud Storage یا inline ایجاد کنید ، یا از محیطی که قبلاً پیکربندی کرده‌اید، fork کنید . از منابع، system_instruction و base_environment با منابع مشخص کنید. پلتفرم در هر فراخوانی، یک sandbox جدید با فایل‌های شما فراهم می‌کند. برای انواع منبع موجود (Git، Cloud Storage، inline) به Environments مراجعه کنید.

پایتون

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", # This is appended to the system instruction
                "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}")

جاوا اسکریپت

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}`);

استراحت

curl -X POST "https://generativelanguage.googleapis.com/v1beta/agents" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-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"
            }
        ]
    }
}'

از یک محیط موجود (fork)

با عامل پایه Antigravity این کار را تکرار کنید تا محیط مناسب شود (بسته‌ها نصب شوند، فایل‌ها در جای خود قرار گیرند)، سپس آن را به یک عامل مدیریت‌شده فورک کنید.

پایتون

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 named 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}")

جاوا اسکریپت

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}`);

استراحت

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Api-Revision: 2026-05-20" \
  -d '{
      "agent": "antigravity-preview-05-2026",
      "input": "Install pandas, matplotlib, and seaborn. Create an analysis template at /workspace/template.py.",
      "environment": "remote"
  }'

پیکربندی قوانین شبکه

شما می‌توانید از فیلد network برای محدود کردن ترافیک خروجی به دامنه‌های خاص استفاده کنید. اعتبارنامه‌ها از طریق پروکسی خروجی عبور می‌کنند و هرگز در داخل جعبه شنی (sandbox) در معرض دید قرار نمی‌گیرند. برای اطلاعات بیشتر در مورد پیکربندی دسترسی به شبکه، به پیکربندی شبکه در سند محیط‌ها مراجعه کنید:

پایتون

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}")

جاوا اسکریپت

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}`);

استراحت

curl -X POST "https://generativelanguage.googleapis.com/v1beta/agents" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Api-Revision: 2026-05-20" \
  -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"}
              ]
          }
      }
  }'

وقتی یک لیست مجاز تنظیم می‌شود، فقط درخواست‌های مربوط به دامنه‌های فهرست‌شده مجاز هستند. برای مشاهده‌ی طرح کامل لیست مجاز و الگوهای اعتبارنامه، به بخش محیط‌ها: پیکربندی شبکه مراجعه کنید. می‌توانید از کاراکترهای جایگزین برای تطبیق زیردامنه‌ها استفاده کنید (مثلاً {"domain": "*.example.com"} )، اما توجه داشته باشید که این با دامنه‌ی ریشه example.com که باید جداگانه اضافه شود، مطابقت ندارد. برای مجاز کردن سایر ترافیک‌ها، مانند مسیریابی دامنه‌های فهرست‌نشده بدون هدرهای تزریق‌شده، {"domain": "*"} را به عنوان یک ورودی catch-all اضافه کنید.

مرجع تعریف عامل

جدول زیر تمام پارامترهای قابل تنظیم روی یک عامل را شرح می‌دهد:

میدان نوع مورد نیاز توضیحات
id رشته بله شناسه منحصر به فرد عامل. برای فراخوانی عامل استفاده می‌شود.
description رشته خیر توصیف عامل که برای انسان قابل خواندن باشد.
base_agent رشته بله شناسه عامل پایه (مثلاً antigravity-preview-05-2026 ).
system_instruction رشته خیر اعلان سیستم، رفتار و شخصیت را تعریف می‌کند.
tools رشته یا شیء خیر ابزارهایی که عامل می‌تواند از آنها استفاده کند، (البته موارد ذکر شده) به code_execution ، google_search و url_context دسترسی خواهند داشت.
base_environment رشته یا شیء خیر "remote" ، یک environment_id یا یک شیء پیکربندی با sources و network . به Environments مراجعه کنید.

دستورالعمل‌های سیستم: AGENTS.md

این مهار در هنگام راه‌اندازی، دو مسیر را برای AGENTS.md جستجو می‌کند:

مسیر دامنه
.agents/AGENTS.md ریشه فضای کاری فعلی.
/.agents/AGENTS.md ریشه سیستم فایل.

اگر هر دو وجود داشته باشند، هر دو به عنوان دستورالعمل‌های سیستمی بارگذاری می‌شوند.

برای mount کردن فایل AGENTS.md با استفاده از یک منبع درون خطی:

پایتون

from google import genai

client = genai.Client()

agent = client.agents.create(
    id="styled-writer",
    base_agent="antigravity-preview-05-2026",
    base_environment={
        "type": "remote",
        "sources": [
            {
                "type": "inline",
                "target": ".agents/AGENTS.md",
                "content": "# Writing Style\n\n- Use active voice\n- Keep paragraphs under 3 sentences\n- Include code examples for every concept",
            },
        ],
    },
)

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

جاوا اسکریپت

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

const client = new GoogleGenAI({});

const agent = await client.agents.create({
    id: "styled-writer",
    base_agent: "antigravity-preview-05-2026",
    base_environment: {
        type: "remote",
        sources: [
            {
                type: "inline",
                target: ".agents/AGENTS.md",
                content: "# Writing Style\n\n- Use active voice\n- Keep paragraphs under 3 sentences\n- Include code examples for every concept",
            },
        ],
    },
});

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

استراحت

curl -X POST "https://generativelanguage.googleapis.com/v1beta/agents" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Api-Revision: 2026-05-20" \
  -d '{
      "id": "styled-writer",
      "base_agent": "antigravity-preview-05-2026",
      "base_environment": {
          "type": "remote",
          "sources": [
              {
                  "type": "inline",
                  "target": ".agents/AGENTS.md",
                  "content": "# Writing Style\n\n- Use active voice\n- Keep paragraphs under 3 sentences\n- Include code examples for every concept"
              }
          ]
      }
  }'

مهارت‌ها: SKILL.md

مهارت‌ها فایل‌هایی هستند که قابلیت‌های عامل را گسترش می‌دهند. آن‌ها را در مسیر .agents/skills/<skill-name>/SKILL.md قرار دهید تا مهار (harness) آن‌ها را به‌طور خودکار کشف و ثبت کند.

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

برای نصب یک مهارت با استفاده از منبع درون خطی:

پایتون

from google import genai

client = genai.Client()

agent = client.agents.create(
    id="presenter",
    base_agent="antigravity-preview-05-2026",
    system_instruction="You create presentations from data.",
    base_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(f"Created presenter: {agent.id}")

جاوا اسکریپت

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

const client = new GoogleGenAI({});

const agent = await client.agents.create({
    id: "presenter",
    base_agent: "antigravity-preview-05-2026",
    system_instruction: "You create presentations from data.",
    base_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",
            },
        ],
    },
});

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

استراحت

# Create agent with skill
curl -X POST "https://generativelanguage.googleapis.com/v1beta/agents" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Api-Revision: 2026-05-20" \
  -d '{
      "id": "presenter",
      "base_agent": "antigravity-preview-05-2026",
      "system_instruction": "You create presentations from data.",
      "base_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"
              }
          ]
      }
  }'

عامل را احضار کنید

برای فراخوانی عامل مدیریت‌شده‌ی سفارشی خود، client.interactions.create را با شناسه‌ی عامل خود فراخوانی کنید. هر فراخوانی، محیط پایه را منشعب می‌کند، بنابراین هر اجرا به صورت تمیز شروع می‌شود.

پایتون

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)

جاوا اسکریپت

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);

استراحت

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Api-Revision: 2026-05-20" \
  -d '{
      "agent": "data-analyst",
      "input": "Analyze Q1 revenue data from /workspace/templates/sample.csv and create a slide deck.",
      "environment": "remote"
  }'

برای مکالمات و پخش جریانی چند نوبتی، به شروع سریع مراجعه کنید. همان الگوهای previous_interaction_id و environment برای عوامل مدیریت‌شده اعمال می‌شود.

نادیده گرفتن پیکربندی در هنگام فراخوانی

شما می‌توانید هنگام ایجاد یک تعامل system_instruction و tools پیش‌فرض عامل را لغو کنید. این به شما امکان می‌دهد رفتار یا قابلیت‌های عامل را برای یک اجرای خاص بدون تغییر تعریف عامل ذخیره شده تغییر دهید.

پایتون

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)

جاوا اسکریپت

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);

استراحت

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Api-Revision: 2026-05-20" \
  -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"
  }'

مدیریت عوامل

شما می‌توانید عامل‌ها را فهرست، دریافت و حذف کنید.

لیست عوامل

پایتون

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

جاوا اسکریپت

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

استراحت

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

یک نماینده بگیرید

پایتون

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

جاوا اسکریپت

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

استراحت

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

حذف یک عامل

حذف، پیکربندی را حذف می‌کند. محیط‌های موجود و تعاملات ایجاد شده توسط عامل تحت تأثیر قرار نمی‌گیرند.

پایتون

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

جاوا اسکریپت

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

استراحت

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

گردش کار تکرار

  1. نمونه اولیه با عامل ضد جاذبه پایه. دستورالعمل‌ها، مهارت‌ها و تنظیمات محیط را به صورت تعاملی آزمایش کنید.
  2. محیط را پایدار کنید . بسته‌ها را نصب کنید، منابع را مانت کنید، تأیید کنید که همه چیز کار می‌کند.
  3. به عنوان یک عامل مدیریت‌شده با client.agents.create ، چه از منابع و چه با ایجاد انشعاب در محیط، به کار خود ادامه دهید .
  4. تعریف عامل را به‌روزرسانی کنید . system_instruction را تغییر دهید، مهارت‌های خود را تغییر دهید یا منابع را اضافه کنید. فراخوانی بعدی پیکربندی جدید را دریافت می‌کند.

محدودیت‌ها

  • وضعیت پیش‌نمایش : نمایندگان مدیریت‌شده در حالت پیش‌نمایش هستند. ویژگی‌ها و طرحواره‌ها ممکن است تغییر کنند.
  • عامل پایه : فقط antigravity-preview-05-2026 به عنوان base_agent پشتیبانی می‌شود.
  • بدون نسخه‌بندی : نسخه‌بندی عامل و بازگرداندن به نسخه قبل هنوز در دسترس نیست.
  • عدم تودرتوسازی زیرعامل : واگذاری زیرعامل هنوز پشتیبانی نمی‌شود.
  • شما می‌توانید در هر پروژه تا ۱۰۰۰ عامل مدیریت‌شده در هر زمان داشته باشید.

قدم بعدی چیست؟