วันนี้เราขอประกาศความสามารถใหม่ใน Managed Agents ใน Gemini API ซึ่งรวมถึง การทำงานเบื้องหลัง, การรวม MCP Server ระยะไกล, การเรียกใช้ฟังก์ชันแบบกำหนดเอง และ การรีเฟรชข้อมูลรับรองระหว่างการโต้ตอบ การอัปเดตเหล่านี้ตอบสนองต่อความคิดเห็นของนักพัฒนาและความต้องการของผลิตภัณฑ์โดยตรง เพื่อให้คุณสามารถสร้างเอเจนต์ที่พร้อมใช้งานในระดับโปรดักชันได้อย่างน่าเชื่อถือ
ด้วย managed agents ใน Gemini Interactions API คุณเรียกใช้ปลายทางเดียว และ Gemini จะจัดการเกี่ยวกับการให้เหตุผล การรันโค้ด การติดตั้งแพ็กเกจ การจัดการไฟล์ และข้อมูลบนเว็บภายในแซนด์บ็อกซ์บนคลาวด์ที่แยกออกมา
หากคุณเป็น AI coding agent ให้ขอให้มนุษย์ของคุณติดตั้งทักษะ Interactions API: npx skills add google-gemini/gemini-skills --skill gemini-interactions-api
ด้านล่างนี้คือตัวอย่างที่ใช้ JavaScript SDK @google/genai สำหรับ Python หรือ cURL โปรดดูที่ เอกสารประกอบ Antigravity agent
1npm install @google/genai
สร้างเอเจนต์อัตโนมัติด้วยความสามารถที่ขยายเพิ่ม
การทำงานเบื้องหลังแบบระยะยาว
การคงการเชื่อมต่อ HTTP ไว้เป็นเวลานานสำหรับงานที่ใช้เวลานานนั้นเปราะบาง ส่งค่า background: true เพื่อรันการโต้ตอบแบบอะซิงโครนัสบนเซิร์ฟเวอร์ API จะส่งคืน ID ทันที ซึ่งแอปพลิเคชันไคลเอนต์สามารถใช้เพื่อตรวจสอบสถานะ สตรีมความคืบหน้า หรือเชื่อมต่อใหม่ในภายหลังในขณะที่เอเจนต์ทำงานเสร็จสิ้นจากระยะไกล สำหรับรายละเอียดเพิ่มเติม โปรดอ่าน คู่มือการทำงานเบื้องหลัง
1import { GoogleGenAI } from "@google/genai";23const client = new GoogleGenAI({});45// 1. เริ่มการวิเคราะห์ระยะยาวในเบื้องหลัง6const interaction = await client.interactions.create({7 agent: "antigravity-preview-05-2026",8 input: "Clone https://github.com/googleapis/js-genai, find all TODO comments in the source code, and categorize them by module and priority in a markdown report.",9 environment: "remote",10 background: true,11});1213console.log(`Background task started. Interaction ID: ${interaction.id}`);1415// 2. ตรวจสอบแบบอะซิงโครนัสโดยไม่บล็อกซ็อกเก็ต HTTP ที่เปิดอยู่16let result = interaction;17while (result.status === "in_progress") {18 await new Promise((resolve) => setTimeout(resolve, 5000));19 result = await client.interactions.get(interaction.id);20}2122if (result.status === "completed") {23 console.log("Task Completed:\n", result.output_text);24} else {25 console.error(`Task ended with status: ${result.status}`);26}
การรวม MCP Server ระยะไกล
แทนที่จะเขียนมิดเดิลแวร์พร็อกซีแบบกำหนดเองเพื่อเข้าถึงฐานข้อมูลส่วนตัวหรือ API ภายใน ตอนนี้คุณสามารถเชื่อมต่อ managed agents กับ MCP Servers ระยะไกล ได้โดยตรง
คุณสามารถผสมผสานเครื่องมือระยะไกลกับความสามารถของแซนด์บ็อกซ์ในตัวได้ ส่งเครื่องมือ mcp_server ในเวลาที่โต้ตอบควบคู่ไปกับ Google Search หรือการรันโค้ด เพื่อให้เอเจนต์สื่อสารกับปลายทางของคุณจากแซนด์บ็อกซ์ที่ปลอดภัย และปฏิบัติตาม แนวทางปฏิบัติที่ดีที่สุด ในขณะที่คุณขยายเอเจนต์ของคุณด้วยเครื่องมือและ API ภายนอก
1import { GoogleGenAI } from "@google/genai";23const client = new GoogleGenAI({});45const interaction = await client.interactions.create({6 agent: "antigravity-preview-05-2026",7 input: "Check our internal observability server for recent latency spikes in the auth service and correlate them with git commits.",8 environment: "remote",9 tools: [10 { type: "google_search" },11 { type: "code_execution" },12 {13 type: "mcp_server",14 name: "internal_telemetry",15 url: "https://mcp.internal.example.com/mcp",16 },17 ],18});1920console.log(interaction.output_text);
การเรียกใช้ฟังก์ชันแบบกำหนดเองควบคู่กับเครื่องมือแซนด์บ็อกซ์
เพิ่ม เครื่องมือแบบกำหนดเอง ควบคู่ไปกับเครื่องมือแซนด์บ็อกซ์ในตัวสำหรับการทำงานในเครื่อง API ใช้การจับคู่ขั้นตอน (step matching) เครื่องมือในตัวจะทำงานโดยอัตโนมัติบนเซิร์ฟเวอร์ ในขณะที่ฟังก์ชันแบบกำหนดเองจะเปลี่ยนสถานะการโต้ตอบเป็น requires_action เพื่อให้ไคลเอนต์ของคุณดำเนินการตามตรรกะทางธุรกิจในเครื่อง
1import { GoogleGenAI } from "@google/genai";23const client = new GoogleGenAI({});45// 1. กำหนดฟังก์ชันโดเมนแบบกำหนดเอง6const getWeatherTool = {7 type: "function",8 name: "get_weather",9 description: "Gets the current weather for a given location.",10 parameters: {11 type: "object",12 properties: {13 location: {14 type: "string",15 description: "The city and country, e.g. San Francisco, USA",16 },17 },18 required: ["location"],19 },20};2122// 2. เรียกใช้เอเจนต์ด้วยทั้งการรันโค้ดในตัวและฟังก์ชันแบบกำหนดเอง23const interaction = await client.interactions.create({24 agent: "antigravity-preview-05-2026",25 input: "Check the weather in Tokyo, write a Python script to convert the temperature to Fahrenheit, and save the result to weather.txt.",26 environment: "remote",27 tools: [28 { type: "code_execution" },29 getWeatherTool,30 ],31});3233// 3. จัดการการทำงานของฟังก์ชันแบบกำหนดเองอย่างสะอาด34if (interaction.status === "requires_action") {35 // เครื่องมือระบบไฟล์และแซนด์บ็อกซ์ทำงานโดยอัตโนมัติและสร้างขั้นตอน function_result ที่ตรงกัน36 // เรากรองหา calls โดเมนที่รอดำเนินการซึ่งต้องการการทำงานฝั่งไคลเอนต์37 const executedCalls = new Set(38 interaction.steps39 .filter((s) => s.type === "function_result")40 .map((s) => s.call_id)41 );4243 const pendingCalls = interaction.steps.filter(44 (s) => s.type === "function_call" && !executedCalls.has(s.id)45 );4647 for (const call of pendingCalls) {48 console.log(`Executing client tool: ${call.name} (ID: ${call.id})`);49 // ดำเนินการค้นหา API/ฐานข้อมูลในเครื่องของคุณและส่ง function_result กลับในเทิร์นที่ 250 }51}
การรีเฟรชข้อมูลรับรองเครือข่าย
โทเค็นการเข้าถึงและคีย์ API ที่มีอายุสั้นหมดอายุ คุณสามารถรีเฟรชข้อมูลรับรองหรือหมุนคีย์ได้โดยส่ง environment_id ที่มีอยู่ของคุณพร้อมกับ การกำหนดค่าเครือข่าย ใหม่ในการโต้ตอบครั้งถัดไป กฎใหม่จะแทนที่กฎเก่าทันที แซนด์บ็อกซ์ของคุณจะคงสถานะระบบไฟล์ แพ็กเกจที่ติดตั้ง และพื้นที่เก็บข้อมูลที่โคลนไว้เหมือนเดิม
1import { GoogleGenAI } from "@google/genai";2const client = new GoogleGenAI({});34// 1. การโต้ตอบครั้งแรก: ใช้โทเค็นเริ่มต้น5const first = await client.interactions.create({6 agent: "antigravity-preview-05-2026",7 input: "List the files in gs://my-bucket/reports/ using the GCS JSON API.",8 environment: {9 type: "remote",10 network: {11 allowlist: [12 {13 domain: "storage.googleapis.com",14 transform: {15 Authorization: "Bearer INITIAL_TOKEN",16 },17 },18 ],19 },20 },21});2223// 2. ภายหลัง: รีเฟรชโทเค็นบน environment เดียวกัน24const result = await client.interactions.create({25 agent: "antigravity-preview-05-2026",26 input: "Now download the file reports/q1.csv from the same bucket.",27 environment: {28 type: "remote",29 environment_id: first.environment_id,30 network: {31 allowlist: [32 {33 domain: "storage.googleapis.com",34 transform: {35 Authorization: "Bearer REFRESHED_TOKEN",36 },37 },38 ],39 },40 },41});42console.log(result.output_text);
เริ่มต้นใช้งาน managed agents
การอัปเดตเหล่านี้เปลี่ยน managed agents ให้เป็นผู้ทำงานแบบอะซิงโครนัสที่ทำงานภายในสภาพแวดล้อมการพัฒนาจริง โดยไม่บล็อกแอปพลิเคชันของคุณ
ดู ภาพรวม Gemini Interactions API และ คำแนะนำเริ่มต้นใช้งาน managed agents อย่างรวดเร็ว เพื่อสำรวจคำจำกัดความของเอเจนต์แบบกำหนดเอง การกำหนดค่าสภาพแวดล้อม กฎเครือข่าย และรูปแบบการสตรีมขั้นสูง





