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

Gemini API adds background tasks, remote MCP, and credential rotation to managed agents Google is expanding the Gemini Interactions API with support…

By Vane August 6, 2026 4 min read
Expanding Managed Agents in Gemini API:  background tasks, remote MCP and more


Gemini API adds background tasks, remote MCP, and credential rotation to managed agents

Google is expanding the Gemini Interactions API with support for asynchronous execution, remote Model Context Protocol servers, custom function calling, and automatic credential refresh. These changes address developer requests for more reliable, production-ready agents.

Managed agents in this API run inside an isolated cloud sandbox. A single endpoint call handles reasoning, code execution, package installation, file management and web searches.

To use the Interactions API skill, run this command in your terminal:

npx skills add google-gemini/gemini-skills --skill gemini-interactions-api.

The examples below use the JavaScript SDK. Python users and those preferring cURL should check the Antigravity agent documentation.

npm install @google/genai

New capabilities for autonomous agents

Long-running background execution

Keeping an HTTP connection open for long tasks is fragile. You can now pass background: true to run interactions asynchronously on the server. The API returns an ID immediately. Client applications can use this ID to poll for status, stream progress, or reconnect later while the agent finishes remotely.

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 servers.

You can mix remote tools with built-in sandbox capabilities. Pass an mcp_server tool at interaction time alongside Google Search or code execution. This lets 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. 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);

Getting started

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.


Scroll to Top