Commit 535faa5
Feature/bidirectional streaming (#180)
* feat: add WebSocket support with @app.websocket decorator (#41)
* feat: add WebSocket support with @app.websocket decorator
Add bidirectional streaming support for agent invocations:
- Add @app.websocket decorator for registering WebSocket handlers
- Register /ws endpoint in BedrockAgentCoreApp constructor
- Implement _handle_websocket method with proper error handling
- Follow existing decorator patterns (entrypoint, ping) for consistency
- Support WebSocketDisconnect for graceful connection handling
- Integrate with existing RequestContext for session management
test: add unit and integration tests for WebSocket support
Add comprehensive test coverage for WebSocket decorator:
Unit tests (10 tests):
- WebSocket route initialization and registration
- Decorator functionality and handler storage
- Basic send/receive communication
- Context integration with session IDs
- Exception handling and error cases
- Multiple message handling
- Graceful disconnect handling
- Custom request headers via context
- Streaming data functionality
Integration test:
- End-to-end WebSocket echo server
- Streaming multiple messages
- Session ID propagation through headers
- Real WebSocket client connection testing
All tests pass successfully.
* fix: remove exception details from WebSocket close reason
Don't send exception messages to clients when closing WebSocket connections
with code 1011. This prevents leaking internal error details to clients.
Changes:
- Remove reason parameter from websocket.close() calls
- Exception details are still logged server-side
- Tests continue to pass as they only check for disconnect exceptions
---------
Co-authored-by: Abishek Kumar <kumabish@amazon.com>
* feat: add AgentRuntimeClient for WebSocket authentication (#42)
* feat: add AgentRuntimeClient for WebSocket authentication
- Implemented AgentRuntimeClient with methods for generating WebSocket credentials
- Added generate_ws_connection() for backend services (returns URL + SigV4 headers)
- Added generate_presigned_url() for frontend clients (returns presigned URL)
- Support for endpoint qualifiers and custom query parameters (presigned URLs only)
- Comprehensive unit tests with 22 test cases covering all functionality
- Integration tests for validating credential format
- Complete documentation with usage examples
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: move websockets to dev dependencies for CI
The websockets package was in optional dependencies which caused
CI test failures. Moving it to dev dependencies ensures it's
installed during CI test runs.
* fix: skip integration tests when AWS credentials unavailable
Add skipif decorator to integration tests that require AWS credentials.
This prevents CI failures when credentials are not configured.
* refactor: use mocked credentials instead of skipping tests
Replace skipif decorators with pytest fixture that mocks boto3 credentials
using botocore.credentials.Credentials class. This ensures integration tests
run in all environments (local and CI) while still validating URL and header
generation logic.
Benefits:
- Tests always run, providing better coverage
- Uses real Credentials class for proper SigV4 signing
- No need for AWS credentials to be configured
* refactor: rename AgentRuntimeClient to AgentCoreRuntimeClient
- Rename class from AgentRuntimeClient to AgentCoreRuntimeClient
- Rename module from agent_runtime_client.py to agent_core_runtime_client.py
- Update all unit and integration tests to use new class name
- Update __init__.py exports
- Update documentation examples
This provides a more accurate name that reflects the AgentCore Runtime service.
---------
Co-authored-by: Abishek Kumar <kumabish@amazon.com>
Co-authored-by: Claude <noreply@anthropic.com>
* chore: exclude integration testing workflow changes
* fix: add websockets to integration test
---------
Co-authored-by: Abishek K <Abishek10@users.noreply.github.com>
Co-authored-by: Abishek Kumar <kumabish@amazon.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Sundar Raghavan <sdraghav@amazon.com>1 parent 95bbfa4 commit 535faa5
File tree
11 files changed
+2373
-804
lines changed- .github/workflows
- docs/examples
- src/bedrock_agentcore/runtime
- tests_integ/runtime
- tests
- bedrock_agentcore/runtime
- integration/runtime
- unit/runtime
11 files changed
+2373
-804
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
| 147 | + | |
146 | 148 | | |
147 | 149 | | |
148 | 150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments