AI Agents

Gemini API Managed Agents: Background Tasks and Remote MCP for Production-Ready Agents

Google expands Managed Agents in Gemini API with background execution, remote MCP servers, custom functions, and credential refresh. Learn how to build reliable, production-ready…

Gemini API Managed Agents: Background Tasks and Remote MCP for Production-Ready Agents — article cover
On this page6 SECTIONS
  1. What Changed: From Synchronous Calls to Asynchronous Workers
  2. How It Works: Background Execution and Remote MCP in Practice
  3. Practical Use Cases for Product Builders
  4. Limitations and Trade-offs
  5. Key Takeaways for Building with Managed Agents
  6. Sources

Google has announced new capabilities for Managed Agents in the Gemini API, aimed at helping developers build reliable, production-ready agents. The updates include background execution for asynchronous tasks, remote MCP server integration, custom function calling, and credential refresh across interactions. For product builders and AI tool learners, these features represent a shift from simple conversational bots to long-running, cross-system execution units. This article breaks down what changed, how it works, practical use cases, limitations, and key takeaways.

What Changed: From Synchronous Calls to Asynchronous Workers

Previously, calling an agent via the Gemini API was largely synchronous: you send a request, wait for a response, and the interaction ends. That model breaks down for real-world tasks like batch processing documents, scraping websites, or generating reports, which can take minutes or longer. Holding an HTTP connection open for such long-running tasks is fragile, as the official blog notes.

The new background execution feature addresses this by allowing interactions to run asynchronously on the server. By passing background: true, the API immediately returns an interaction ID, which client applications can use to poll for status, stream progress, or reconnect later while the agent finishes remotely. This changes the interaction model from a request-response pattern to a job-queue-like architecture, enabling agents to act as asynchronous workers.

In addition to background tasks, Google introduced remote MCP server integration. Model Context Protocol (MCP) has become a standard for connecting agents to external tools, but previously it was often limited to local or same-environment setups. Now, managed agents can connect directly to remote MCP servers, allowing access to private databases or internal APIs without writing custom proxy middleware. This is particularly useful for enterprises where tools are distributed across departments or cloud environments.

Other updates include custom function calling alongside built-in sandbox tools, and the ability to refresh credentials across interactions, which helps maintain long-running sessions securely.

How It Works: Background Execution and Remote MCP in Practice

The official blog provides code examples using the @google/genai JavaScript SDK. For Python or cURL, developers are directed to the Antigravity agent documentation.

Background Execution

To start a long-running analysis in the background, you create an interaction with background: true. The API returns an ID immediately, and you can poll for status using client.interactions.get(). Here’s a simplified example from the blog:

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

This pattern allows you to submit a task and check back later, freeing your application from maintaining a persistent connection.

Remote MCP Server Integration

To connect a managed agent to a remote MCP server, you pass an mcp_server tool at interaction time, alongside built-in tools like Google Search or code execution. The blog shows an example where the agent checks an internal observability server for latency spikes and correlates them with git commits:

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

This lets the agent communicate with your endpoints from its secure sandbox, mixing remote tools with built-in capabilities.

Custom Function Calling

Custom functions allow you to add domain-specific tools alongside built-in sandbox tools. 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. The blog provides an example with a get_weather function:

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 result
}

This hybrid approach lets you keep sensitive logic on your side while leveraging the agent’s built-in capabilities.

Practical Use Cases for Product Builders

These features open up several practical scenarios for products that need more than a simple chatbot.

  • Asynchronous document processing: Users upload contracts, reports, or datasets. The system starts a background task to analyze, summarize, or extract data, then notifies the user when done. This fits a job-queue model and improves UX by not blocking the user.
  • Cross-system data correlation: With remote MCP, agents can pull data from internal CRM, databases, or third-party services. For example, an agent could check internal telemetry for latency spikes and correlate them with recent code commits, as shown in the blog. This is valuable for DevOps and incident response.
  • Hybrid tool execution: Custom functions allow you to keep proprietary algorithms or sensitive operations on your infrastructure while letting the agent handle reasoning and sandbox tasks. For instance, you could have the agent generate a report and then call a custom function to apply your company’s specific formatting rules.
  • Long-running research tasks: Background execution is ideal for tasks like web scraping, batch analysis, or report generation that take minutes. The agent can run in the background while the user continues other work.

Limitations and Trade-offs

The official blog post is an announcement, not a full technical reference. It highlights the features but leaves out critical details that developers will need for production deployment.

  • No explicit limits: The blog does not specify maximum execution time for background tasks, concurrency limits, or rate limits. You’ll need to check the API documentation for these constraints.
  • Security and authentication: Remote MCP integration raises security concerns. The blog mentions following best practices for extending agents with external tools, but does not detail authentication methods, encryption, or how to prevent prompt injection. You must design these safeguards yourself.
  • Monitoring and debugging: Background tasks and remote connections increase system complexity. You’ll need robust logging and tracing to understand what the agent is doing, especially when it’s running asynchronously.
  • Credential refresh: While the feature is mentioned, the blog doesn’t explain how it works in detail. You’ll need to consult the documentation to implement it correctly.

Key Takeaways for Building with Managed Agents

These updates signal that Google is pushing agents from single-turn conversations toward persistent, service-like execution. For product builders, the implications are clear:

  • Design async-first: If your agent handles long tasks, rethink the user experience. Instead of making users wait, design a “task submitted, we’ll notify you” flow.
  • Standardize tool connections: Remote MCP makes tool integration more modular, but requires strict management of connection settings and permissions.
  • Invest in observability: With background tasks and remote connections, you need comprehensive logging and tracing to debug effectively.

Before adopting these features, read the full API documentation and run small-scale proofs of concept, especially around security and reliability. The tools are just the foundation; the real product value comes from how you design the agent’s task flow and error handling. As the blog states, these capabilities are designed to help you build reliable, production-ready agents—but the responsibility for production readiness ultimately lies with you.

Sources

AI-assisted summary compiled from the sources above, reviewed by a human before publishing.

SHAREXEMAIL