From 16b833c194826972e3d897c5cce19ccafc4a8e7f Mon Sep 17 00:00:00 2001 From: Filipi Fuchter Date: Fri, 28 Nov 2025 09:33:36 -0300 Subject: [PATCH] Refactoring to use smallwebrtc --- examples/aws-agentcore/.gitignore | 1 + .../aws-agentcore/agents/pipecat/README.md | 4 ++ .../agents/pipecat/pipecat-agent.py | 47 +++++++++---------- examples/aws-agentcore/server/server.py | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 examples/aws-agentcore/agents/pipecat/README.md diff --git a/examples/aws-agentcore/.gitignore b/examples/aws-agentcore/.gitignore index ee67afabd..a5acfe63b 100644 --- a/examples/aws-agentcore/.gitignore +++ b/examples/aws-agentcore/.gitignore @@ -1,4 +1,5 @@ .bedrock_agentcore.yaml .dockerignore .bedrock_agentcore +.bkp logs \ No newline at end of file diff --git a/examples/aws-agentcore/agents/pipecat/README.md b/examples/aws-agentcore/agents/pipecat/README.md new file mode 100644 index 000000000..98231ac39 --- /dev/null +++ b/examples/aws-agentcore/agents/pipecat/README.md @@ -0,0 +1,4 @@ +# Need to update the Dockerfile after executing `agentcore configure` + +Add this command to the Dockerfile: +- `RUN apt update && apt install -y libgl1 libglib2.0-0 && apt clean` \ No newline at end of file diff --git a/examples/aws-agentcore/agents/pipecat/pipecat-agent.py b/examples/aws-agentcore/agents/pipecat/pipecat-agent.py index 58604f4be..ac7748cad 100644 --- a/examples/aws-agentcore/agents/pipecat/pipecat-agent.py +++ b/examples/aws-agentcore/agents/pipecat/pipecat-agent.py @@ -16,13 +16,17 @@ from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.task import PipelineParams, PipelineTask from pipecat.processors.aggregators.llm_context import LLMContext from pipecat.processors.aggregators.llm_response_universal import LLMContextAggregatorPair -from pipecat.runner.types import DailyRunnerArguments, RunnerArguments +from pipecat.runner.types import RunnerArguments, SmallWebRTCRunnerArguments from pipecat.runner.utils import create_transport from pipecat.services.cartesia.tts import CartesiaTTSService from pipecat.services.deepgram.stt import DeepgramSTTService from pipecat.services.openai.llm import OpenAILLMService from pipecat.transports.base_transport import BaseTransport, TransportParams -from pipecat.transports.daily.transport import DailyLogLevel, DailyParams, DailyTransport +from pipecat.transports.daily.transport import DailyParams +from pipecat.transports.smallwebrtc.connection import SmallWebRTCConnection +from pipecat.transports.smallwebrtc.request_handler import ( + SmallWebRTCRequest, +) app = BedrockAgentCoreApp() @@ -50,6 +54,10 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): logger.info(f"Starting bot") yield {"status": "initializing bot!"} + # Returning the answer + if isinstance(runner_args, SmallWebRTCRunnerArguments): + yield {"status": "Will return smallwebrtc answer."} + yield runner_args.webrtc_connection.get_answer() stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY")) @@ -116,31 +124,18 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): @app.entrypoint async def agentcore_bot(payload, context): """Bot entry point for running on Amazon Bedrock AgentCore Runtime.""" - room_url = payload.get("roomUrl") - transport = await create_transport( - 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, - }, - ], - } - ) + request = SmallWebRTCRequest.from_dict(payload) + # TODO: need to implement this + # ice_servers=self._ice_servers + pipecat_connection = SmallWebRTCConnection() + await pipecat_connection.initialize(sdp=request.sdp, type=request.type) + + # Prepare runner arguments with the callback to run your bot + runner_args = SmallWebRTCRunnerArguments( + webrtc_connection=pipecat_connection, body=request.request_data + ) + transport = await create_transport(runner_args, transport_params) async for result in run_bot(transport, RunnerArguments()): yield result diff --git a/examples/aws-agentcore/server/server.py b/examples/aws-agentcore/server/server.py index 4ac71ed4d..654714c09 100644 --- a/examples/aws-agentcore/server/server.py +++ b/examples/aws-agentcore/server/server.py @@ -59,7 +59,7 @@ async def offer(request: Request): agentRuntimeArn=AGENT_RUNTIME_ARN, contentType="application/json", accept="application/json", - payload=json.dumps({"input": data}), + payload=json.dumps(data), # TODO: create a custom randon id runtimeSessionId="user-123456-conversation-111115555", )