From efa066915501fbbe53df185f94c5d17062dfc5cc Mon Sep 17 00:00:00 2001 From: Paul Kompfner Date: Thu, 20 Nov 2025 11:36:51 -0500 Subject: [PATCH] Amazon Bedrock AgentCore exploration, cont'd --- examples/aws-agentcore/bot.py | 33 ++++++++++++++++++++++--- examples/aws-agentcore/pyproject.toml | 1 + examples/aws-agentcore/requirements.txt | 1 + 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/examples/aws-agentcore/bot.py b/examples/aws-agentcore/bot.py index d7d09cf1d..06c61baff 100644 --- a/examples/aws-agentcore/bot.py +++ b/examples/aws-agentcore/bot.py @@ -6,6 +6,7 @@ import os +import aiohttp from bedrock_agentcore import BedrockAgentCoreApp from dotenv import load_dotenv from loguru import logger @@ -35,6 +36,22 @@ app = BedrockAgentCoreApp() load_dotenv(override=True) +async def get_public_ip(): + """Retrieve public IP from AWS metadata service or external service.""" + try: + # Fallback to external service + async with aiohttp.ClientSession() as session: + async with session.get( + "https://api.ipify.org", timeout=aiohttp.ClientTimeout(total=5) + ) as response: + if response.status == 200: + return await response.text() + except Exception: + pass + + return None + + async def fetch_weather_from_api(params: FunctionCallParams): await params.result_callback({"conditions": "nice", "temperature": "75"}) @@ -65,6 +82,14 @@ transport_params = { async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): logger.info(f"Starting bot") + public_ip = await get_public_ip() + if public_ip: + logger.info(f"Public IP address: {public_ip}") + else: + logger.warning("Could not retrieve public IP address") + + yield {"status": "initializing", "ip": public_ip} + stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY")) tts = CartesiaTTSService( @@ -162,13 +187,14 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): app.complete_async_task(task_id) - return {"status": "success"} + yield {"status": "completed"} async def bot(runner_args: RunnerArguments): """Bot entry point for running locally and on Pipecat Cloud.""" transport = await create_transport(runner_args, transport_params) - await run_bot(transport, runner_args) + async for result in run_bot(transport, runner_args): + pass # Consume the stream @app.entrypoint @@ -179,7 +205,8 @@ async def agentcore_bot(payload, context): DailyRunnerArguments(room_url=room_url), transport_params, ) - await run_bot(transport, RunnerArguments()) + async for result in run_bot(transport, RunnerArguments()): + yield result if __name__ == "__main__": diff --git a/examples/aws-agentcore/pyproject.toml b/examples/aws-agentcore/pyproject.toml index d8c47e5e1..038a9fa84 100644 --- a/examples/aws-agentcore/pyproject.toml +++ b/examples/aws-agentcore/pyproject.toml @@ -4,6 +4,7 @@ version = "0.1.0" description = "Example for building Pipecat bots deployable to Amazon Bedrock AgentCore" requires-python = ">=3.10" dependencies = [ + "aiohttp", "bedrock-agentcore", "pipecat-ai[webrtc,daily,silero,deepgram,openai,cartesia,local-smart-turn-v3,runner]", ] diff --git a/examples/aws-agentcore/requirements.txt b/examples/aws-agentcore/requirements.txt index d2775d113..a451ef1a5 100644 --- a/examples/aws-agentcore/requirements.txt +++ b/examples/aws-agentcore/requirements.txt @@ -1,2 +1,3 @@ +aiohttp bedrock-agentcore pipecat-ai[webrtc,daily,silero,deepgram,openai,cartesia,local-smart-turn-v3,runner] \ No newline at end of file