Skip to content

Commit 969909f

Browse files
haranrkcopybara-github
authored andcommitted
docs(samples): Add ManagedAgent sample using server-side google_search
Add a runnable sample under contributing/samples/managed_agent/basic showing how to use ManagedAgent (backed by the Managed Agents API) with the server-side google_search tool, mirroring the live integration test flow. The sample exposes a root_agent in agent.py and ships a README covering the required enterprise/ADC setup and example prompts (including a multi-turn follow-up that reuses the recovered remote sandbox). Co-authored-by: Haran Rajkumar <haranrk@google.com> PiperOrigin-RevId: 943536117
1 parent 9a79fa1 commit 969909f

3 files changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Managed Agent
2+
3+
## Overview
4+
5+
This sample runs a `ManagedAgent` configured with the built-in `google_search`
6+
tool. Given an open-ended request, the server-side harness autonomously issues
7+
many searches and synthesizes the result in a single turn.
8+
9+
## Sample Inputs
10+
11+
- `Compare the current flagship smartphones from Apple, Samsung, and Google. For each, find its launch price, display size, and main rear camera resolution, then recommend the best value for someone who mostly takes photos.`
12+
13+
The showcase input. A single question the harness answers by fanning out into a
14+
dozen-odd searches. It does broad discovery first, then targeted per-model spec
15+
and price lookups, self-correcting when it hits a stale model, before composing
16+
a comparison table and a reasoned recommendation.
17+
18+
- `Which of those would you pick for shooting video instead?`
19+
20+
A follow-up turn that reuses the recovered remote sandbox and the previous
21+
interaction, continuing the same research thread. This demonstrates multi-turn
22+
chaining.
23+
24+
## Graph
25+
26+
```mermaid
27+
graph LR
28+
User -->|message| ManagedAgent
29+
ManagedAgent -->|interactions.create| ManagedAgentsAPI
30+
ManagedAgentsAPI -->|server-side research loop: google_search ×N| ManagedAgentsAPI
31+
ManagedAgentsAPI -->|streamed events| ManagedAgent
32+
ManagedAgent -->|answer| User
33+
```
34+
35+
## How To
36+
37+
- **Create the agent**: instantiate `ManagedAgent` with an `agent_id`, an
38+
`environment` spec, and a list of server-side `tools`. No `model` is set; the
39+
model is part of the managed agent on the server.
40+
- **Provision a sandbox**: `environment={'type': 'remote'}` requests a fresh
41+
remote sandbox. The resulting environment id is stored on emitted events, so
42+
subsequent turns automatically recover and reuse it.
43+
- **Multi-turn chaining**: the agent recovers the `previous_interaction_id` from
44+
the session events, so follow-up turns continue the same interaction without
45+
any extra wiring.
46+
- **Drive it**: a `ManagedAgent` is a `BaseAgent`, so a standard `Runner` runs
47+
it just like any other agent.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from . import agent
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""A ManagedAgent backed by the Managed Agents API (interactions.create).
16+
17+
``ManagedAgent`` calls the Managed Agents API directly from its run loop instead
18+
of running a local model loop. It currently supports server-side tools only
19+
(ADK built-in tools and raw ``google.genai.types.Tool`` configs); here we wire
20+
up ``google_search``, which runs entirely on the server.
21+
22+
A fresh remote sandbox is provisioned via ``environment={'type': 'remote'}``;
23+
the environment id is recovered from prior events so multi-turn conversations
24+
reuse the same sandbox.
25+
26+
Run with ``adk web`` / ``adk run contributing/samples/managed_agent/basic``. See
27+
the README for the required environment / auth setup.
28+
"""
29+
30+
import os
31+
32+
from google.adk.agents import ManagedAgent
33+
from google.adk.tools import google_search
34+
35+
# The Managed Agent id served by the Managed Agents API. Override with the
36+
# MANAGED_AGENT_ID environment variable if your project has access to a
37+
# different agent.
38+
_DEFAULT_AGENT_ID = 'antigravity-preview-05-2026'
39+
40+
root_agent = ManagedAgent(
41+
name='managed_search_agent',
42+
agent_id=os.environ.get('MANAGED_AGENT_ID', _DEFAULT_AGENT_ID),
43+
# Provision a remote sandbox for the agent. The environment id is recovered
44+
# from prior events, so follow-up turns reuse the same sandbox.
45+
environment={'type': 'remote'},
46+
# Only server-side tools are supported today. google_search is an ADK
47+
# built-in tool that executes on the server.
48+
tools=[google_search],
49+
)

0 commit comments

Comments
 (0)