|
19 | 19 | import queue
|
20 | 20 | import threading
|
21 | 21 | from typing import AsyncGenerator, Generator, Optional
|
| 22 | +import warnings |
22 | 23 |
|
23 | 24 | from deprecated import deprecated
|
24 | 25 | from google.genai import types
|
@@ -244,25 +245,52 @@ async def _append_new_message_to_session(
|
244 | 245 | async def run_live(
|
245 | 246 | self,
|
246 | 247 | *,
|
247 |
| - session: Session, |
| 248 | + user_id: Optional[str] = None, |
| 249 | + session_id: Optional[str] = None, |
248 | 250 | live_request_queue: LiveRequestQueue,
|
249 | 251 | run_config: RunConfig = RunConfig(),
|
| 252 | + session: Optional[Session] = None, |
250 | 253 | ) -> AsyncGenerator[Event, None]:<
8000
/div>
|
251 | 254 | """Runs the agent in live mode (experimental feature).
|
252 | 255 |
|
253 | 256 | 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. |
255 | 262 | live_request_queue: The queue for live requests.
|
256 | 263 | run_config: The run config for the agent.
|
257 | 264 |
|
258 | 265 | 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. |
260 | 269 |
|
261 | 270 | .. warning::
|
262 | 271 | This feature is **experimental** and its API or behavior may change
|
263 | 272 | in future releases.
|
| 273 | +
|
| 274 | + .. note:: |
| 275 | + Either `session` or both `user_id` and `session_id` must be provided. |
264 | 276 | """
|
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}') |
266 | 294 | invocation_context = self._new_invocation_context_for_live(
|
267 | 295 | session,
|
268 | 296 | live_request_queue=live_request_queue,
|
|
0 commit comments