{"slug": "gemini-api-managed-agents-background-execution-and-remote-mcp-guide", "title": "Gemini API Managed Agents: Background Execution and Remote MCP Guide", "summary": "Google shipped four production-readiness upgrades to Gemini API Managed Agents on July 7, including background execution that allows agents to run asynchronously server-side without a persistent HTTP connection, and remote MCP support for calling private APIs from inside the sandbox. The background execution feature, enabled by setting background=True, returns an interaction ID immediately and supports polling or resuming streams via last_event_id, available on the free tier for gemini-3.5-flash, gemini-3.1-pro-preview, and antigravity-preview-05-2026. Remote MCP lets agents call MCP-compatible endpoints by passing an mcp_server tool at interaction time, with the MCP 2026-07-28 spec removing stateful sessions for stateless builds.", "body_md": "Google shipped four production-readiness upgrades to **Gemini API Managed Agents** on July 7. The headline feature: background execution — agents now run asynchronously server-side without a persistent HTTP connection. If you’ve been watching Managed Agents since Google I/O and waiting for them to handle real workloads, this is the update that tips the scale.\n\n## What Managed Agents Are (If You Missed Google I/O)\n\nManaged Agents in the Gemini API, introduced at [Google I/O May 2026](https://blog.google/innovation-and-ai/technology/developers-tools/google-io-2026-developer-highlights/), give you a fully provisioned, sandboxed Linux agent environment via a single API call. Pass in an agent name, a model, and input — Google runs it in an isolated container with code execution, Google Search, and a writable filesystem already wired up. No infrastructure to manage, no orchestration layer to build.\n\nThe limitation has been obvious: agents run synchronously, requiring an open HTTP connection for the full duration. Complex tasks take minutes; HTTP timeouts kick in after seconds. That mismatch has been the primary reason teams held off on using Managed Agents for anything beyond quick queries.\n\n## Background Execution: The Feature That Actually Matters\n\nThe fix is a single parameter: `background=True`\n\n. When set, `interactions.create()`\n\nreturns an interaction ID immediately. The agent continues running on Google’s servers. Your connection dropping is no longer fatal.\n\n``` python\nfrom google import genai\nimport time\n\nclient = genai.Client()\n\n# Returns immediately with an interaction ID\ninteraction = client.interactions.create(\n    agent=\"antigravity-preview-05-2026\",\n    input=\"Analyze Q1 revenue data, identify anomalies, and generate a report\",\n    background=True\n)\n\n# Poll until done\nwhile True:\n    result = client.interactions.get(interaction.id)\n    if result.status in [\"completed\", \"failed\"]:\n        break\n    time.sleep(5)\n\nprint(result.output)\n```\n\nIf your connection drops mid-task, pass `last_event_id`\n\nto resume the stream from where it left off. The task keeps running regardless. Background execution is supported for `gemini-3.5-flash`\n\n, `gemini-3.1-pro-preview`\n\n, and `antigravity-preview-05-2026`\n\n— and is available on the free tier. Full details are in [Google’s background execution documentation](https://ai.google.dev/gemini-api/docs/background-execution).\n\n## Remote MCP: Your Private APIs Inside Google’s Sandbox\n\nThe second major addition lets a Managed Agent call your MCP-compatible endpoints directly from inside its sandbox. Pass an `mcp_server`\n\ntool at interaction time:\n\n```\ninteraction = client.interactions.create(\n    agent=\"antigravity-preview-05-2026\",\n    input=\"Fetch all P0 bugs from Jira and correlate with the last 10 commits\",\n    tools=[\n        {\"type\": \"mcp_server\", \"url\": \"https://your-jira-mcp.example.com/mcp\"},\n        {\"type\": \"code_execution\"},\n        {\"type\": \"google_search\"}\n    ]\n)\n```\n\nThe practical unlocking here is significant. Previously, getting an agent to touch internal data — your ticket system, a proprietary analytics API, an IoT backend — required either exposing endpoints publicly or building a custom proxy function. Remote MCP removes that friction. Network allowlists and credential patterns handle access control on your side.\n\nOne important note if you’re building a remote MCP server for this: the [MCP 2026-07-28 spec](https://www.digitalapplied.com/blog/mcp-2026-07-28-spec-stateless-migration-guide) shipping today removes stateful sessions entirely. Every request carries its own context in `_meta`\n\n; the `initialize`\n\nhandshake is gone. Build your MCP server stateless from day one. ByteIota covered the [full migration guide yesterday](https://byteiota.com/mcp-2026-07-28-spec-sessions-gone-migration-guide/).\n\n## Credential Refresh and Custom Functions\n\nThe other two additions are less flashy but equally important for production use.\n\n**Credential refresh** solves the token expiry problem. When a short-lived OAuth token expires mid-workflow, you previously lost all sandbox state — filesystem, installed packages, cloned repositories. Now pass your existing `environment_id`\n\nwith updated credentials, and the new rules take effect immediately while sandbox state persists. Hour-long agentic workflows are now viable.\n\n**Custom functions** let you define domain-specific capabilities the agent can call in its reasoning loop — proprietary data fetchers, internal metric endpoints, pre-processing functions. These extend the sandbox without requiring a full MCP server setup, which is useful for smaller integrations.\n\n## Where This Leaves the Agent Platform War\n\nThe honest comparison: Gemini Managed Agents give you Google-managed infrastructure. [OpenAI’s Agents SDK](https://platform.openai.com/docs/agents) and Anthropic’s Claude Agents SDK give you a model plus SDK layer — you manage execution yourself. Neither is objectively better.\n\nIf you need cross-cloud portability or want full control over where your agent code runs, Managed Agents aren’t for you. If you’re already on GCP and don’t want to build and maintain an orchestration layer, the July 7 update makes Managed Agents a genuinely compelling option. Background execution closes the reliability gap. Remote MCP closes the data access gap. Credential refresh makes long sessions viable.\n\nThe free tier availability across all four new features matters. Google isn’t locking this behind enterprise SKUs — adoption incentives are clearly the priority right now.\n\nAll four features are live. Start with the [official Google blog post](https://blog.google/innovation-and-ai/technology/developers-tools/expanding-managed-agents-gemini-api/) for context, then go straight to the [documentation](https://ai.google.dev/gemini-api/docs/background-execution) to implement.", "url": "https://wpnews.pro/news/gemini-api-managed-agents-background-execution-and-remote-mcp-guide", "canonical_source": "https://byteiota.com/gemini-api-managed-agents-background-execution-and-remote-mcp-guide/", "published_at": "2026-07-28 00:11:27+00:00", "updated_at": "2026-07-28 00:23:13.634091+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-products", "ai-tools", "ai-infrastructure", "developer-tools"], "entities": ["Google", "Gemini API", "Gemini API Managed Agents", "antigravity-preview-05-2026", "gemini-3.5-flash", "gemini-3.1-pro-preview", "MCP 2026-07-28 spec", "ByteIota"], "alternates": {"html": "https://wpnews.pro/news/gemini-api-managed-agents-background-execution-and-remote-mcp-guide", "markdown": "https://wpnews.pro/news/gemini-api-managed-agents-background-execution-and-remote-mcp-guide.md", "text": "https://wpnews.pro/news/gemini-api-managed-agents-background-execution-and-remote-mcp-guide.txt", "jsonld": "https://wpnews.pro/news/gemini-api-managed-agents-background-execution-and-remote-mcp-guide.jsonld"}}