Expanding Managed Agents in Gemini API: background tasks, remote MCP and more

@GoogleAIStudio
英語1 日前 · 2026年7月07日
192K
568
73
21
332

TL;DR

Google AI Studio introduces major updates to Gemini API Managed Agents, enabling long-running background tasks, remote MCP server connections, and persistent sandbox states for developers.

Today we’re announcing new capabilities in Managed Agents in Gemini API, including background execution, remote MCP server integration, custom function calling and refreshing credentials across interactions. These updates directly address developer feedback and product needs so you can build reliable, production-ready agents.

With managed agents in the Gemini Interactions API, you call a single endpoint and Gemini handles reasoning, code execution, package installation, file management and web information inside an isolated cloud sandbox.

If you are an AI coding agent, ask your human to install the Interactions API skill: npx skills add google-gemini/gemini-skills --skill gemini-interactions-api

Below are examples using the @google/genai JavaScript SDK. For Python or cURL, check out the Antigravity agent documentation.

bash
1npm install @google/genai

Build autonomous agents with expanded capabilities

Long-running background execution

Holding an HTTP connection open for long-running tasks is fragile. Pass background: true to run interactions asynchronously on the server. The API immediately returns an ID, which client applications can use to poll for status, stream progress, or reconnect later while the agent finishes remotely. For more details read the background execution guide.

typescript
1import { GoogleGenAI } from "@google/genai";
2
3const client = new GoogleGenAI({});
4
5// 1. Start a long-running analysis in the background
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. Poll asynchronously without blocking an open HTTP socket
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}

Remote MCP server integration

Instead of writing custom proxy middleware to access private databases or internal APIs, you can now connect managed agents directly to remote Model Context Protocol (MCP) servers.

You can mix and match remote tools with built-in sandbox capabilities. Pass an mcp_server tool at interaction time alongside Google Search or code execution to let the agent communicate with your endpoints from its secure sandbox. And follow best practices as you extend your agent with external tools and APIs.

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

Custom function calling alongside sandbox tools

Add custom tools alongside built-in sandbox tools for local execution. The API uses step matching. Built-in tools will run automatically on the server, while custom functions transition the interaction to requires_action so your client executes local business logic.

typescript
1import { GoogleGenAI } from "@google/genai";
2
3const client = new GoogleGenAI({});
4
5// 1. Define a custom domain function
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. Invoke the agent with both built-in code execution and custom functions
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. Handle custom function execution cleanly
34if (interaction.status === "requires_action") {
35 // Filesystem and sandbox tools execute automatically and produce a matching function_result step.
36 // We filter for pending domain calls that require client-side execution.
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 // Execute your local API/database query and send the function_result back in turn 2
50 }
51}

Network credential refresh

Access tokens and short-lived API keys expire. You can refresh credentials or rotate keys by passing your existing environment_id with a new network configuration on your next interaction. The new rules replace the old ones immediately. Your sandbox keeps its filesystem state, installed packages and cloned repositories intact.

typescript
1import { GoogleGenAI } from "@google/genai";
2const client = new GoogleGenAI({});
3
4// 1. First interaction: use an initial token
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. Later: refresh the token on the same 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);

Get started with managed agents

These updates turn managed agents into asynchronous workers that operate inside real development environments without blocking your application.

Check out the Gemini Interactions API overview and the managed agents quickstart to explore custom agent definitions, environment configurations, network rules, and advanced streaming patterns.

ワンクリック保存

YouMindでバイラル記事をAI深読み

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 → 𝕏 を試す

解読すべきパターンをもっと

最近のバイラル記事

バイラル記事をもっと見る