diff --git a/examples/aws-agentcore/bot.py b/examples/aws-agentcore/bot.py index ddf6d2cef..0b8481144 100644 --- a/examples/aws-agentcore/bot.py +++ b/examples/aws-agentcore/bot.py @@ -29,7 +29,7 @@ from pipecat.services.deepgram.stt import DeepgramSTTService from pipecat.services.llm_service import FunctionCallParams from pipecat.services.openai.llm import OpenAILLMService from pipecat.transports.base_transport import BaseTransport, TransportParams -from pipecat.transports.daily.transport import DailyParams, DailyTransport +from pipecat.transports.daily.transport import DailyLogLevel, DailyParams, DailyTransport app = BedrockAgentCoreApp() @@ -82,19 +82,6 @@ transport_params = { async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): logger.info(f"Starting bot") - daily_transport: DailyTransport = transport - daily_transport._client._client.set_ice_config( - { - "iceServers": [ - { - "urls": ["turn:turn.cloudflare.com:3478?transport=tcp"], - "username": "YOUR_TURN_USERNAME", - "credential": "YOUR_TURN_CREDENTIAL", - }, - ] - } - ) - public_ip = await get_public_ip() if public_ip: logger.info(f"Public IP address: {public_ip}") @@ -218,6 +205,26 @@ async def agentcore_bot(payload, context): DailyRunnerArguments(room_url=room_url), transport_params, ) + if isinstance(transport, DailyTransport): + transport.set_log_level(DailyLogLevel.Info) + turn_username = os.getenv("TURN_USERNAME") + turn_credential = os.getenv("TURN_CREDENTIAL") + transport._client._client.set_ice_config( + { + "placement": "replace", + "iceServers": [ + { + "urls": [ + "turn:turn.cloudflare.com:80?transport=tcp", + "turns:turn.cloudflare.com:443?transport=tcp", + ], + "username": turn_username, + "credential": turn_credential, + }, + ], + } + ) + async for result in run_bot(transport, RunnerArguments()): yield result diff --git a/examples/aws-agentcore/bot_hellow.py b/examples/aws-agentcore/bot_hellow.py index 389d59a43..818551394 100644 --- a/examples/aws-agentcore/bot_hellow.py +++ b/examples/aws-agentcore/bot_hellow.py @@ -1,8 +1,12 @@ import asyncio +import os import socket import aioice from bedrock_agentcore import BedrockAgentCoreApp +from dotenv import load_dotenv + +load_dotenv(override=True) app = BedrockAgentCoreApp() @@ -79,45 +83,48 @@ def comprehensive_network_test(): # Test basic UDP connectivity results["udp_stun"] = test_udp() + turn_username = os.getenv("TURN_USERNAME") + turn_credential = os.getenv("TURN_CREDENTIAL") + # TURN test list turn_servers = [ ( "turn.cloudflare.com", # cleaned 3478, - "g0c069ee067cb5585f7a4799950312a355f2cb9c20e23d21bd1ecb1f93c1e8b0", - "d40a0992b4d08175af51f32f46a3732725a69045422f96b388420c98dd13ced3", + turn_username, + turn_credential, "udp", False, ), ( "turn.cloudflare.com", # cleaned 5349, - "g0c069ee067cb5585f7a4799950312a355f2cb9c20e23d21bd1ecb1f93c1e8b0", - "d40a0992b4d08175af51f32f46a3732725a69045422f96b388420c98dd13ced3", + turn_username, + turn_credential, "tcp", True, ), ( "turn.cloudflare.com", # cleaned 443, - "g0c069ee067cb5585f7a4799950312a355f2cb9c20e23d21bd1ecb1f93c1e8b0", - "d40a0992b4d08175af51f32f46a3732725a69045422f96b388420c98dd13ced3", + turn_username, + turn_credential, "tcp", True, ), ( "turn.cloudflare.com", # cleaned 80, - "g0c069ee067cb5585f7a4799950312a355f2cb9c20e23d21bd1ecb1f93c1e8b0", - "d40a0992b4d08175af51f32f46a3732725a69045422f96b388420c98dd13ced3", + turn_username, + turn_credential, "tcp", False, ), ( "turn.cloudflare.com", # cleaned 3478, - "g0c069ee067cb5585f7a4799950312a355f2cb9c20e23d21bd1ecb1f93c1e8b0", - "d40a0992b4d08175af51f32f46a3732725a69045422f96b388420c98dd13ced3", + turn_username, + turn_credential, "tcp", False, ), @@ -180,6 +187,10 @@ def my_agent(payload): if __name__ == "__main__": - app.run() - #results = comprehensive_network_test() - #print(results) + if os.getenv("PIPECAT_LOCAL_DEV") == "1": + # Running locally + results = comprehensive_network_test() + print(results) + else: + # Running on AgentCore Runtime + app.run() diff --git a/examples/aws-agentcore/env.example b/examples/aws-agentcore/env.example index bf35370f5..a7fb1524a 100644 --- a/examples/aws-agentcore/env.example +++ b/examples/aws-agentcore/env.example @@ -1,4 +1,7 @@ OPENAI_API_KEY=... DEEPGRAM_API_KEY=... CARTESIA_API_KEY=... -DAILY_SAMPLE_ROOM_URL=https://.daily.co/ + +PIPECAT_LOCAL_DEV=... +TURN_USERNAME= +TURN_CREDENTIAL=