Skip to content

Prepare Agent for RL

Preparing an Agent for RL training is straightforward. The side-by-side below shows a deployed Bedrock AgentCore agent and the RL-adapted version using AgentCoreRuntimeApp.

A math agent that uses Bedrock AgentCore Runtime and the Strands Agents framework.

from bedrock_agentcore.runtime import BedrockAgentCoreApp
from strands import Agent
from strands.models import BedrockModel
from strands_tools import calculator
app = BedrockAgentCoreApp()
@app.entrypoint
def invoke_agent(payload):
model = BedrockModel(model_id="us.anthropic.claude-sonnet-5-5")
agent = Agent(
model=model,
tools=[calculator],
system_prompt="Solve the math problem step by step.",
)
user_input = payload.get("prompt")
response = agent(user_input)
# Skip the leading reasoningContent block from adaptive thinking.
content = response.message.get("content") or []
return "".join(block["text"] for block in content if "text" in block)
if __name__ == "__main__":
app.run()
from agentcore_rl_toolkit import RewardFunction
class MyReward(RewardFunction):
def __call__(self, **kwargs) -> float:
# Compute a scalar from response_text, ground_truth,
# test_tracker, repo_dir, or whatever context you need.
return reward

The container must implement the Runtime’s HTTP contract: serve /invocations and /ping on port 8080. AgentCoreRuntimeApp provides these endpoints. The examples use ARM64 images built through the Python AgentCore CLI and CodeBuild.

The Runtime must be able to reach the inference server or rollout gateway. For a private endpoint, deploy into a VPC that routes to it and allows traffic on its TCP port. Container builds also need access to dependency sources.

Each example README includes its deployment commands. For CLI setup, see installation.

A successful deploy prints the agent runtime ARN — that’s the identifier the training backend uses to invoke the agent. For verl and slime, configure the HTTP session backend:

rollout_session_backend:
backend: agentcore_rl_toolkit.rollout_session.agentcore_http_session.AgentCoreHttpSession
agentcore_runtime_arn: "arn:aws:bedrock-agentcore:REGION:ACCOUNT:runtime/AGENT_ID"

Browse Training Backends for the toolkit’s verl, slime, SkyRL, and Tinker guides. For rLLM’s native AgentCore integration, follow the rLLM documentation.