8000 feat: Align run_live interface with run_async etc · Syntax404-coder/adk-python@c4d5e3b · GitHub
[go: up one dir, main page]

Skip to content

Commit c4d5e3b

Browse files
hangfeicopybara-github
authored andcommitted
feat: Align run_live interface with run_async etc
PiperOrigin-RevId: 758289318
1 parent 08c9cf8 commit c4d5e3b

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/google/adk/runners.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import queue
2020
import threading
2121
from typing import AsyncGenerator, Generator, Optional
22+
import warnings
2223

2324
from deprecated import deprecated
2425
from google.genai import types
@@ -244,25 +245,52 @@ async def _append_new_message_to_session(
244245
async def run_live(
245246
self,
246247
*,
247-
session: Session,
248+
user_id: Optional[str] = None,
249+
session_id: Optional[str] = None,
248250
live_request_queue: LiveRequestQueue,
249251
run_config: RunConfig = RunConfig(),
252+
session: Optional[Session] = None,
250253
) -> AsyncGenerator[Event, None]:< 8000 /div>
251254
"""Runs the agent in live mode (experimental feature).
252255
253256
Args:
254-
session: The session to use.
257+
session: The session to use. This parameter is deprecated, please use
258+
`user_id` and `session_id` instead.
259+
user_id: The user ID for the session. Required if `session` is None.
260+
session_id: The session ID for the session. Required if `session` is
261+
None.
255262
live_request_queue: The queue for live requests.
256263
run_config: The run config for the agent.
257264
258265
Yields:
259-
The events generated by the agent.
266+
AsyncGenerator[Event, None]: An asynchronous generator that yields
267+
`Event`
268+
objects as they are produced by the agent during its live execution.
260269
261270
.. warning::
262271
This feature is **experimental** and its API or behavior may change
263272
in future releases.
273+
274+
.. note::
275+
Either `session` or both `user_id` and `session_id` must be provided.
264276
"""
265-
# TODO: right now, only works for a single audio agent without FC.
277+
if session is None and (user_id is None or session_id is None):
278+
raise ValueError(
279+
'Either session or user_id and session_id must be provided.'
280+
)
281+
if session is not None:
282+
warnings.warn(
283+
'The `session` parameter is deprecated. Please use `user_id` and'
284+
' `session_id` instead.',
285+
DeprecationWarning,
286+
stacklevel=2,
287+
)
288+
if not session:
289+
session = self.session_service.get_session(
290+
app_name=self.app_name, user_id=user_id, session_id=session_id
291+
)
292+
if not session:
293+
raise ValueError(f'Session not found: {session_id}')
266294
invocation_context = self._new_invocation_context_for_live(
267295
session,
268296
live_request_queue=live_request_queue,

0 commit comments

Comments
 (0)
0