Skip to content

Commit be08e06

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/openapi-tool-httpx-client-factory
2 parents 11f22b8 + af8bfe0 commit be08e06

7 files changed

Lines changed: 48 additions & 11 deletions

File tree

.github/workflows/check-file-contents.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111
# 1. Identify files containing any googleapis.com URL.
112112
set +e
113113
FILES_WITH_ENDPOINTS=$(grep -lE 'https?://[a-zA-Z0-9.-]+\.googleapis\.com' $CHANGED_FILES)
114-
114+
115115
# 2. From those, identify files that are MISSING the required mTLS version.
116116
if [ -n "$FILES_WITH_ENDPOINTS" ]; then
117117
FILES_MISSING_MTLS=$(grep -L '.mtls.googleapis.com' $FILES_WITH_ENDPOINTS)

contributing/samples/integrations/data_agent/agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
],
8080
)
8181

82+
8283
# NOTE: The generate_chart tool requires 'altair' and 'vl-convert-python' to be
8384
# installed in your environment. You can install them using:
8485
# pip install altair vl-convert-python

src/google/adk/cli/utils/evals.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from __future__ import annotations
1616

1717
import os
18-
from typing import Any, TYPE_CHECKING
18+
from typing import Any
19+
from typing import TYPE_CHECKING
1920

2021
from pydantic import alias_generators
2122
from pydantic import BaseModel
@@ -77,9 +78,9 @@ def create_gcs_eval_managers_from_uri(
7778
from ...evaluation.gcs_eval_sets_manager import GcsEvalSetsManager
7879
except ImportError as e:
7980
raise RuntimeError(
80-
'GCS evaluation managers require Google Cloud optional dependencies.\n'
81-
'Please install them using: pip install google-adk[gcp]\n'
82-
'Or: pip install google-cloud-storage>=2.18'
81+
'GCS evaluation managers require Google Cloud optional'
82+
' dependencies.\nPlease install them using: pip install'
83+
' google-adk[gcp]\nOr: pip install google-cloud-storage>=2.18'
8384
) from e
8485

8586
gcs_bucket = eval_storage_uri.split('://')[1]

src/google/adk/skills/_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ def _list_skills_in_gcs_dir(
411411
except ImportError as e:
412412
raise ImportError(
413413
"google-cloud-storage is required to list skills in GCS. Install it"
414-
" with `pip install google-cloud-storage` or `pip install google-adk[gcp]`."
414+
" with `pip install google-cloud-storage` or `pip install"
415+
" google-adk[gcp]`."
415416
) from e
416417

417418
client = storage.Client(project=project_id, credentials=credentials)
@@ -478,7 +479,8 @@ def _load_skill_from_gcs_dir(
478479
except ImportError as e:
479480
raise ImportError(
480481
"google-cloud-storage is required to load skills from GCS. Install it"
481-
" with `pip install google-cloud-storage` or `pip install google-adk[gcp]`."
482+
" with `pip install google-cloud-storage` or `pip install"
483+
" google-adk[gcp]`."
482484
) from e
483485

484486
client = storage.Client(project=project_id, credentials=credentials)

src/google/adk/telemetry/_instrumentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ async def record_agent_invocation(
114114
_record_agent_metrics(
115115
agent.name,
116116
elapsed_ms,
117-
ctx.user_content,
118-
ctx.session.events,
117+
getattr(ctx, "user_content", None),
118+
getattr(getattr(ctx, "session", None), "events", []),
119119
caught_error,
120120
)
121121

tests/unittests/skills/test__utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,5 +393,3 @@ def mock_import(name, globals=None, locals=None, fromlist=(), level=0):
393393
with mock.patch("builtins.__import__", mock_import):
394394
with pytest.raises(ImportError, match="google-cloud-storage is required"):
395395
_load_skill_from_gcs_dir("my-bucket", "skills/my-skill/")
396-
397-

tests/unittests/telemetry/test_instrumentation.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from google.adk.telemetry import _instrumentation
2121
from opentelemetry import trace
22+
import pytest
2223

2324

2425
def test_get_elapsed_ms_span_none():
@@ -80,3 +81,37 @@ def test_get_elapsed_ms_span_non_int_end():
8081
with mock.patch("time.monotonic", return_value=12.0):
8182
elapsed = _instrumentation._get_elapsed_ms(mock_span, start_time)
8283
assert elapsed == 2000.0
84+
85+
86+
@pytest.mark.asyncio
87+
async def test_record_agent_invocation_tolerates_minimal_context():
88+
"""Tolerates context-likes that lack user_content or session.
89+
90+
Test doubles, partial migrations, and external embedders can pass an
91+
InvocationContext-like object without `user_content` or with a `session`
92+
that has no `events` attribute. The telemetry path must not raise
93+
AttributeError on the metrics call in those cases.
94+
"""
95+
agent = mock.MagicMock()
96+
agent.name = "test_agent"
97+
# Bare object without `user_content` and without `session`.
98+
bare_ctx = object()
99+
100+
with (
101+
mock.patch.object(
102+
_instrumentation, "_record_agent_metrics"
103+
) as mock_record,
104+
mock.patch.object(_instrumentation, "tracing") as mock_tracing,
105+
):
106+
mock_tracing.tracer.start_as_current_span.return_value.__enter__.return_value = mock.MagicMock(
107+
spec=trace.Span
108+
)
109+
async with _instrumentation.record_agent_invocation(bare_ctx, agent):
110+
pass
111+
112+
mock_record.assert_called_once()
113+
call_args = mock_record.call_args
114+
# positional: (agent_name, elapsed_ms, user_content, events, caught_error)
115+
assert call_args.args[0] == "test_agent"
116+
assert call_args.args[2] is None # user_content default
117+
assert call_args.args[3] == [] # events default

0 commit comments

Comments
 (0)