Skip to content

Commit 077e9c1

Browse files
committed
Provide a way to run aws-agentcore-websocket example locally before deploying it to AgentCore Runtime
1 parent ea6fb83 commit 077e9c1

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

deployment/aws-agentcore-websocket/README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ You can also choose to specify more granular permissions; see [Amazon Bedrock Ag
6262
cp env.example .env
6363
```
6464

65-
Add your AWS credentials and configuration, for generating the signed WebSocket URL in the `/start` endpoint:
65+
Add your AWS credentials and configuration, for generating a signed WebSocket URL in the `/start` endpoint:
6666

6767
- `AWS_ACCESS_KEY_ID`
6868
- `AWS_SECRET_ACCESS_KEY`
@@ -113,7 +113,7 @@ This is also the command you need to run after you've updated your agent code.
113113

114114
## Running the Server
115115

116-
The server provides a `/start` endpoint that generates signed WebSocket URLs for the client.
116+
The server provides a `/start` endpoint that generates WebSocket URLs for the client to connect to the agent.
117117

118118
See [the server README](./server/README.md) for setup and run instructions.
119119

@@ -123,6 +123,27 @@ Once the server is running, you can run the client to connect to your AgentCore-
123123

124124
See [the client README](./client/README.md) for setup and run instructions.
125125

126+
## Testing Locally
127+
128+
To test agent logic locally before deploying to AgentCore Runtime, do the following.
129+
130+
First, run the agent locally:
131+
132+
```bash
133+
cd agent
134+
uv run python agent.py
135+
```
136+
137+
This will make the agent reachable at "ws://localhost:8080/ws".
138+
139+
Then, run the server as usual, but with the `LOCAL_AGENT=1` environment variable:
140+
141+
```bash
142+
LOCAL_AGENT=1 uv run python server.py
143+
```
144+
145+
You can then [run your client as usual](#running-the-client).
146+
126147
## Observation
127148

128149
Paste one of the log tailing commands you received when deploying your agent to AgentCore Runtime. It should look something like:

deployment/aws-agentcore-websocket/agent/agent.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from loguru import logger
1212
from pipecat.adapters.schemas.function_schema import FunctionSchema
1313
from pipecat.adapters.schemas.tools_schema import ToolsSchema
14-
from pipecat.audio.turn.smart_turn.base_smart_turn import SmartTurnParams
1514
from pipecat.audio.turn.smart_turn.local_smart_turn_v3 import LocalSmartTurnAnalyzerV3
1615
from pipecat.audio.vad.silero import SileroVADAnalyzer
1716
from pipecat.audio.vad.vad_analyzer import VADParams
@@ -27,8 +26,7 @@
2726
from pipecat.services.cartesia.tts import CartesiaTTSService
2827
from pipecat.services.deepgram.stt import DeepgramSTTService
2928
from pipecat.services.llm_service import FunctionCallParams
30-
from pipecat.transports.base_transport import BaseTransport, TransportParams
31-
from pipecat.transports.daily.transport import DailyParams
29+
from pipecat.transports.base_transport import BaseTransport
3230
from pipecat.transports.websocket.fastapi import FastAPIWebsocketParams, FastAPIWebsocketTransport
3331

3432
app = BedrockAgentCoreApp()
@@ -44,25 +42,6 @@ async def fetch_restaurant_recommendation(params: FunctionCallParams):
4442
await params.result_callback({"name": "The Golden Dragon"})
4543

4644

47-
# We store functions so objects (e.g. SileroVADAnalyzer) don't get
48-
# instantiated. The function will be called when the desired transport gets
49-
# selected.
50-
transport_params = {
51-
"daily": lambda: DailyParams(
52-
audio_in_enabled=True,
53-
audio_out_enabled=True,
54-
vad_analyzer=SileroVADAnalyzer(params=VADParams(stop_secs=0.2)),
55-
turn_analyzer=LocalSmartTurnAnalyzerV3(params=SmartTurnParams()),
56-
),
57-
"webrtc": lambda: TransportParams(
58-
audio_in_enabled=True,
59-
audio_out_enabled=True,
60-
vad_analyzer=SileroVADAnalyzer(params=VADParams(stop_secs=0.2)),
61-
turn_analyzer=LocalSmartTurnAnalyzerV3(params=SmartTurnParams()),
62-
),
63-
}
64-
65-
6645
async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
6746
logger.info(f"Starting bot")
6847

@@ -176,7 +155,8 @@ async def agentcore_bot(websocket, context):
176155
audio_in_enabled=True,
177156
audio_out_enabled=True,
178157
add_wav_header=False,
179-
vad_analyzer=SileroVADAnalyzer(),
158+
vad_analyzer=SileroVADAnalyzer(params=VADParams(stop_secs=0.2)),
159+
turn_analyzer=LocalSmartTurnAnalyzerV3(),
180160
serializer=ProtobufFrameSerializer(),
181161
),
182162
)

deployment/aws-agentcore-websocket/server/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Server
22

3-
This server provides a `/start` endpoint that generates signed WebSocket URLs for connecting to the agent running on Amazon Bedrock AgentCore.
3+
This server provides a `/start` endpoint that generates WebSocket URLs for connecting to the agent running on Amazon Bedrock AgentCore.
44

55
## Prerequisites
66

@@ -35,11 +35,19 @@ uv run python server.py
3535

3636
The server will be available at `http://localhost:7860`.
3737

38+
## Running the Server in Local Agent Mode
39+
40+
If you want to test a locally-running agent (reachable at "ws://localhost:8080/ws"), start the server like this:
41+
42+
```bash
43+
LOCAL_AGENT=1 uv run python server.py
44+
```
45+
3846
## Endpoint
3947

4048
### POST /start
4149

42-
Returns a signed WebSocket URL for the client to connect to the agent running on Amazon Bedrock AgentCore.
50+
Returns a WebSocket URL for the client to connect to the agent running on Amazon Bedrock AgentCore.
4351

4452
**Response:**
4553

deployment/aws-agentcore-websocket/server/server.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ async def start_bot(request: Request) -> Dict[Any, Any]:
4747
Returns:
4848
Dict[Any, Any]: Contains the signed WebSocket URL for the client to connect
4949
"""
50+
# Check if LOCAL_AGENT mode is enabled
51+
if os.getenv("LOCAL_AGENT") == "1":
52+
return {"ws_url": "ws://localhost:8080/ws"}
53+
5054
# Get required environment variables
5155
access_key_id = os.getenv("AWS_ACCESS_KEY_ID")
5256
secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY")

0 commit comments

Comments
 (0)