| [ Web Proxy ] |
| Viewing: https://adk.dev/integrations/../../context/../../../runtime/../../agents/managed-agents/ | [Back] [Original] |
[logo]
Managed agents let you use Google's first-party, out-of-the-box agents, backed
by the Managed Agents API, from within your ADK flows. Managed agents are
available through the Gemini API
and Agent
Platform.
The ManagedAgent class connects to a managed agent (such as the Antigravity
agent) that runs in a specialized, server-side execution environment, so you get
powerful built-in capabilities without managing sandboxes or writing client-side
function declarations.
ManagedAgent implements the same BaseAgent contract as other ADK agents, so
you can use it standalone or drop it directly into an ADK flow. It is a good fit
when you want a robust, server-hosted agent with specialized built-in tools
rather than building and operating that environment yourself.
A managed agent is an agent whose reasoning, tools, and execution environment
are hosted and operated by Google through the Managed Agents API, rather than
run by your own ADK process. Instead of issuing standard generate_content
calls, ManagedAgent creates server-side interactions and streams the results
back into your ADK flow. Managed agents provide several built-in advantages:
agent_id.Managed agents and ADK agents solve different problems. Choosing between them is mostly a trade-off between out-of-the-box power and fine-grained control.
LlmAgent) give you
fine-grained control over the model, instructions, tools (including custom
function tools and MCP tools), and where execution happens.ManagedAgent supports two backends. Complete the prerequisites for the backend
you plan to use: obtain credentials and an agent_id.
GEMINI_API_KEY
environment variable.agent_id to connect to. You can either:antigravity-preview-05-2026,
which is used in the examples below.gcloud auth
application-default login).global
location. ManagedAgent enforces a connection to global on the Agent
Platform backend.agent_id. Create one using
the Create and manage agents
guide,
or use an out-of-the-box agent ID available to your project.The following example creates two managed agents: one that answers questions
using web search, and one that solves computational questions by running code
server-side. Both run their tools in the managed environment
(environment={'type': 'remote'}).
import os
from google.adk.agents import ManagedAgent
from google.adk.tools import google_search
from google.genai import types
# Ensure you have the MANAGED_AGENT_ID and the proper environment config
_AGENT_ID = os.environ.get('MANAGED_AGENT_ID', 'antigravity-preview-05-2026')
managed_search_agent = ManagedAgent(
name='managed_search_agent',
description='Answers questions that need fresh, grounded information from the web.',
agent_id=_AGENT_ID,
environment={'type': 'remote'},
tools=[google_search],
)
# A managed code execution agent using raw types.Tool
managed_code_execution_agent = ManagedAgent(
name='managed_code_execution_agent',
description='Solves computational questions by running code server-side.',
agent_id=_AGENT_ID,
environment={'type': 'remote'},
tools=[types.Tool(code_execution=types.ToolCodeExecution())],
)
When you invoke a ManagedAgent, ADK sends your request to the managed agent
via the Interactions
API and streams
the results, both partial and final, back into your ADK flow in real time. The
reasoning, tools, and execution all run in Google's managed environment rather
than in your ADK process.
How ManagedAgent maps to the Managed Agents API
An ADK ManagedAgent does not create or register a new managed agent
resource. It connects to an agent that already exists on the backend (the
one named by agent_id) and applies its configuration (such as tools and
environment) as per-interaction overrides at runtime. In Managed Agents
API terms, ADK works entirely on the data plane (the Interactions API) and
leaves the control plane (the Agents API, which creates and manages agent
resources) untouched. For how these two planes differ, see the Managed
Agents API system
architecture.
ManagedAgent keeps almost no state locally. The ADK session persists only two
values on the events it emits: the previous_interaction_id and the sandbox
environment_id. On each new turn the agent recovers both by scanning prior
session events, then reuses them so the conversation and its sandbox continue.
Everything else lives server-side. The Managed Agents API owns the sandbox environment and the full interaction history, and that remote interaction, not the local session, is the source of truth for continuing a conversation. Response text appears in both the local ADK events and the remote interaction history, but ADK stores only the IDs it needs to recover and reuse the remote state; it never re-sends prior turns.
global location.
Regional endpoints raise an error.NotImplementedError.stream=True).
Background-polling execution and strictly non-streaming connections are not
yet fully supported.| Web Proxy Viewer | New URL | Original Page |