diff --git a/src/google/adk/evaluation/local_eval_service.py b/src/google/adk/evaluation/local_eval_service.py index f443bb70..fa50f70d 100644 --- a/src/google/adk/evaluation/local_eval_service.py +++ b/src/google/adk/evaluation/local_eval_service.py @@ -68,14 +68,19 @@ class LocalEvalService(BaseEvalService): self, root_agent: BaseAgent, eval_sets_manager: EvalSetsManager, - metric_evaluator_registry: MetricEvaluatorRegistry = DEFAULT_METRIC_EVALUATOR_REGISTRY, - session_service: BaseSessionService = InMemorySessionService(), - artifact_service: BaseArtifactService = InMemoryArtifactService(), + metric_evaluator_registry: Optional[MetricEvaluatorRegistry] = None, + session_service: Optional[BaseSessionService] = None, + artifact_service: Optional[BaseArtifactService] = None, eval_set_results_manager: Optional[EvalSetResultsManager] = None, session_id_supplier: Callable[[], str] = _get_session_id, ): self._root_agent = root_agent self._eval_sets_manager = eval_sets_manager + metric_evaluator_registry = ( + metric_evaluator_registry or DEFAULT_METRIC_EVALUATOR_REGISTRY + ) + session_service = session_service or InMemorySessionService() + artifact_service = artifact_service or InMemoryArtifactService() self._metric_evaluator_registry = metric_evaluator_registry self._session_service = session_service self._artifact_service = artifact_service diff --git a/src/google/adk/runners.py b/src/google/adk/runners.py index f0f92047..d18127b1 100644 --- a/src/google/adk/runners.py +++ b/src/google/adk/runners.py @@ -188,7 +188,7 @@ class Runner: user_id: str, session_id: str, new_message: types.Content, - run_config: RunConfig = RunConfig(), + run_config: Optional[RunConfig] = None, ) -> Generator[Event, None, None]: """Runs the agent. @@ -205,6 +205,7 @@ class Runner: Yields: The events generated by the agent. """ + run_config = run_config or RunConfig() event_queue = queue.Queue() async def _invoke_run_async(): @@ -248,7 +249,7 @@ class Runner: session_id: str, new_message: types.Content, state_delta: Optional[dict[str, Any]] = None, - run_config: RunConfig = RunConfig(), + run_config: Optional[RunConfig] = None, ) -> AsyncGenerator[Event, None]: """Main entry method to run the agent in this runner. @@ -261,6 +262,7 @@ class Runner: Yields: The events generated by the agent. """ + run_config = run_config or RunConfig() async def _run_with_trace( new_message: types.Content, @@ -426,7 +428,7 @@ class Runner: user_id: Optional[str] = None, session_id: Optional[str] = None, live_request_queue: LiveRequestQueue, - run_config: RunConfig = RunConfig(), + run_config: Optional[RunConfig] = None, session: Optional[Session] = None, ) -> AsyncGenerator[Event, None]: """Runs the agent in live mode (experimental feature). @@ -452,6 +454,7 @@ class Runner: .. NOTE:: Either `session` or both `user_id` and `session_id` must be provided. """ + run_config = run_config or RunConfig() if session is None and (user_id is None or session_id is None): raise ValueError( 'Either session or user_id and session_id must be provided.' @@ -601,7 +604,7 @@ class Runner: *, new_message: Optional[types.Content] = None, live_request_queue: Optional[LiveRequestQueue] = None, - run_config: RunConfig = RunConfig(), + run_config: Optional[RunConfig] = None, ) -> InvocationContext: """Creates a new invocation context. @@ -614,6 +617,7 @@ class Runner: Returns: The new invocation context. """ + run_config = run_config or RunConfig() invocation_id = new_invocation_context_id() if run_config.support_cfc and isinstance(self.agent, LlmAgent): @@ -645,9 +649,10 @@ class Runner: session: Session, *, live_request_queue: Optional[LiveRequestQueue] = None, - run_config: RunConfig = RunConfig(), + run_config: Optional[RunConfig] = None, ) -> InvocationContext: """Creates a new invocation context for live multi-agent.""" + run_config = run_config or RunConfig() # For live multi-agent, we need model's text transcription as context for # next agent. diff --git a/tests/unittests/cli/test_fast_api.py b/tests/unittests/cli/test_fast_api.py index b05bf3c4..d0d84cac 100755 --- a/tests/unittests/cli/test_fast_api.py +++ b/tests/unittests/cli/test_fast_api.py @@ -21,6 +21,7 @@ import sys import tempfile import time from typing import Any +from typing import Optional from unittest.mock import MagicMock from unittest.mock import patch @@ -120,8 +121,9 @@ async def dummy_run_async( session_id, new_message, state_delta=None, - run_config: RunConfig = RunConfig(), + run_config: Optional[RunConfig] = None, ): + run_config = run_config or RunConfig() yield _event_1() await asyncio.sleep(0)