Skip to content

Commit aacd664

Browse files
authored
Merge branch 'main' into fix/input-schema-non-ascii
2 parents e2b395b + 757ef22 commit aacd664

264 files changed

Lines changed: 13438 additions & 9243 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.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "2.3.0"
2+
".": "2.4.0"
33
}

‎.github/release-please-config.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@
5757
]
5858
}
5959
},
60-
"last-release-sha": "0cb4c814928f579bfbac9b9e1f95669e4304e089"
60+
"last-release-sha": "44d747ed5eaf543b5b8d22e0088f8a7c7eeee846"
6161
}

‎.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: |

‎CHANGELOG.md‎

Lines changed: 180 additions & 0 deletions
Large diffs are not rendered by default.

‎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

0 commit comments

Comments
 (0)