Repository navigation
fix: preserve AgentCore context in RFT handlers - #6571
Conversation
|
cc @992X @SifeiLi for review. issue identified by @qingliz in awslabs/agentcore-rl-toolkit#209 |
There was a problem hiding this comment.
🤖 AI code review
This PR fixes sagemaker_rft_handler so that both the sync and async wrappers forward extra positional/keyword arguments to the wrapped handler, allowing AgentCore entrypoints with a (payload, context) signature to work. The change is minimal, backward compatible, and comes with new unit tests covering sync/async handlers, positional and keyword context forwarding, feedback reporting, and context cleanup. The docstring is also corrected to use the real decorator name. The code is correct — imports (RolloutFeedbackClient, sagemaker_rft_handler, get_inference_params, get_rollout_context) and the monkeypatched _bearer_post all exist in the base checkout. No issues found.
Reviewed commit 2c195a5. Automated review; verify before acting.
There was a problem hiding this comment.
🤖 AI code review
This PR fixes sagemaker_rft_handler so it forwards extra positional/keyword arguments (e.g. AgentCore's context) through both the sync and async wrappers while still using functools.wraps. The change is small, correct, and backward-compatible with single-argument handlers. It adds solid unit coverage (sync/async, positional/keyword context, feedback reporting, context cleanup) and corrects a stale decorator name in the docstring example. I found no issues; the exports and context helpers used by the new test exist at the base commit, and the monkeypatched _bearer_post is the real method on the feedback client.
Reviewed commit 898efb0. Automated review; verify before acting.
|
Checks are passing (including AI code reviewer), remaining issue is a merge conflict just on a unit test file, can be run locally so that checks do not need to be rerun! |
|
Checks already passed previously, and test_rft_decorators.py was run locally and verified due to merge conflicts introduced by merging #6572. |
Description
Fix
sagemaker_rft_handlerfailing when an AgentCore entrypoint accepts(payload, context). The SageMaker integration guide requires applying this decorator to AgentCore entrypoints. The official AgentCore Python SDK supports the context parameter and covers it in both sync and async tests.For example:
AgentCore uses
inspect.signature()to decide whether to pass the request context. Because the RFT decorator usesfunctools.wraps, inspection exposes the original two-argument signature, but the wrapper accepts onlypayload. Invoking the example therefore returns HTTP 500 withTypeError: invoke() takes 1 positional argument but 2 were given, before the handler or rollout feedback logic runs.Forward additional positional and keyword arguments through both RFT wrappers while retaining
wraps. This lets AgentCore supply the context and preserves existing single-argument handlers. Add unit coverage for sync/async handlers, positional and keyword context forwarding, feedback reporting, and rollout context cleanup. Update the decorator's argument documentation and correct its name in the existing example.Validation
pytest sagemaker-train/tests/unit/train/test_rft_decorators.py: 8 passed.BedrockAgentCoreApp, with feedback HTTP requests mocked: sync and async context handlers fail before the fix and succeed after it.