Skip to content

Commit 32a1160

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-thought-signature-pruning
2 parents c3de34f + 84bbb35 commit 32a1160

7 files changed

Lines changed: 3046 additions & 348 deletions

File tree

src/google/adk/agents/parallel_agent.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import annotations
1818

1919
import asyncio
20+
import logging
2021
import sys
2122
from typing import AsyncGenerator
2223
from typing import ClassVar
@@ -32,6 +33,8 @@
3233
from .invocation_context import InvocationContext
3334
from .parallel_agent_config import ParallelAgentConfig
3435

36+
logger = logging.getLogger('google_adk.' + __name__)
37+
3538

3639
def _create_branch_ctx_for_sub_agent(
3740
agent: BaseAgent,
@@ -65,9 +68,15 @@ async def process_an_agent(events_for_one_agent):
6568
await queue.put((event, resume_signal))
6669
# Wait for upstream to consume event before generating new events.
6770
await resume_signal.wait()
71+
except asyncio.CancelledError:
72+
logger.info('Agent run cancelled.')
73+
raise
6874
finally:
6975
# Mark agent as finished.
70-
await queue.put((sentinel, None))
76+
try:
77+
await queue.put((sentinel, None))
78+
except Exception as e:
79+
logger.warning('Failed to put sentinel on queue: %s', e)
7180

7281
async with asyncio.TaskGroup() as tg:
7382
for events_for_one_agent in agent_runs:
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
"""Opt-in for the ADK telemetry schema version.
16+
17+
``ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN`` lets a deployment pin which version of
18+
the ADK telemetry format (span names, span/log attributes, metrics) it emits.
19+
20+
Why this exists:
21+
22+
* **Staged migration.** Telemetry format changes are breaking for anyone who
23+
built dashboards/alerts on the previous shape. The version env lets users
24+
fall back to the legacy format if they rely on it, and migrate on their own
25+
schedule.
26+
* **Fast iteration on managed services.** GCP-managed runtimes (e.g. Agent
27+
Runtime / Vertex Agent Engine) can pin themselves to the latest version and
28+
iterate quickly, decoupled from the broader user base.
29+
* **Eventually removable.** Ideally this knob is phased out once ADK is
30+
({almost,} fully) OTel semconv compliant, after which we no longer expect
31+
breaking telemetry changes.
32+
33+
Default resolution:
34+
35+
* ``2`` on Agent Engine, detected via the presence of the
36+
``GOOGLE_CLOUD_AGENT_ENGINE_ID`` env var.
37+
* ``1`` everywhere else.
38+
39+
Migration plan (steps land incrementally; this comment should be kept in sync
40+
as each one ships):
41+
42+
1. The ``invocation`` span is updated to the ``invoke_workflow`` span.
43+
2. The ``call_llm`` span is removed.
44+
3. The ``execute_tool`` content-bearing attributes become OTel semconv aligned.
45+
4. The experimental OTel GenAI semconv becomes the default in both
46+
``opentelemetry-instrumentation-google-genai`` and ADK's native
47+
instrumentation.
48+
5. ``2`` becomes the global default (this knob flips).
49+
6. After ~6 months, the env var is phased out entirely, along with support for
50+
the LEGACY schema.
51+
"""
52+
53+
from __future__ import annotations
54+
55+
import os
56+
57+
# Env var users set to pin the ADK telemetry schema version ("1" or "2").
58+
ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN = "ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN"
59+
60+
# Presence of this env var indicates the process runs on Vertex Agent Engine.
61+
GOOGLE_CLOUD_AGENT_ENGINE_ID = "GOOGLE_CLOUD_AGENT_ENGINE_ID"
62+
63+
# Legacy telemetry format: top-level ``invocation`` span, no entrypoint
64+
# ``invoke_workflow`` span/metric.
65+
SCHEMA_VERSION_LEGACY = 1
66+
67+
# OTel-semconv-aligned telemetry format: the ``invocation`` span is replaced by
68+
# an entrypoint ``invoke_workflow {entrypoint}`` span + duration metric.
69+
SCHEMA_VERSION_SEMCONV_ALIGNED = 2
70+
71+
72+
def resolve_schema_version() -> int:
73+
"""Resolves the active ADK telemetry schema version.
74+
75+
Precedence: ``ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN`` (if set to a recognized
76+
value) > ``2`` on Agent Engine > ``1``.
77+
78+
Returns:
79+
Either :data:`SCHEMA_VERSION_LEGACY` or
80+
:data:`SCHEMA_VERSION_SEMCONV_ALIGNED`.
81+
"""
82+
opt_in = os.environ.get(ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN, "").strip()
83+
if opt_in == "1":
84+
return SCHEMA_VERSION_LEGACY
85+
if opt_in == "2":
86+
return SCHEMA_VERSION_SEMCONV_ALIGNED
87+
88+
# Unset/unrecognized: default to v2 on Agent Engine, v1 elsewhere.
89+
if os.environ.get(GOOGLE_CLOUD_AGENT_ENGINE_ID):
90+
return SCHEMA_VERSION_SEMCONV_ALIGNED
91+
return SCHEMA_VERSION_LEGACY

0 commit comments

Comments
 (0)