Google adds background tasks, remote MCP servers, and credential refresh to the Gemini API
Google is expanding the Managed Agents feature in the Gemini API to support asynchronous execution, remote Model Context Protocol (MCP) servers, custom function calling, and automatic credential rotation. These changes address developer requests for building agents that can run reliably in production environments.
The Gemini Interactions API allows a single endpoint call to handle reasoning, code execution, package installation, file management, and web searches within an isolated cloud sandbox. Developers can enable the Interactions API skill using the following command:
npx skills add google-gemini/gemini-skills --skill gemini-interactions-apiThe examples below use the @google/genai JavaScript SDK. Python and cURL users should consult the Antigravity agent documentation.
npm install @google/genaiExpanded capabilities for autonomous agents
Long-running background execution
Maintaining an open HTTP connection for extended tasks is unreliable. Developers can now pass background: true to run interactions asynchronously on the server. The API returns an ID immediately, allowing client applications to poll for status, stream progress, or reconnect later while the agent works remotely. See the background execution guide for details.
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// 1. Start a long-running analysis in the background
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
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.",
environment: "remote",
background: true,
});
console.log(`Background task started. Interaction ID: ${interaction.id}`);
// 2. Poll asynchronously without blocking an open HTTP socket
let result = interaction;
while (result.status === "in_progress") {
await new Promise((resolve) => setTimeout(resolve, 5000));
result = await client.interactions.get(interaction.id);
}
if (result.status === "completed") {
console.log("Task Completed:\n", result.output_text);
} else {
console.error(`Task ended with status: ${result.status}`);
}Remote MCP server integration
Developers no longer need custom proxy middleware to access private databases or internal APIs. Managed agents can now connect directly to remote Model Context Protocol (MCP) servers.
You can combine 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. Follow best practices when extending your agent with external tools and APIs.
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Check our internal observability server for recent latency spikes in the auth service and correlate them with git commits.",
environment: "remote",
tools: [
{ type: "google_search" },
{ type: "code_execution" },
{
type: "mcp_server",
name: "internal_telemetry",
url: "https://mcp.internal.example.com/mcp",
},
],
});
console.log(interaction.output_text);Custom function calling alongside sandbox tools
You can add custom tools alongside built-in sandbox tools for local execution. The API uses step matching. Built-in tools run automatically on the server, while custom functions transition the interaction to requires_action so your client executes local business logic.
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// 1. Define a custom domain function
const getWeatherTool = {
type: "function",
name: "get_weather",
description: "Gets the current weather for a given location.",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and country, e.g. San Francisco, USA",
},
},
required: ["location"],
},
};
// 2. Invoke the agent with both built-in code execution and custom functions
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Check the weather in Tokyo, write a Python script to convert the temperature to Fahrenheit, and save the result to weather.txt.",
environment: "remote",
tools: [
{ type: "code_execution" },
getWeatherTool,
],
});
// 3. Handle custom function execution cleanly
if (interaction.status === "requires_action") {
// Filesystem and sandbox tools execute automatically and produce a matching function_result step.
// We filter for pending domain calls that require client-side execution.
const executedCalls = new Set(
interaction.steps
.filter((s) => s.type === "function_result")
.map((s) => s.call_id)
);
const pendingCalls = interaction.steps.filter(
(s) => s.type === "function_call" && !executedCalls.has(s.id)
);
for (const call of pendingCalls) {
console.log(`Executing client tool: ${call.name} (ID: ${call.id})`);
// Execute your local API/database query and send the function_result back in turn 2
}
}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.
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// 1. First interaction: use an initial token
const first = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "List the files in gs://my-bucket/reports/ using the GCS JSON API.",
environment: {
type: "remote",
network: {
allowlist: [
{
domain: "storage.googleapis.com",
transform: {
Authorization: "Bearer INITIAL_TOKEN",
},
},
],
},
},
});
// 2. Later: refresh the token on the same environment
const result = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Now download the file reports/q1.csv from the same bucket.",
environment: {
type: "remote",
environment_id: first.environment_id,
network: {
allowlist: [
{
domain: "storage.googleapis.com",
transform: {
Authorization: "Bearer REFRESHED_TOKEN",
},
},
],
},
},
});
console.log(result.output_text);Get started with managed agents
These updates allow managed agents to operate as asynchronous workers inside real development environments without blocking your application.
Review the Gemini Interactions API overview and the managed agents quickstart to explore custom agent definitions, environment configurations, network rules, and advanced streaming patterns.




