feat(runtime): add HTTP invocation and execute_command support to AgentCoreRuntimeClient#422
Open
EashanKaushik wants to merge 2 commits intoaws:mainfrom
Open
feat(runtime): add HTTP invocation and execute_command support to AgentCoreRuntimeClient#422EashanKaushik wants to merge 2 commits intoaws:mainfrom
EashanKaushik wants to merge 2 commits intoaws:mainfrom
Conversation
Author
|
Pushed the rework per the review:
Commits on the branch:
Happy to squash before merge if that's the preferred shape. Test numbers (run from
PR body and #423 updated to match. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #422 +/- ##
=======================================
Coverage ? 91.34%
=======================================
Files ? 58
Lines ? 5197
Branches ? 803
=======================================
Hits ? 4747
Misses ? 256
Partials ? 194
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #423
Summary
Extends
AgentCoreRuntimeClient(which previously only generated WebSocket URLs and SigV4/OAuth headers) with HTTP invocation, SSE streaming, async streaming, and theInvokeAgentRuntimeCommandshell-exec API using bearer-token auth. Methods takeruntime_arnandbearer_tokenper call, mirroring the existinggenerate_ws_connection_oauthshape.Design (per reviewer guidance)
AgentCoreRuntimeClientalongside the existing URL-generation methods. No new sibling class.invoke,invoke_streaming,invoke_streaming_async,execute_command,execute_command_streaming, andstop_runtime_sessionall take(runtime_arn, bearer_token, ...)positionally — identical shape togenerate_ws_connection_oauth.PoolManager.self._httpis a@propertythat imports and constructsurllib3.PoolManageron first access. Callers that only use SigV4 URL-generation methods never trigger the import or pay the allocation cost._build_http_url, which extracts region via_parse_runtime_arnand builds the base URL viaget_data_plane_endpointfrombedrock_agentcore._utils.endpoints. No hardcoded host or region.Usage
Setup
Streaming invocation (SSE)
Async variant for FastAPI / MCP servers:
Shell command execution (
InvokeAgentRuntimeCommand)Blocking, collects full output:
Streaming EventStream events for long-running commands:
Stop a session
What's included
src/bedrock_agentcore/runtime/agent_core_runtime_client.py— six new HTTP methods onAgentCoreRuntimeClient,AgentRuntimeErrorexception,_build_http_urlhelper reusing_parse_runtime_arn+get_data_plane_endpoint, lazy_httpproperty, and response-parsing helpers.src/bedrock_agentcore/runtime/__init__.py— exportsAgentRuntimeError.tests/unit/runtime/test_agent_core_runtime_client.py— 72 new unit tests (lazy-pool lifecycle, per-method behavior, all_decode_sse_linebranches, EventStream parsing). 96% branch coverage on the merged class.CHANGELOG.md—[Unreleased]entry.Design notes
botocore.eventstream.EventStreamBuffer(already transitive viaboto3).execute_command(..., command_timeout=DEFAULT_COMMAND_TIMEOUT)— the server-side wall-clock limit. The HTTP read timeout is derived internally ascommand_timeout + 30(not caller-facing).generate_ws_connection/generate_presigned_url/generate_ws_connection_oauthsignatures or behavior.Test plan
uv run ruff check src/ tests/— cleanuv run mypy src/bedrock_agentcore/runtime/agent_core_runtime_client.py— only pre-existing warning ongenerate_presigned_url(line 518, unchanged from upstream main; verified viagit stash)uv run pytest tests/unit/runtime/test_agent_core_runtime_client.py— 106/106 pass (34 pre-existing SigV4 tests preserved + 72 new HTTP tests)uv run pytest tests/ --cov=src— 1505 passed, 0 failed, total coverage 92.77% (above 90% gate)agent_core_runtime_client.py: 96%tests_integ/runtime/— not added (would require a deployed exec-capable runtime; happy to follow up)Possible follow-up (not in this PR)
regionin__init__becomes redundant when the ARN is supplied per-call (HTTP methods use the ARN-parsed region). The SigV4 URL-generation methods still rely onself.regionfor signing, so changing this touches more than I wanted to in one PR. Happy to open a separate issue/PR if it's worth relaxing.