Skip to content

Commit a645580

Browse files
google-genai-botcopybara-github
authored andcommitted
ADK changes
PiperOrigin-RevId: 804937691
1 parent 78eea1a commit a645580

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/google/adk/evaluation/local_eval_service.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,19 @@ def __init__(
6868
self,
6969
root_agent: BaseAgent,
7070
eval_sets_manager: EvalSetsManager,
71-
metric_evaluator_registry: MetricEvaluatorRegistry = DEFAULT_METRIC_EVALUATOR_REGISTRY,
72-
session_service: BaseSessionService = InMemorySessionService(),
73-
artifact_service: BaseArtifactService = InMemoryArtifactService(),
71+
metric_evaluator_registry: Optional[MetricEvaluatorRegistry] = None,
72+
session_service: Optional[BaseSessionService] = None,
73+
artifact_service: Optional[BaseArtifactService] = None,
7474
eval_set_results_manager: Optional[EvalSetResultsManager] = None,
7575
session_id_supplier: Callable[[], str] = _get_session_id,
7676
):
7777
self._root_agent = root_agent
7878
self._eval_sets_manager = eval_sets_manager
79+
metric_evaluator_registry = (
80+
metric_evaluator_registry or DEFAULT_METRIC_EVALUATOR_REGISTRY
81+
)
82+
session_service = session_service or InMemorySessionService()
83+
artifact_service = artifact_service or InMemoryArtifactService()
7984
self._metric_evaluator_registry = metric_evaluator_registry
8085
self._session_service = session_service
8186
self._artifact_service = artifact_service

src/google/adk/runners.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def run(
188188
user_id: str,
189189
session_id: str,
190190
new_message: types.Content,
191-
run_config: RunConfig = RunConfig(),
191+
run_config: Optional[RunConfig] = None,
192192
) -> Generator[Event, None, None]:
193193
"""Runs the agent.
194194
@@ -205,6 +205,7 @@ def run(
205205
Yields:
206206
The events generated by the agent.
207207
"""
208+
run_config = run_config or RunConfig()
208209
event_queue = queue.Queue()
209210

210211
async def _invoke_run_async():
@@ -248,7 +249,7 @@ async def run_async(
248249
session_id: str,
249250
new_message: types.Content,
250251
state_delta: Optional[dict[str, Any]] = None,
251-
run_config: RunConfig = RunConfig(),
252+
run_config: Optional[RunConfig] = None,
252253
) -> AsyncGenerator[Event, None]:
253254
"""Main entry method to run the agent in this runner.
254255
@@ -261,6 +262,7 @@ async def run_async(
261262
Yields:
262263
The events generated by the agent.
263264
"""
265+
run_config = run_config or RunConfig()
264266

265267
async def _run_with_trace(
266268
new_message: types.Content,
@@ -426,7 +428,7 @@ async def run_live(
426428
user_id: Optional[str] = None,
427429
session_id: Optional[str] = None,
428430
live_request_queue: LiveRequestQueue,
429-
run_config: RunConfig = RunConfig(),
431+
run_config: Optional[RunConfig] = None,
430432
session: Optional[Session] = None,
431433
) -> AsyncGenerator[Event, None]:
432434
"""Runs the agent in live mode (experimental feature).
@@ -452,6 +454,7 @@ async def run_live(
452454
.. NOTE::
453455
Either `session` or both `user_id` and `session_id` must be provided.
454456
"""
457+
run_config = run_config or RunConfig()
455458
if session is None and (user_id is None or session_id is None):
456459
raise ValueError(
457460
'Either session or user_id and session_id must be provided.'
@@ -601,7 +604,7 @@ def _new_invocation_context(
601604
*,
602605
new_message: Optional[types.Content] = None,
603606
live_request_queue: Optional[LiveRequestQueue] = None,
604-
run_config: RunConfig = RunConfig(),
607+
run_config: Optional[RunConfig] = None,
605608
) -> InvocationContext:
606609
"""Creates a new invocation context.
607610
@@ -614,6 +617,7 @@ def _new_invocation_context(
614617
Returns:
615618
The new invocation context.
616619
"""
620+
run_config = run_config or RunConfig()
617621
invocation_id = new_invocation_context_id()
618622

619623
if run_config.support_cfc and isinstance(self.agent, LlmAgent):
@@ -645,9 +649,10 @@ def _new_invocation_context_for_live(
645649
session: Session,
646650
*,
647651
live_request_queue: Optional[LiveRequestQueue] = None,
648-
run_config: RunConfig = RunConfig(),
652+
run_config: Optional[RunConfig] = None,
649653
) -> InvocationContext:
650654
"""Creates a new invocation context for live multi-agent."""
655+
run_config = run_config or RunConfig()
651656

652657
# For live multi-agent, we need model's text transcription as context for
653658
# next agent.

tests/unittests/cli/test_fast_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import tempfile
2222
import time
2323
from typing import Any
24+
from typing import Optional
2425
from unittest.mock import MagicMock
2526
from unittest.mock import patch
2627

@@ -120,8 +121,9 @@ async def dummy_run_async(
120121
session_id,
121122
new_message,
122123
state_delta=None,
123-
run_config: RunConfig = RunConfig(),
124+
run_config: Optional[RunConfig] = None,
124125
):
126+
run_config = run_config or RunConfig()
125127
yield _event_1()
126128
await asyncio.sleep(0)
127129

0 commit comments

Comments
 (0)