From 54f0bb83264d566d7e2da443b9f4d4d9476d1be7 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Wed, 30 Jul 2025 21:12:02 -0400 Subject: [PATCH] session_args become runner_args --- .../runner-examples/01-all-transport-bot.py | 18 ++++---- .../01-all-transport-factory-bot.py | 4 +- .../runner-examples/02-two-transport-bot.py | 12 ++--- .../03-single-transport-bot.py | 4 +- src/pipecat/runner/run.py | 44 +++++++++---------- src/pipecat/runner/utils.py | 30 ++++++------- 6 files changed, 56 insertions(+), 56 deletions(-) diff --git a/examples/runner-examples/01-all-transport-bot.py b/examples/runner-examples/01-all-transport-bot.py index c7d4a07dc..2a82c210b 100644 --- a/examples/runner-examples/01-all-transport-bot.py +++ b/examples/runner-examples/01-all-transport-bot.py @@ -101,11 +101,11 @@ async def run_bot(transport): async def bot( - session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments | WebSocketRunnerArguments, + runner_args: DailyRunnerArguments | SmallWebRTCRunnerArguments | WebSocketRunnerArguments, ): """Main bot entry point compatible with Pipecat Cloud.""" - if isinstance(session_args, DailyRunnerArguments): + if isinstance(runner_args, DailyRunnerArguments): from pipecat.transports.services.daily import DailyParams, DailyTransport if os.environ.get("ENV") != "local": @@ -116,8 +116,8 @@ async def bot( krisp_filter = None transport = DailyTransport( - session_args.room_url, - session_args.token, + runner_args.room_url, + runner_args.token, "Pipecat Bot", params=DailyParams( audio_in_enabled=True, @@ -127,7 +127,7 @@ async def bot( ), ) - elif isinstance(session_args, SmallWebRTCRunnerArguments): + elif isinstance(runner_args, SmallWebRTCRunnerArguments): from pipecat.transports.base_transport import TransportParams from pipecat.transports.network.small_webrtc import SmallWebRTCTransport @@ -137,14 +137,14 @@ async def bot( audio_out_enabled=True, vad_analyzer=SileroVADAnalyzer(), ), - webrtc_connection=session_args.webrtc_connection, + webrtc_connection=runner_args.webrtc_connection, ) - elif isinstance(session_args, WebSocketRunnerArguments): + elif isinstance(runner_args, WebSocketRunnerArguments): # Use the utility to parse WebSocket data from pipecat.runner.utils import parse_telephony_websocket - transport_type, call_data = await parse_telephony_websocket(session_args.websocket) + transport_type, call_data = await parse_telephony_websocket(runner_args.websocket) logger.info(f"Auto-detected transport: {transport_type}") # Create transport based on detected type @@ -190,7 +190,7 @@ async def bot( ) transport = FastAPIWebsocketTransport( - websocket=session_args.websocket, + websocket=runner_args.websocket, params=FastAPIWebsocketParams( audio_in_enabled=True, audio_out_enabled=True, diff --git a/examples/runner-examples/01-all-transport-factory-bot.py b/examples/runner-examples/01-all-transport-factory-bot.py index 859d92683..b9f0db01a 100644 --- a/examples/runner-examples/01-all-transport-factory-bot.py +++ b/examples/runner-examples/01-all-transport-factory-bot.py @@ -137,10 +137,10 @@ async def run_bot(transport): async def bot( - session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments | WebSocketRunnerArguments, + runner_args: DailyRunnerArguments | SmallWebRTCRunnerArguments | WebSocketRunnerArguments, ): """Main bot entry point compatible with Pipecat Cloud.""" - transport = await create_transport(session_args, transport_params) + transport = await create_transport(runner_args, transport_params) await run_bot(transport) diff --git a/examples/runner-examples/02-two-transport-bot.py b/examples/runner-examples/02-two-transport-bot.py index 7103f1bee..308aec1a4 100644 --- a/examples/runner-examples/02-two-transport-bot.py +++ b/examples/runner-examples/02-two-transport-bot.py @@ -92,10 +92,10 @@ async def run_bot(transport): await runner.run(task) -async def bot(session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments): +async def bot(runner_args: DailyRunnerArguments | SmallWebRTCRunnerArguments): """Main bot entry point compatible with Pipecat Cloud.""" - if isinstance(session_args, DailyRunnerArguments): + if isinstance(runner_args, DailyRunnerArguments): from pipecat.transports.services.daily import DailyParams, DailyTransport if os.environ.get("ENV") != "local": @@ -106,8 +106,8 @@ async def bot(session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments): krisp_filter = None transport = DailyTransport( - session_args.room_url, - session_args.token, + runner_args.room_url, + runner_args.token, "Pipecat Bot", params=DailyParams( audio_in_enabled=True, @@ -117,7 +117,7 @@ async def bot(session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments): ), ) - elif isinstance(session_args, SmallWebRTCRunnerArguments): + elif isinstance(runner_args, SmallWebRTCRunnerArguments): from pipecat.transports.base_transport import TransportParams from pipecat.transports.network.small_webrtc import SmallWebRTCTransport @@ -127,7 +127,7 @@ async def bot(session_args: DailyRunnerArguments | SmallWebRTCRunnerArguments): audio_out_enabled=True, vad_analyzer=SileroVADAnalyzer(), ), - webrtc_connection=session_args.webrtc_connection, + webrtc_connection=runner_args.webrtc_connection, ) await run_bot(transport) diff --git a/examples/runner-examples/03-single-transport-bot.py b/examples/runner-examples/03-single-transport-bot.py index 84dfadba8..dedfdce9c 100644 --- a/examples/runner-examples/03-single-transport-bot.py +++ b/examples/runner-examples/03-single-transport-bot.py @@ -91,7 +91,7 @@ async def run_bot(transport): await runner.run(task) -async def bot(session_args: SmallWebRTCRunnerArguments): +async def bot(runner_args: SmallWebRTCRunnerArguments): """Main bot entry point compatible with Pipecat Cloud.""" transport = SmallWebRTCTransport( @@ -100,7 +100,7 @@ async def bot(session_args: SmallWebRTCRunnerArguments): audio_out_enabled=True, vad_analyzer=SileroVADAnalyzer(), ), - webrtc_connection=session_args.webrtc_connection, + webrtc_connection=runner_args.webrtc_connection, ) await run_bot(transport) diff --git a/src/pipecat/runner/run.py b/src/pipecat/runner/run.py index 068c57b3e..453c55996 100644 --- a/src/pipecat/runner/run.py +++ b/src/pipecat/runner/run.py @@ -15,16 +15,16 @@ Install with:: pip install pipecat-ai[runner] -All bots must implement a `bot(session_args)` async function as the entry point. +All bots must implement a `bot(runner_args)` async function as the entry point. The server automatically discovers and executes this function when connections are established. Single transport example:: - async def bot(session_args: DailyRunnerArguments): + async def bot(runner_args: DailyRunnerArguments): transport = DailyTransport( - session_args.room_url, - session_args.token, + runner_args.room_url, + runner_args.token, "Bot", DailyParams(...) ) @@ -37,14 +37,14 @@ Single transport example:: Multiple transport example:: - async def bot(session_args): + async def bot(runner_args): # Type-safe transport detection - if isinstance(session_args, DailyRunnerArguments): - transport = setup_daily_transport(session_args) # Your application code - elif isinstance(session_args, SmallWebRTCRunnerArguments): - transport = setup_webrtc_transport(session_args) # Your application code - elif isinstance(session_args, WebSocketRunnerArguments): - transport = setup_telephony_transport(session_args) # Your application code + if isinstance(runner_args, DailyRunnerArguments): + transport = setup_daily_transport(runner_args) # Your application code + elif isinstance(runner_args, SmallWebRTCRunnerArguments): + transport = setup_webrtc_transport(runner_args) # Your application code + elif isinstance(runner_args, WebSocketRunnerArguments): + transport = setup_telephony_transport(runner_args) # Your application code # Your bot implementation await run_pipeline(transport) @@ -144,9 +144,9 @@ async def _run_telephony_bot(websocket: WebSocket): bot_module = _get_bot_module() # Just pass the WebSocket - let the bot handle parsing - session_args = WebSocketRunnerArguments(websocket=websocket) + runner_args = WebSocketRunnerArguments(websocket=websocket) - await bot_module.bot(session_args) + await bot_module.bot(runner_args) def _create_server_app( @@ -221,8 +221,8 @@ def _setup_webrtc_routes(app: FastAPI, esp32_mode: bool = False, host: str = "lo pcs_map.pop(webrtc_connection.pc_id, None) bot_module = _get_bot_module() - session_args = SmallWebRTCRunnerArguments(webrtc_connection=pipecat_connection) - background_tasks.add_task(bot_module.bot, session_args) + runner_args = SmallWebRTCRunnerArguments(webrtc_connection=pipecat_connection) + background_tasks.add_task(bot_module.bot, runner_args) answer = pipecat_connection.get_answer() @@ -263,8 +263,8 @@ def _setup_daily_routes(app: FastAPI): # Start the bot in the background bot_module = _get_bot_module() - session_args = DailyRunnerArguments(room_url=room_url, token=token, body={}) - asyncio.create_task(bot_module.bot(session_args)) + runner_args = DailyRunnerArguments(room_url=room_url, token=token, body={}) + asyncio.create_task(bot_module.bot(runner_args)) return RedirectResponse(room_url) @app.post("/connect") @@ -281,8 +281,8 @@ def _setup_daily_routes(app: FastAPI): # Start the bot in the background bot_module = _get_bot_module() - session_args = DailyRunnerArguments(room_url=room_url, token=token, body={}) - asyncio.create_task(bot_module.bot(session_args)) + runner_args = DailyRunnerArguments(room_url=room_url, token=token, body={}) + asyncio.create_task(bot_module.bot(runner_args)) return {"room_url": room_url, "token": token} @@ -345,7 +345,7 @@ async def _run_daily_direct(): async with aiohttp.ClientSession() as session: room_url, token = await configure(session) - session_args = DailyRunnerArguments(room_url=room_url, token=token, body={}) + runner_args = DailyRunnerArguments(room_url=room_url, token=token, body={}) # Get the bot module and run it directly bot_module = _get_bot_module() @@ -354,7 +354,7 @@ async def _run_daily_direct(): print(" (Direct connection - no web server needed)") print() - await bot_module.bot(session_args) + await bot_module.bot(runner_args) def main(): @@ -375,7 +375,7 @@ def main(): -d/--direct: Connect directly to Daily room (automatically sets transport to daily) -v/--verbose: Increase logging verbosity - The bot file must contain a `bot(session_args)` function as the entry point. + The bot file must contain a `bot(runner_args)` function as the entry point. """ parser = argparse.ArgumentParser(description="Pipecat Development Runner") parser.add_argument("--host", type=str, default="localhost", help="Host address") diff --git a/src/pipecat/runner/utils.py b/src/pipecat/runner/utils.py index cd0781f78..e6cb0dc60 100644 --- a/src/pipecat/runner/utils.py +++ b/src/pipecat/runner/utils.py @@ -389,15 +389,15 @@ async def _create_telephony_transport( async def create_transport( - session_args: Any, transport_params: Dict[str, Callable] + runner_args: Any, transport_params: Dict[str, Callable] ) -> BaseTransport: - """Create a transport from session arguments using factory functions. + """Create a transport from runner arguments using factory functions. This function uses the clean transport_params factory pattern where users define a dictionary mapping transport names to parameter factory functions. Args: - session_args: Session arguments from the runner. + runner_args: Arguments from the runner. transport_params: Dict mapping transport names to parameter factory functions. Keys should be: "daily", "webrtc", "twilio", "telnyx", "plivo" Values should be functions that return transport parameters when called. @@ -406,7 +406,7 @@ async def create_transport( Configured transport instance. Raises: - ValueError: If transport key is missing from transport_params or session args type is unsupported. + ValueError: If transport key is missing from transport_params or runner_args type is unsupported. ImportError: If required dependencies are not installed. Example:: @@ -442,40 +442,40 @@ async def create_transport( ), } - transport = await create_transport(session_args, transport_params) + transport = await create_transport(runner_args, transport_params) """ - # Create transport based on session args type - if isinstance(session_args, DailyRunnerArguments): + # Create transport based on runner args type + if isinstance(runner_args, DailyRunnerArguments): params = _get_transport_params("daily", transport_params) from pipecat.transports.services.daily import DailyTransport return DailyTransport( - session_args.room_url, - session_args.token, + runner_args.room_url, + runner_args.token, "Pipecat Bot", params=params, ) - elif isinstance(session_args, SmallWebRTCRunnerArguments): + elif isinstance(runner_args, SmallWebRTCRunnerArguments): params = _get_transport_params("webrtc", transport_params) from pipecat.transports.network.small_webrtc import SmallWebRTCTransport return SmallWebRTCTransport( params=params, - webrtc_connection=session_args.webrtc_connection, + webrtc_connection=runner_args.webrtc_connection, ) - elif isinstance(session_args, WebSocketRunnerArguments): + elif isinstance(runner_args, WebSocketRunnerArguments): # Parse once to determine the provider and get data - transport_type, call_data = await parse_telephony_websocket(session_args.websocket) + transport_type, call_data = await parse_telephony_websocket(runner_args.websocket) params = _get_transport_params(transport_type, transport_params) # Create telephony transport with pre-parsed data return await _create_telephony_transport( - session_args.websocket, params, transport_type, call_data + runner_args.websocket, params, transport_type, call_data ) else: - raise ValueError(f"Unsupported session arguments type: {type(session_args)}") + raise ValueError(f"Unsupported runner arguments type: {type(runner_args)}")