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.
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.
1import { GoogleGenAI } from "@google/genai";23const client = new GoogleGenAI({});45// 1. Start a long-running analysis in the background6const 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. Poll asynchronously without blocking an open HTTP socket16let 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}
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.
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);
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.
1import { GoogleGenAI } from "@google/genai";23const client = new GoogleGenAI({});45// 1. Define a custom domain function6const 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. Invoke the agent with both built-in code execution and custom functions23const 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. Handle custom function execution cleanly34if (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.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 // Execute your local API/database query and send the function_result back in turn 250 }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.
1import { GoogleGenAI } from "@google/genai";2const client = new GoogleGenAI({});34// 1. First interaction: use an initial token5const 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. Later: refresh the token on the same environment24const 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.





