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

Expanding Managed Agents in Gemini API: background tasks, remote MCP and more
Google adding support for new capabilities like background execution for async interactions, easy connection to remote MCP servers, custom functions and credential refresh.
Today google announcing new capabilities for 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.
npm 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.
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
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.
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
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.
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 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.

🚀 Core Updates to Managed Agents
1. Long-Running Background Execution [5] from Expanding Managed
- How it works: Passing
background: truetriggers the server to process the interaction asynchronously. - State Management: The API instantly returns an interaction ID. Client applications can disconnect and later use this ID to poll status, stream progress, or retrieve the complete execution state once finished. [4, 7]
2. Remote MCP Server Integration [7]
- Unified Tooling: You can pass an
mcp_servertool configuration at interaction time alongside built-in capabilities like Google Search or code execution. [8] - Direct Access: This allows the agent to safely read from or write to private databases, proprietary internal APIs, and secure data streams directly from its cloud sandbox without infrastructure overhead. [4, 8]
3. Custom Function Calling (Step Matching) [5, 8, 10] from Expanding Managed
- Built-in Tools: General utilities like code execution or web searches execute automatically on Google’s server infrastructure.
- Local Actions: When the agent decides to invoke a custom client function, the API uses “step matching” to pause the interaction and transition its state to
requires_action. This yields control back to your client code to execute local logic safely before resuming. [8]
4. Mid-Session Network Credential Refresh [5]
- State Preservation: You can now rotate security tokens and apply a new network configuration on subsequent interactions by passing the existing
environment_id. [11] - Seamless Updates: The updated network rules take effect instantly without clearing the sandbox’s underlying filesystem, cloned repositories, or installed packages. [11]
🛠️ Example: Inline Agent Configuration
{
"system_instruction": "You are a production DevOps assistant.",
"background": true,
"tools": [
{ "code_execution": {} },
{ "google_search": {} },
{
"mcp_server": {
"name": "internal_inventory_db",
"url": "https://company.com",
"headers": {
"Authorization": "Bearer EXPIRED_TOKEN_REFRESHABLE_HERE"
}
}
},
{
"function_declarations": [
{
"name": "triggerLocalSlackAlert",
"description": "Notifies the team locally when a step requires a manual gateway approval."
}
]
}
]
}
🔒 Architectural Best Practices
- Separate Phases: Allow the agent to asynchronously gather context, inspect logs, and draft code autonomously, but introduce strict manual approval gates before irreversible write steps (e.g., merging code or modifying live production data). [13]
- Auditability: Log precisely which user initiated the agent interaction, which specific remote MCP endpoints were targeted, and what parameters were passed. [13]
- Expanding Managed
Read more
. Big news for Jodhpur! A world-class airport terminal is here
. MCP vs API: Why traditional APIs are failing AI agents
. A new way to connect and earn with gifts
. What’s at the center of Claude’s mind?
. Join video conferences on Google Meet hardware via SIP through Pexip
. Occupancy counting now available for Google Meet on Neat room hardware
.Fill with Gemini in Sheets now available in 11 additional languages
. New calendar sharing permission level and changes to recurring event visibility
for more refer Gemini website click here
for more refer Artificial Intelligence website click here

