mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-24 17:38:41 -06:00
feat: Align run_live interface with run_async etc
PiperOrigin-RevId: 758289318
This commit is contained in:
parent
08c9cf86c3
commit
c4d5e3b298
@ -19,6 +19,7 @@ import logging
|
|||||||
import queue
|
import queue
|
||||||
import threading
|
import threading
|
||||||
from typing import AsyncGenerator, Generator, Optional
|
from typing import AsyncGenerator, Generator, Optional
|
||||||
|
import warnings
|
||||||
|
|
||||||
from deprecated import deprecated
|
from deprecated import deprecated
|
||||||
from google.genai import types
|
from google.genai import types
|
||||||
@ -244,25 +245,52 @@ class Runner:
|
|||||||
async def run_live(
|
async def run_live(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
session: Session,
|
user_id: Optional[str] = None,
|
||||||
|
session_id: Optional[str] = None,
|
||||||
live_request_queue: LiveRequestQueue,
|
live_request_queue: LiveRequestQueue,
|
||||||
run_config: RunConfig = RunConfig(),
|
run_config: RunConfig = RunConfig(),
|
||||||
|
session: Optional[Session] = None,
|
||||||
) -> AsyncGenerator[Event, None]:
|
) -> AsyncGenerator[Event, None]:
|
||||||
"""Runs the agent in live mode (experimental feature).
|
"""Runs the agent in live mode (experimental feature).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
session: The session to use.
|
session: The session to use. This parameter is deprecated, please use
|
||||||
|
`user_id` and `session_id` instead.
|
||||||
|
user_id: The user ID for the session. Required if `session` is None.
|
||||||
|
session_id: The session ID for the session. Required if `session` is
|
||||||
|
None.
|
||||||
live_request_queue: The queue for live requests.
|
live_request_queue: The queue for live requests.
|
||||||
run_config: The run config for the agent.
|
run_config: The run config for the agent.
|
||||||
|
|
||||||
Yields:
|
Yields:
|
||||||
The events generated by the agent.
|
AsyncGenerator[Event, None]: An asynchronous generator that yields
|
||||||
|
`Event`
|
||||||
|
objects as they are produced by the agent during its live execution.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
This feature is **experimental** and its API or behavior may change
|
This feature is **experimental** and its API or behavior may change
|
||||||
in future releases.
|
in future releases.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
Either `session` or both `user_id` and `session_id` must be provided.
|
||||||
"""
|
"""
|
||||||
# TODO: right now, only works for a single audio agent without FC.
|
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.'
|
||||||
|
)
|
||||||
|
if session is not None:
|
||||||
|
warnings.warn(
|
||||||
|
'The `session` parameter is deprecated. Please use `user_id` and'
|
||||||
|
' `session_id` instead.',
|
||||||
|
DeprecationWarning,
|
||||||
|
stacklevel=2,
|
||||||
|
)
|
||||||
|
if not session:
|
||||||
|
session = self.session_service.get_session(
|
||||||
|
app_name=self.app_name, user_id=user_id, session_id=session_id
|
||||||
|
)
|
||||||
|
if not session:
|
||||||
|
raise ValueError(f'Session not found: {session_id}')
|
||||||
invocation_context = self._new_invocation_context_for_live(
|
invocation_context = self._new_invocation_context_for_live(
|
||||||
session,
|
session,
|
||||||
live_request_queue=live_request_queue,
|
live_request_queue=live_request_queue,
|
||||||
|
Loading…
Reference in New Issue
Block a user