การขยายขีดความสามารถ Managed Agents ใน Gemini API: งานเบื้องหลัง, Remote MCP และอื่นๆ

@GoogleAIStudio
อังกฤษ1 วันที่ผ่านมา · 07 ก.ค. 2569
192K
568
73
21
332

TL;DR

Google AI Studio เปิดตัวการอัปเดตครั้งใหญ่สำหรับ Gemini API Managed Agents ซึ่งช่วยให้นักพัฒนาสามารถรันงานเบื้องหลังระยะยาว, เชื่อมต่อกับเซิร์ฟเวอร์ Remote MCP และคงสถานะ Sandbox ไว้ได้อย่างต่อเนื่อง

วันนี้เราขอประกาศความสามารถใหม่ใน 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

bash
1npm install @google/genai

สร้างเอเจนต์อัตโนมัติด้วยความสามารถที่ขยายเพิ่ม

การทำงานเบื้องหลังแบบระยะยาว

การคงการเชื่อมต่อ HTTP ไว้เป็นเวลานานสำหรับงานที่ใช้เวลานานนั้นเปราะบาง ส่งค่า background: true เพื่อรันการโต้ตอบแบบอะซิงโครนัสบนเซิร์ฟเวอร์ API จะส่งคืน ID ทันที ซึ่งแอปพลิเคชันไคลเอนต์สามารถใช้เพื่อตรวจสอบสถานะ สตรีมความคืบหน้า หรือเชื่อมต่อใหม่ในภายหลังในขณะที่เอเจนต์ทำงานเสร็จสิ้นจากระยะไกล สำหรับรายละเอียดเพิ่มเติม โปรดอ่าน คู่มือการทำงานเบื้องหลัง

typescript
1import { GoogleGenAI } from "@google/genai";
2
3const client = new GoogleGenAI({});
4
5// 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});
12
13console.log(`Background task started. Interaction ID: ${interaction.id}`);
14
15// 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}
21
22if (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 ภายนอก

typescript
1import { GoogleGenAI } from "@google/genai";
2
3const client = new GoogleGenAI({});
4
5const 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});
19
20console.log(interaction.output_text);

การเรียกใช้ฟังก์ชันแบบกำหนดเองควบคู่กับเครื่องมือแซนด์บ็อกซ์

เพิ่ม เครื่องมือแบบกำหนดเอง ควบคู่ไปกับเครื่องมือแซนด์บ็อกซ์ในตัวสำหรับการทำงานในเครื่อง API ใช้การจับคู่ขั้นตอน (step matching) เครื่องมือในตัวจะทำงานโดยอัตโนมัติบนเซิร์ฟเวอร์ ในขณะที่ฟังก์ชันแบบกำหนดเองจะเปลี่ยนสถานะการโต้ตอบเป็น requires_action เพื่อให้ไคลเอนต์ของคุณดำเนินการตามตรรกะทางธุรกิจในเครื่อง

typescript
1import { GoogleGenAI } from "@google/genai";
2
3const client = new GoogleGenAI({});
4
5// 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};
21
22// 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});
32
33// 3. จัดการการทำงานของฟังก์ชันแบบกำหนดเองอย่างสะอาด
34if (interaction.status === "requires_action") {
35 // เครื่องมือระบบไฟล์และแซนด์บ็อกซ์ทำงานโดยอัตโนมัติและสร้างขั้นตอน function_result ที่ตรงกัน
36 // เรากรองหา calls โดเมนที่รอดำเนินการซึ่งต้องการการทำงานฝั่งไคลเอนต์
37 const executedCalls = new Set(
38 interaction.steps
39 .filter((s) => s.type === "function_result")
40 .map((s) => s.call_id)
41 );
42
43 const pendingCalls = interaction.steps.filter(
44 (s) => s.type === "function_call" && !executedCalls.has(s.id)
45 );
46
47 for (const call of pendingCalls) {
48 console.log(`Executing client tool: ${call.name} (ID: ${call.id})`);
49 // ดำเนินการค้นหา API/ฐานข้อมูลในเครื่องของคุณและส่ง function_result กลับในเทิร์นที่ 2
50 }
51}

การรีเฟรชข้อมูลรับรองเครือข่าย

โทเค็นการเข้าถึงและคีย์ API ที่มีอายุสั้นหมดอายุ คุณสามารถรีเฟรชข้อมูลรับรองหรือหมุนคีย์ได้โดยส่ง environment_id ที่มีอยู่ของคุณพร้อมกับ การกำหนดค่าเครือข่าย ใหม่ในการโต้ตอบครั้งถัดไป กฎใหม่จะแทนที่กฎเก่าทันที แซนด์บ็อกซ์ของคุณจะคงสถานะระบบไฟล์ แพ็กเกจที่ติดตั้ง และพื้นที่เก็บข้อมูลที่โคลนไว้เหมือนเดิม

typescript
1import { GoogleGenAI } from "@google/genai";
2const client = new GoogleGenAI({});
3
4// 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});
22
23// 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 อย่างรวดเร็ว เพื่อสำรวจคำจำกัดความของเอเจนต์แบบกำหนดเอง การกำหนดค่าสภาพแวดล้อม กฎเครือข่าย และรูปแบบการสตรีมขั้นสูง

บันทึกในคลิกเดียว

อ่านบทความไวรัลเชิงลึกด้วย AI ใน YouMind

Save the source, ask focused questions, summarize the argument, and turn a viral article into reusable notes in one AI workspace.

Explore YouMind
สำหรับครีเอเตอร์

เปลี่ยน Markdown ของคุณให้เป็นบทความ 𝕏 ที่สะอาดตา

เวลาคุณเผยแพร่งานเขียนยาวของตัวเอง การจัดรูปแบบรูปภาพ ตาราง และบล็อกโค้ดให้เข้ากับ 𝕏 นั้นน่าปวดหัว YouMind เปลี่ยนร่าง Markdown ทั้งฉบับให้เป็นบทความ 𝕏 ที่สะอาดตาและพร้อมโพสต์ทันที

ลอง Markdown เป็น 𝕏

แพตเทิร์นให้ถอดรหัสเพิ่มเติม

บทความไวรัลล่าสุด

สำรวจบทความไวรัลเพิ่มเติม