عاملهای مدیریتشده در Gemini API به شما امکان میدهند عامل Antigravity را با دستورالعملها، مهارتها، و دادههای خودتان گسترش دهید. میتوانید عامل را در زمان تعامل سفارشیسازی کنید، یا پیکربندی را بهعنوان عامل مدیریتشدهای ذخیره کنید که با شناسه فراخوانی میکنید.
سفارشیسازی کردن عامل Antigravity
سریعترین راه برای ساختن کارگزار سفارشی این است که پیکربندیتان را بهصورت درونخطی و بدون نیاز به مرحله ثبتنام، هنگام ایجاد تعامل جدید ارسال کنید. میتوانید کارگزار را به چند روش کلیدی گسترش دهید:
- انتخاب مدل: مدل Gemini زیرین را ازطریق
agent_configانتخاب کنید (بهطور پیشفرض روی Gemini 3.8 Flash تنظیم شده است). - دستورالعملهای سیستم: نوشتار درونخطی را ازطریق
system_instructionبه رفتار شکل ارسال کنید. - ابزارها: ابزارهای پیشفرض را ملغی کنید (اجرای کد، جستجو، بافتار نشانی وب)، سرورهای MCP ازراهدور را ثبت کنید، یا کارکردهای سفارشی را تعریف کنید (فراخوانی کارکرد).
- فایلها و مهارتها: فایلهایی مثل
AGENTS.mdوSKILL.mdرا در محیط نصب کنید.
در اینجا نمونهای از ارسال هر سه بهصورت درونخطی آورده شده است:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-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-09-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);
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Source;
import com.google.genai.gaos.models.interactions.SourceType;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
Client client = new Client();
Environment env = Environment.builder()
.sources(List.of(
Source.builder()
.type(SourceType.INLINE)
.target(".agents/AGENTS.md")
.content("Always use matplotlib for charts. Include a summary table in every report.")
.build(),
Source.builder()
.type(SourceType.INLINE)
.target(".agents/skills/slide-maker/SKILL.md")
.content("---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results.")
.build()
))
.build();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Analyze the Q1 revenue data and create a slide deck."))
.systemInstruction("You are a data analyst. Always include visualizations and export results as PDF.")
.environment(CreateAgentInteractionEnvironment.of(env))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
env := interactions.Environment{
Sources: []interactions.Source{
{
Type: interactions.SourceTypeInline.ToPointer(),
Target: genai.Ptr(".agents/AGENTS.md"),
Content: genai.Ptr("Always use matplotlib for charts. Include a summary table in every report."),
},
{
Type: interactions.SourceTypeInline.ToPointer(),
Target: genai.Ptr(".agents/skills/slide-maker/SKILL.md"),
Content: genai.Ptr("---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results."),
},
},
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateAgentInteraction{
Agent: interactions.AgentOption("antigravity-preview-09-2026"),
Input: interactions.NewInteractionsInput("Analyze the Q1 revenue data and create a slide deck."),
SystemInstruction: genai.Ptr("You are a data analyst. Always include visualizations and export results as PDF."),
Environment: genai.Ptr(interactions.NewCreateAgentInteractionEnvironment(env)),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
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-09-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."
}
]
}
}'
همه چیز در زمان تعامل تعریف میشود. نیازی به ثبت کردن چیزی ازقبل نیست. مهار عامل «ضدجاذبه» زمان اجرا (اجرای کد، مدیریت فایل، دسترسی به وب) و لایههای پیکربندی شما را در بالا فراهم میکند.
ابزارها و دستورالعملهای سیستم
بااستفاده از پارامترهای system_instruction و tools میتوانید رفتار و تواناییهای عامل را برای تعاملی خاص سفارشیسازی کنید.
- دستورالعملهای سیستم: از پارامتر
system_instructionبرای انتقال نوشتار درونخطی که رفتار کارگزار را شکل میدهد استفاده کنید. این ویژگی برای تغییرات سریع که میخواهید برای هر تماس تغییر دهید ایدهآل است. system_instructionوAGENTS.mdافزودنی هستند؛ هر دو درصورت وجود اعمال میشوند. - ابزارها: بهطور پیشفرض، عامل Antigravity به
code_execution،google_search، وurl_contextدسترسی دارد. با ارسال پارامترtoolsدر زمان تعامل میتوانید این فهرست را ملغی کنید. همچنین میتوانید سرورهای MCP از دور را ثبت کنید یا کارکردهای سفارشی (فراخوانی کارکرد) را تعریف کنید تا عامل را به پایههای API و پایگاههای داده خودتان متصل کنید. برای جزئیات کامل درباره ابزارهای دردسترس، عامل Antigravity: ابزارهای پشتیبانیشده را ببینید.
سفارشیسازی فایلمحور
ساختار فهرست راهنمای عامل
اگرچه میتوانید پیکربندی را بهصورت درونخطی انجام دهید، توصیه میکنیم فایلهای عاملتان را در یک دایرکتوری ساختاریافته سازماندهی کنید. این کار مدیریت، کنترل نسخه، و نصب در محیط عامل را آسانتر میکند.
دایرکتوری پروژه عامل معمولاً به این شکل است:
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
زمان اجرای Antigravity .agents/ (و ریشه محیط) را برای این فایلها اسکن میکند.
AGENTS.md
کارگزار بهطور خودکار .agents/AGENTS.md (یا /.agents/AGENTS.md) را از محیط بهعنوان دستورالعملهای سیستم در زمان راهاندازی بار میکند. از AGENTS.md برای تعریفهای شخصیت بلند، دستورالعملهای دقیق، و دستورالعملهایی که میخواهید در کنار کدتان کنترل نسخه داشته باشند استفاده کنید.
بااستفاده از منبع بهخط، AGENTS.md را نصب کنید:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-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-09-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);
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Source;
import com.google.genai.gaos.models.interactions.SourceType;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
Client client = new Client();
Environment env = Environment.builder()
.sources(List.of(
Source.builder()
.type(SourceType.INLINE)
.target(".agents/AGENTS.md")
.content("Always use matplotlib for charts. Include a summary table in every report.")
.build()
))
.build();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Analyze the Q1 revenue data and create a report."))
.systemInstruction("You are a data analyst. Always include visualizations and export results as PDF.")
.environment(CreateAgentInteractionEnvironment.of(env))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
env := interactions.Environment{
Sources: []interactions.Source{
{
Type: interactions.SourceTypeInline.ToPointer(),
Target: genai.Ptr(".agents/AGENTS.md"),
Content: genai.Ptr("Always use matplotlib for charts. Include a summary table in every report."),
},
},
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateAgentInteraction{
Agent: interactions.AgentOption("antigravity-preview-09-2026"),
Input: interactions.NewInteractionsInput("Analyze the Q1 revenue data and create a report."),
SystemInstruction: genai.Ptr("You are a data analyst. Always include visualizations and export results as PDF."),
Environment: genai.Ptr(interactions.NewCreateAgentInteractionEnvironment(env)),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
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-09-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."
}
]
}
}'
مهارتها: SKILL.md
مهارتها فایلهایی هستند که قابلیتهای عامل را گسترش میدهند. آنها را زیر .agents/skills/<skill-name>/SKILL.md قرار دهید و مهار آنها را بهطور خودکار شناسایی و ثبت میکند.
.agents/
├── AGENTS.md
└── skills/
└── slide-maker/
└── SKILL.md
نصب مهارت بااستفاده از منبع بهخط:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-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-09-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);
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Source;
import com.google.genai.gaos.models.interactions.SourceType;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
Client client = new Client();
Environment env = Environment.builder()
.sources(List.of(
Source.builder()
.type(SourceType.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")
.build()
))
.build();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Create a presentation about our Q1 results."))
.systemInstruction("You create presentations from data.")
.environment(CreateAgentInteractionEnvironment.of(env))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
env := interactions.Environment{
Sources: []interactions.Source{
{
Type: interactions.SourceTypeInline.ToPointer(),
Target: genai.Ptr(".agents/skills/slide-maker/SKILL.md"),
Content: genai.Ptr("---\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"),
},
},
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateAgentInteraction{
Agent: interactions.AgentOption("antigravity-preview-09-2026"),
Input: interactions.NewInteractionsInput("Create a presentation about our Q1 results."),
SystemInstruction: genai.Ptr("You create presentations from data."),
Environment: genai.Ptr(interactions.NewCreateAgentInteractionEnvironment(env)),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
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-09-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"
}
]
}
}'
مهارتهای بارگیریشده از .agents/skills/ و /.agents/skills/ هر دو بهطور خودکار شناسایی میشوند.
ایجاد عامل مدیریتشده
پساز اینکه پیکربندیتان را تکرار کردید، میتوانید آن را بهعنوان عامل مدیریتشده با agents.create ایجاد کنید. این کار به شما امکان میدهد عامل را با شناسه فراخوانی کنید و هر بار پیکربندی را تکرار نکنید.
id که هنگام ایجاد عامل مدیریتشده مشخص میکنید باید برای پروژه شما یکتا باشد و نباید با پیشوندهای رزروشده (مثلاً google-، gemini-) شروع شود. برای مشاهده فهرست کامل پیشوندهای محدودشده، به محدودیتهای شناسه عامل مراجعه کنید.
از منابع
base_agent، id، agent_config، system_instruction، و base_environment را با منابع مشخص کنید. پلاتفرم در هر فراخوانی یک محیط آزمایشی جدید با فایلهای شما آماده میکند. برای اطلاع از انواع منبع دردسترس (Git، GCS، درونخط)، به محیطها مراجعه کنید.
Python
from google import genai
client = genai.Client()
agent = client.agents.create(
id="data-analyst",
base_agent="antigravity-preview-09-2026",
agent_config={
"type": "antigravity",
"model": "gemini-3.8-flash",
},
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-09-2026",
agent_config: {
type: "antigravity",
model: "gemini-3.8-flash",
},
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}`);
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.agents.Agent;
import com.google.genai.gaos.models.agents.AgentConfig;
import com.google.genai.gaos.models.agents.BaseEnvironment;
import com.google.genai.gaos.models.interactions.AntigravityAgentConfig;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.Source;
import com.google.genai.gaos.models.interactions.SourceType;
import java.util.List;
Client client = new Client();
Environment env = Environment.builder()
.sources(List.of(
Source.builder()
.type(SourceType.INLINE)
.target(".agents/AGENTS.md")
.content("Always use matplotlib for charts. Include a summary table in every report.")
.build(),
Source.builder()
.type(SourceType.INLINE)
.target(".agents/skills/slide-maker/SKILL.md")
.content("---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results.")
.build(),
Source.builder()
.type(SourceType.REPOSITORY)
.source("https://github.com/my-org/analysis-templates")
.target("/workspace/templates")
.build()
))
.build();
Agent agentParams = Agent.builder()
.id("data-analyst")
.baseAgent("antigravity-preview-09-2026")
.agentConfig(AgentConfig.of(
AntigravityAgentConfig.builder()
.model("gemini-3.8-flash")
.build()
))
.systemInstruction("You are a data analyst. Always include visualizations and export results as PDF.")
.baseEnvironment(BaseEnvironment.of(env))
.build();
Agent agent = client.agents.create(agentParams).agent().get();
System.out.println("Created agent: " + agent.id().orElse(""));
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/agents"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
env := interactions.Environment{
Sources: []interactions.Source{
{
Type: interactions.SourceTypeInline.ToPointer(),
Target: genai.Ptr(".agents/AGENTS.md"),
Content: genai.Ptr("Always use matplotlib for charts. Include a summary table in every report."),
},
{
Type: interactions.SourceTypeInline.ToPointer(),
Target: genai.Ptr(".agents/skills/slide-maker/SKILL.md"),
Content: genai.Ptr("---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results."),
},
{
Type: interactions.SourceTypeRepository.ToPointer(),
Source: genai.Ptr("https://github.com/my-org/analysis-templates"),
Target: genai.Ptr("/workspace/templates"),
},
},
}
res, err := client.Agents.Create(ctx, operations.CreateAgentRequest{
Body: agents.Agent{
ID: genai.Ptr("data-analyst"),
BaseAgent: genai.Ptr("antigravity-preview-09-2026"),
AgentConfig: genai.Ptr(agents.NewAgentConfig(interactions.AntigravityAgentConfig{
Model: genai.Ptr("gemini-3.8-flash"),
})),
SystemInstruction: genai.Ptr("You are a data analyst. Always include visualizations and export results as PDF."),
BaseEnvironment: genai.Ptr(agents.NewBaseEnvironment(env)),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created agent: %s\n", *res.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-09-2026",
"agent_config": {
"type": "antigravity",
"model": "gemini-3.8-flash"
},
"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"
}
]
}
}'
از محیط موجود (انشعاب)
با عامل پایه «ضدجاذبه» تکرار کنید تا محیط مناسب شود (بستهها نصب شوند، فایلها در جای خود قرار بگیرند)، سپس آن را به عامل مدیریتشدهای انشعاب دهید.
Python
from google import genai
client = genai.Client()
# Step 1: set up the environment interactively
interaction = client.interactions.create(
agent="antigravity-preview-09-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-09-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-09-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-09-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}`);
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.agents.Agent;
import com.google.genai.gaos.models.agents.BaseEnvironment;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
// Step 1: set up the environment interactively
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Install pandas, matplotlib, and seaborn. Create an analysis template at /workspace/template.py."))
.environment(CreateAgentInteractionEnvironment.of("remote"))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
// Step 2: fork that environment into a managed agent
Agent agentParams = Agent.builder()
.id("my-data-analyst")
.baseAgent("antigravity-preview-09-2026")
.systemInstruction("You are a data analyst. Use the template at /workspace/template.py for all reports.")
.baseEnvironment(BaseEnvironment.of(interaction.environmentId().orElse("")))
.build();
Agent agent = client.agents.create(agentParams).agent().get();
System.out.println("Forked agent successfully: " + agent.id().orElse(""));
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/agents"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
// Step 1: set up the environment interactively
intRes, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateAgentInteraction{
Agent: interactions.AgentOption("antigravity-preview-09-2026"),
Input: interactions.NewInteractionsInput("Install pandas, matplotlib, and seaborn. Create an analysis template at /workspace/template.py."),
Environment: genai.Ptr(interactions.NewCreateAgentInteractionEnvironment("remote")),
}),
})
if err != nil {
log.Fatal(err)
}
interaction := intRes.Interaction
// Step 2: fork that environment into a managed agent
agentRes, err := client.Agents.Create(ctx, operations.CreateAgentRequest{
Body: agents.Agent{
ID: genai.Ptr("my-data-analyst"),
BaseAgent: genai.Ptr("antigravity-preview-09-2026"),
SystemInstruction: genai.Ptr("You are a data analyst. Use the template at /workspace/template.py for all reports."),
BaseEnvironment: genai.Ptr(agents.NewBaseEnvironment(*interaction.EnvironmentID)),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Forked agent successfully: %s\n", *agentRes.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-09-2026",
"input": "Install pandas, matplotlib, and seaborn. Create an analysis template at /workspace/template.py.",
"environment": "remote"
}'
با قوانین شبکه
هنگام ذخیره کردن عامل مدیریتشده، میتوانید دسترسی خروجی را محدود کنید یا اطلاعات اعتباری را تزریق کنید. برای طرحواره فهرست مجاز کامل، الگوهای اطلاعات اعتباری، و نویسههای عام، محیطها: پیکربندی شبکه را ببینید.
بااستفاده از شناسه در قانون فهرست مجاز ("credential": "github-production")، به اطلاعات اعتباری ذخیرهشده ارجاع دهید و کارگزار خروجی رمز را در زمان درخواست تزریق میکند، بنابراین رمز هرگز در تعریف عامل شما قرار نمیگیرد. این مثال بهجای آن، سرصفحه را با transform درخط تنظیم میکند. کارگزار هر دو شکل را به یک روش اعمال میکند، اطلاعات اعتباری علاوهبراین به شما امکان میدهد رمز را در بین عاملها دوباره استفاده کنید و آن را در یک مکان بچرخانید.
مثال زیر issue-resolver عاملی ایجاد میکند که فقط میتواند به GitHub و PyPI دسترسی داشته باشد و اطلاعات اعتباری برای GitHub تزریق میشود:
Python
from google import genai
client = genai.Client()
agent = client.agents.create(
id="issue-resolver",
base_agent="antigravity-preview-09-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-09-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}`);
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.agents.Agent;
import com.google.genai.gaos.models.agents.BaseEnvironment;
import com.google.genai.gaos.models.interactions.Allowlist;
import com.google.genai.gaos.models.interactions.AllowlistEntry;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.EnvironmentNetworkEgressAllowlist;
import com.google.genai.gaos.models.interactions.Network;
import com.google.genai.gaos.models.interactions.Source;
import com.google.genai.gaos.models.interactions.SourceType;
import com.google.genai.gaos.models.interactions.Transform;
import java.util.List;
import java.util.Map;
Client client = new Client();
Environment env = Environment.builder()
.sources(List.of(
Source.builder()
.type(SourceType.REPOSITORY)
.source("https://github.com/my-org/backend")
.target("/workspace/repo")
.build()
))
.network(Network.of(
EnvironmentNetworkEgressAllowlist.builder()
.allowlist(Allowlist.of(List.of(
AllowlistEntry.builder()
.domain("api.github.com")
.transform(Transform.of(Map.of(
"Authorization", "Basic YOUR_BASE64_TOKEN"
)))
.build(),
AllowlistEntry.builder().domain("pypi.org").build()
)))
.build()
))
.build();
Agent agentParams = Agent.builder()
.id("issue-resolver")
.baseAgent("antigravity-preview-09-2026")
.systemInstruction("You resolve GitHub issues. Clone the repo, find the bug, write the fix, run the tests, and open a PR.")
.baseEnvironment(BaseEnvironment.of(env))
.build();
Agent agent = client.agents.create(agentParams).agent().get();
System.out.println("Created issue-resolver agent successfully: " + agent.id().orElse(""));
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/agents"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
env := interactions.Environment{
Sources: []interactions.Source{
{
Type: interactions.SourceTypeRepository.ToPointer(),
Source: genai.Ptr("https://github.com/my-org/backend"),
Target: genai.Ptr("/workspace/repo"),
},
},
Network: genai.Ptr(interactions.NewNetwork(interactions.EnvironmentNetworkEgressAllowlist{
Allowlist: genai.Ptr(interactions.NewAllowlist([]interactions.AllowlistEntry{
{
Domain: "api.github.com",
Transform: genai.Ptr(interactions.NewTransform(map[string]string{
"Authorization": "Basic YOUR_BASE64_TOKEN",
})),
},
{
Domain: "pypi.org",
},
})),
})),
}
res, err := client.Agents.Create(ctx, operations.CreateAgentRequest{
Body: agents.Agent{
ID: genai.Ptr("issue-resolver"),
BaseAgent: genai.Ptr("antigravity-preview-09-2026"),
SystemInstruction: genai.Ptr("You resolve GitHub issues. Clone the repo, find the bug, write the fix, run the tests, and open a PR."),
BaseEnvironment: genai.Ptr(agents.NewBaseEnvironment(env)),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created issue-resolver agent successfully: %s\n", *res.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-09-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"}
]
}
}
}'
فراخواندن عامل
با ایجاد تعامل جدید، با عامل مدیریتشدهتان با شناسه عامل تماس بگیرید. هر فراخوانی محیط پایه را انشعاب میکند، بنابراین هر اجرا از ابتدا شروع میشود.
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);
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("data-analyst"))
.input(InteractionsInput.of("Analyze Q1 revenue data from /workspace/templates/sample.csv and create a slide deck."))
.environment(CreateAgentInteractionEnvironment.of("remote"))
.build();
Interaction result = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(result.outputText().orElse(""));
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateAgentInteraction{
Agent: interactions.AgentOption("data-analyst"),
Input: interactions.NewInteractionsInput("Analyze Q1 revenue data from /workspace/templates/sample.csv and create a slide deck."),
Environment: genai.Ptr(interactions.NewCreateAgentInteractionEnvironment("remote")),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
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"
}'
برای مکالمههای چند نوبتی و جاریسازی، شروع سریع را ببینید. الگوهای previous_interaction_id و environment یکسان برای نمایندگان مدیریتشده اعمال میشود.
عاملهای مدیریتشده از اجرای پسزمینهای و لغو نیز پشتیبانی میکنند. برای جزئیات و نمونههای کد، عامل ضدجاذبه: اجرای پسزمینه را ببینید.
لغو کردن پیکربندی در فراخوانی
هنگام ایجاد تعامل میتوانید پیکربندی شبکه پیشفرض system_instruction، tools، و environment نماینده را ملغی کنید. این کار به شما امکان میدهد رفتار، قابلیتها، یا اطلاعات اعتباری نماینده را برای اجرای خاصی بدون تغییر تعریف ذخیرهشده نماینده اصلاح کنید.
ملغی کردن دستورالعمل و ابزارهای سیستم
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);
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CodeExecution;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
Client client = new Client();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("data-analyst"))
.input(InteractionsInput.of("Analyze Q1 revenue data, but do not create a slide deck. Just output a summary table."))
.systemInstruction("You are a data analyst. Focus ONLY on summary tables. Ignore default instructions about slides.")
.tools(List.of(CodeExecution.builder().build())) // Override to only use code execution
.environment(CreateAgentInteractionEnvironment.of("remote"))
.build();
Interaction result = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(result.outputText().orElse(""));
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateAgentInteraction{
Agent: interactions.AgentOption("data-analyst"),
Input: interactions.NewInteractionsInput("Analyze Q1 revenue data, but do not create a slide deck. Just output a summary table."),
SystemInstruction: genai.Ptr("You are a data analyst. Focus ONLY on summary tables. Ignore default instructions about slides."),
Tools: []interactions.Tool{interactions.NewTool(interactions.CodeExecution{})}, // Override to only use code execution
Environment: genai.Ptr(interactions.NewCreateAgentInteractionEnvironment("remote")),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
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"
}'
ملغی کردن پیکربندی شبکه (بازآوری اطلاعات اعتباری)
اگر عامل مدیریتشده شما اطلاعات اعتباری شبکه را در base_environment خود دارد،
میتوانید آنها را در زمان فراخوانی لغو کنید تا نشانههای منقضیشده را بازآوری کنید یا کلیدهای API را
چرخش دهید. شیء environment را با پیکربندی جدید network ارسال کنید. قوانین شبکه جدید بهطور کامل جایگزین قوانین قبلی برای آن تعامل میشود. منابع (فایلها، مخزنها) محیط پایه حفظ میشود.
اگر base_environment بهجای رمز درونخطی به
اطلاعات اعتباری ذخیرهشده ارجاع میدهد،
نیازی نیست چیزی را ملغی کنید. اطلاعات اعتباری را با PATCH بچرخانید و هر
عامل ارجاعدهنده آن، رمز جدید را در اجرای بعدی برمیدارد.
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);
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.Allowlist;
import com.google.genai.gaos.models.interactions.AllowlistEntry;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.EnvironmentNetworkEgressAllowlist;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Network;
import com.google.genai.gaos.models.interactions.Transform;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
import java.util.Map;
Client client = new Client();
// Invoke the agent with a fresh token, overriding the base_environment credentials
Environment env = Environment.builder()
.network(Network.of(
EnvironmentNetworkEgressAllowlist.builder()
.allowlist(Allowlist.of(List.of(
AllowlistEntry.builder()
.domain("api.github.com")
.transform(Transform.of(Map.of(
"Authorization", "Bearer ghp_REFRESHED_TOKEN"
)))
.build(),
AllowlistEntry.builder().domain("pypi.org").build()
)))
.build()
))
.build();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("issue-resolver"))
.input(InteractionsInput.of("Fix issue #42 and open a PR."))
.environment(CreateAgentInteractionEnvironment.of(env))
.build();
Interaction result = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(result.outputText().orElse(""));
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
// Invoke the agent with a fresh token, overriding the base_environment credentials
env := interactions.Environment{
Network: genai.Ptr(interactions.NewNetwork(interactions.EnvironmentNetworkEgressAllowlist{
Allowlist: genai.Ptr(interactions.NewAllowlist([]interactions.AllowlistEntry{
{
Domain: "api.github.com",
Transform: genai.Ptr(interactions.NewTransform(map[string]string{
"Authorization": "Bearer ghp_REFRESHED_TOKEN",
})),
},
{
Domain: "pypi.org",
},
})),
})),
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateAgentInteraction{
Agent: interactions.AgentOption("issue-resolver"),
Input: interactions.NewInteractionsInput("Fix issue #42 and open a PR."),
Environment: genai.Ptr(interactions.NewCreateAgentInteractionEnvironment(env)),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
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"}
]
}
}
}'
مدیریت عاملها
میتوانید کارگزاران را فهرست کنید، دریافت کنید، و حذف کنید.
فهرست کردن عاملها
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}`);
}
}
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.agents.Agent;
import java.util.List;
Client client = new Client();
List<Agent> agents = client.agents.listDirect().agentListResponse().get().agents().orElse(List.of());
for (Agent a : agents) {
System.out.println(a.id().orElse("") + ": " + a.description().orElse(""));
}
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Agents.List(ctx, operations.ListAgentsRequest{})
if err != nil {
log.Fatal(err)
}
if res.AgentListResponse != nil {
for _, a := range res.AgentListResponse.Agents {
fmt.Printf("%s: %v\n", *a.ID, a.Description)
}
}
}
REST
curl -X GET "https://generativelanguage.googleapis.com/v1beta/agents" \
-H "x-goog-api-key: $GEMINI_API_KEY"
دریافت عامل
Python
agent = client.agents.get(id="data-analyst")
print(agent)
JavaScript
const agent = await client.agents.get("data-analyst");
console.log(agent);
جاوا
import com.google.genai.Client;
import com.google.genai.gaos.models.agents.Agent;
Client client = new Client();
Agent agent = client.agents.get("data-analyst").agent().get();
System.out.println(agent);
رفتن
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Agents.Get(ctx, operations.GetAgentRequest{
ID: "data-analyst",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", res.Agent)
}
REST
curl -X GET "https://generativelanguage.googleapis.com/v1beta/agents/data-analyst" \
-H "x-goog-api-key: $GEMINI_API_KEY"
حذف کردن عامل
حذف کردن پیکربندی را برمیدارد. محیطهای موجود و تعاملهای ایجادشده توسط عامل تحت تأثیر قرار نمیگیرند.
Python
client.agents.delete(id="data-analyst")
JavaScript
await client.agents.delete("data-analyst");
جاوا
import com.google.genai.Client;
Client client = new Client();
client.agents.delete("data-analyst");
رفتن
package main
import (
"context"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
_, err = client.Agents.Delete(ctx, operations.DeleteAgentRequest{
ID: "data-analyst",
})
if err != nil {
log.Fatal(err)
}
}
REST
curl -X DELETE "https://generativelanguage.googleapis.com/v1beta/agents/data-analyst" \
-H "x-goog-api-key: $GEMINI_API_KEY"
مرجع تعریف عامل
| فیلد | نوع | الزامی | شرح |
|---|---|---|---|
id |
رشته | بله | شناسه یکتای کارگزار در پروژه Google Cloud. برای فراخواندن عامل استفاده میشود. نباید از پیشوندهای رزروشده استفاده کند. محدودیتهای شناسه نماینده را ببینید. |
description |
رشته | نه | شرح قابلخواندن برای انسان از نماینده. |
base_agent |
رشته | بله | شناسه عامل پایه (برای نمونه، antigravity-preview-09-2026). |
agent_config |
شیء | نه | پیکربندی برای عامل پایه، ازجمله انتخاب مدل ({"type": "antigravity", "model": "gemini-3.8-flash"}). درصورت حذف شدن، بهطور پیشفرض روی gemini-3.8-flash تنظیم میشود. برای نمایندگان نامدار، در زمان تعامل نمیتواند ملغی شود. |
system_instruction |
رشته | نه | پیامواره سیستم که رفتار و شخصیت را تعریف میکند. |
tools |
آرایه | نه | ابزارهایی که نماینده میتواند استفاده کند. اگر حذف شود، بهطور پیشفرض روی code_execution، google_search، و url_context تنظیم میشود. ابزارهای پشتیبانیشده شامل code_execution، google_search، url_context، mcp_server، و تعاریف سفارشی function میشود. |
base_environment |
رشته یا شیء | نه | "remote"، یک environment_id، یا یک شیء پیکربندی با sources و network. «محیطها» را ببینید. |
محدودیتهای شناسه عامل
هنگام ایجاد نماینده مدیریتشده، id که مشخص میکنید باید از این قوانین پیروی کند:
- باید برای پروژه Google Cloud شما منحصربهفرد باشد.
- نباید با هیچیک از پیشوندهای رزروشده زیر (حروفغیرحساس) شروع شود، درغیراینصورت ایجاد ناموفق خواهد بود:
antigravity-veo-omni-lyria-imagen-gemma-gemini-google-youtube-android-chrome-pixel-waze-fitbit-nest-kaggle-
گردش کار تکرار و بهبود
- با عامل پایه Antigravity نمونه اولیه بسازید. دستور سیستم و منابع محیط را بهصورت بهخط ارسال کنید. دستورالعملهای آزمایش، مهارتها، و تنظیمات محیط را بهصورت تعاملی آزمایش کنید.
- محیط را ثابت کنید. بستهها را نصب کنید، منابع را سوار کنید، و مطمئن شوید همه چیز کار میکند.
- با ایجاد یک عامل جدید، چه از منابع یا با انشعاب محیط، بهعنوان یک عامل مدیریتشده پایدار بمانید.
- تعریف کارگزار را بهروزرسانی کنید. دستورالعمل سیستم را تغییر دهید، مهارتها را عوض کنید، یا منابع را اضافه کنید. فراخوانی بعدی پیکربندی جدید را برمیدارد.
محدودیتها
- وضعیت پیشنمایش: عاملهای مدیریتشده در پیشنمایش هستند. ویژگیها و طرحوارهها ممکن است تغییر کنند.
- عامل پایه و مدلها: فقط
antigravity-preview-09-2026بهعنوانbase_agentپشتیبانی میشود. گزینههای مدل پشتیبانیشده درagent_configعبارتاند ازgemini-3.8-flash(پیشفرض)،gemini-3.7-flash،gemini-3.6-flash،gemini-3.5-flash، وgemini-3.5-flash-lite. برای کارگزاران نامدار، مدل در زمان تعامل نمیتواند ملغی شود. - بدون نسخهبندی: نسخهبندی عامل و بازگرداندن هنوز دردسترس نیست.
- بدون تو در تو بودن کارگزار فرعی: واگذاری کارگزار فرعی هنوز پشتیبانی نمیشود.
- میتوانید حداکثر ۱۰۰۰ عامل مدیریتشده داشته باشید.
قدم بعدی چیست
- نمای کلی عاملها: با مفاهیم اصلی عاملهای مدیریتشده آشنا شوید.
- شروع سریع: با مکالمههای چند نوبتی و جاریسازی شروع به ساختن کنید.
- عامل Antigravity: قابلیتها، ابزارها، و قیمتگذاری عامل پیشفرض را کاوش کنید.
- محیطهای عامل: جعبههای ایمنی، منابع، و شبکهسازی را پیکربندی کنید.
- میانای برنامهسازی کاربردی «عاملهای مدیریتشده» در «پلاتفرم عامل»: برای ایجاد عاملهایی با حاکمیت سازمانی داخلی.