Skip to content

Commit 830faf2

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-thought-signature-pruning
2 parents affda8e + 34b953e commit 830faf2

78 files changed

Lines changed: 4552 additions & 198 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release-update-adk-web.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
steps:
3838
- name: Checkout repository
3939
uses: actions/checkout@v6
40+
with:
41+
persist-credentials: false
4042

4143
- name: Fetch and unzip frontend assets
4244
run: |

contributing/samples/context_management/session_state_agent/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ async def after_agent_callback(callback_context: CallbackContext):
168168
name='root_agent',
169169
description='a verification agent.',
170170
instruction=(
171-
'Log all users query with `log_query` tool. Must always remind user you'
172-
' cannot answer second query because your setup.'
171+
'Reply to the user. Must always remind user you cannot answer a second'
172+
' query because your setup.'
173173
),
174174
model='gemini-3.5-flash',
175175
before_agent_callback=before_agent_callback,

contributing/samples/integrations/gepa/rater_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def __call__(self, messages: list[dict[str, Any]]) -> dict[str, Any]:
167167
Returns:
168168
A dictionary containing rating information including score.
169169
"""
170-
env = jinja2.Environment()
170+
env = jinja2.Environment(autoescape=True)
171171
env.globals['user_input'] = (
172172
messages[0].get('parts', [{}])[0].get('text', '') if messages else ''
173173
)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
import sys
15+
from unittest import mock
16+
17+
# Mock the retry module before importing rater_lib
18+
mock_retry_module = mock.MagicMock()
19+
20+
21+
def mock_retry_decorator(*args, **kwargs):
22+
def decorator(func):
23+
return func
24+
25+
return decorator
26+
27+
28+
mock_retry_module.retry = mock_retry_decorator
29+
sys.modules["retry"] = mock_retry_module
30+
31+
from gepa import rater_lib
32+
33+
34+
def test_rater_escapes_html_inputs_to_prevent_xss():
35+
"""Rater escapes HTML tags in user and model inputs to prevent XSS.
36+
37+
Setup: Mock genai.Client to return a dummy rating response.
38+
Act: Call Rater with messages containing HTML tags.
39+
Assert: Verify that the rendered prompt template contains escaped HTML.
40+
"""
41+
# Arrange
42+
with mock.patch("google.genai.Client") as mock_client_cls:
43+
mock_client = mock_client_cls.return_value
44+
mock_generate = mock_client.models.generate_content
45+
mock_generate.return_value.text = (
46+
"Property: The agent fulfilled the user's primary request.\n"
47+
"Evidence: mock evidence\n"
48+
"Rationale: mock rationale\n"
49+
"Verdict: yes"
50+
)
51+
52+
template_path = (
53+
"contributing/samples/integrations/gepa/rubric_validation_template.txt"
54+
)
55+
rater = rater_lib.Rater(
56+
tool_declarations="[]", validation_template_path=template_path
57+
)
58+
59+
messages = [
60+
{
61+
"role": "user",
62+
"parts": [{"text": "<script>alert('XSS')</script>"}],
63+
},
64+
{
65+
"role": "model",
66+
"parts": [{"text": "Hello <img src=x onerror=alert(1)>"}],
67+
},
68+
]
69+
70+
# Act
71+
rater(messages)
72+
73+
# Assert
74+
assert mock_generate.called
75+
call_args = mock_generate.call_args
76+
contents = call_args.kwargs["contents"]
77+
78+
assert "&lt;script&gt;alert(&#39;XSS&#39;)&lt;/script&gt;" in contents
79+
assert "Hello &lt;img src=x onerror=alert(1)&gt;" in contents

contributing/samples/integrations/gepa/rubric_validation_template.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ Verdict: no
155155
</available_tools>
156156

157157
<main_prompt>
158-
{{user_input}}
158+
{{user_input|e}}
159159
</main_prompt>
160160
</user_prompt>
161161

162162
<responses>
163-
{{model_response}}
163+
{{model_response|e}}
164164
</responses>
165165

166166
<properties>
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+
)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Managed Agent - Code Execution
2+
3+
## Overview
4+
5+
This sample runs a `ManagedAgent` configured with the built-in **code execution**
6+
tool so it can write and run code server-side to compute answers.
7+
8+
Unlike a regular `LlmAgent` (which enables code execution via
9+
`code_executor=BuiltInCodeExecutor()`), `ManagedAgent` has no `code_executor`
10+
field. Instead you pass the raw built-in tool config
11+
`types.Tool(code_execution=types.ToolCodeExecution())` in `tools` -- the same
12+
config `BuiltInCodeExecutor` produces under the hood. This makes the sample a
13+
demonstration of the raw `types.Tool` server-side tool path.
14+
15+
## Sample Inputs
16+
17+
- `What is the sum of the first 50 prime numbers? Use code to compute it.`
18+
19+
The model writes and runs code server-side; the answer (5117) comes from the
20+
executed code rather than the model guessing.
21+
22+
- `Now do the same for the first 100 primes.`
23+
24+
A follow-up turn that reuses the recovered remote sandbox and the previous
25+
interaction (answer: 24133), demonstrating multi-turn chaining.
26+
27+
## Graph
28+
29+
```mermaid
30+
graph LR
31+
User -->|message| ManagedAgent
32+
ManagedAgent -->|interactions.create| ManagedAgentsAPI
33+
ManagedAgentsAPI -->|server-side code execution| ManagedAgentsAPI
34+
ManagedAgentsAPI -->|streamed events| ManagedAgent
35+
ManagedAgent -->|answer| User
36+
```
37+
38+
## How To
39+
40+
- **Create the agent**: instantiate `ManagedAgent` with an `agent_id`, an
41+
`environment` spec, and
42+
`tools=[types.Tool(code_execution=types.ToolCodeExecution())]`. No `model` is
43+
set -- the model is part of the managed agent on the server.
44+
- **Enable code execution**: `ManagedAgent` has no `code_executor` field, so the
45+
raw `types.Tool(code_execution=...)` config is passed in `tools`. The
46+
interactions converter turns it into the server-side `code_execution` tool.
47+
- **Provision a sandbox**: `environment={'type': 'remote'}` requests a fresh
48+
remote sandbox. The resulting environment id is stored on emitted events, so
49+
subsequent turns automatically recover and reuse it.
50+
- **Multi-turn chaining**: the agent recovers the `previous_interaction_id` from
51+
the session events, so follow-up turns continue the same interaction without
52+
any extra wiring.
53+
- **Drive it**: a `ManagedAgent` is a `BaseAgent`, so a standard `Runner` runs
54+
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

0 commit comments

Comments
 (0)