يرشدك هذا الدليل إلى كيفية إنشاء واستخدام "الوكلاء المُدارون" على Gemini API باستخدام وكيل Antigravity. ستجري مكالمتك الأولى مع الوكيل، وتواصل محادثة مترابطة، وتبث الرد، وتنزّل الملفات من وضع الحماية، وتعمل مع وكيل Antigravity المُدار.
إجراء تفاعلك الأول مع الوكيل
يؤدي طلب واحد إلى واجهة برمجة التطبيقات Interactions API إلى توفير بيئة اختبارية لنظام التشغيل Linux، وتشغيل حلقة الوكيل، وعرض النتيجة. عليك تحديد ثلاث مَعلمات:
- مرِّر
agentكـ"antigravity-preview-05-2026",، وهو الإصدار الحالي من الوكيل المُدار المحدّد مسبقًا والعام. - حدِّد
environment="remote"لتوفير بيئة وضع الحماية جديدة. أنشئ إدخالاً يحدّد ما تريد أن يفعله الوكيل.
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="Write a Python script that generates the first 20 Fibonacci numbers and saves them to fibonacci.txt. Then read the file and print its contents.",
environment="remote",
)
# Print the agent's final output
print(f"Interaction ID: {interaction.id}")
print(f"Environment ID: {interaction.environment_id}")
print(f"Output: {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: "Write a Python script that generates the first 20 Fibonacci numbers and saves them to fibonacci.txt. Then read the file and print its contents.",
environment: "remote",
});
console.log(`Interaction ID: ${interaction.id}`);
console.log(`Environment ID: ${interaction.environment_id}`);
console.log(`Output: ${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": [{"type": "text", "text": "Write a Python script that generates the first 20 Fibonacci numbers and saves them to fibonacci.txt. Then read the file and print its contents."}],
"environment": {"type": "remote"}
}'
تعرض الاستجابة عنصر Interaction. يمكنك تخزين interaction.id وinteraction.environment_id لمواصلة المحادثة في بيئة الاختبار المعزولة نفسها. استخدِم interaction.output_text للوصول إلى الردّ النهائي من الموظف. تعرض interaction.steps كل خطوة اتّخذها الوكيل (الاستدلال، واستدعاء الأدوات، وتطبيق الرموز البرمجية).
مواصلة المحادثة (محادثة مترابطة)
تتتبّع واجهة برمجة التطبيقات سمتَين مستقلتَين للحالة:
- سياق المحادثة: سجلّ المحادثات، وتتبُّع الاستدلال، واستخدام الأدوات، واستخدام
previous_interaction_id - حالة البيئة: الملفات والحِزم المثبَّتة وحالة وضع الحماية، باستخدام
environment
يجب تمرير كليهما في مكانهما المناسب لاستئناف العملية:
Python
interaction_2 = client.interactions.create(
agent="antigravity-preview-05-2026",
previous_interaction_id=interaction.id