Skip to main content

Bedrock AgentCore

Call Bedrock AgentCore in the OpenAI Request/Response format.

PropertyDetails
DescriptionAmazon Bedrock AgentCore provides direct access to hosted agent runtimes for executing agentic workflows with foundation models.
Provider Route on LiteLLMbedrock/agentcore/{AGENT_RUNTIME_ARN}
Provider DocAWS Bedrock AgentCore โ†—

Quick Startโ€‹

Model Format to LiteLLMโ€‹

To call a bedrock agent runtime through LiteLLM, use the following model format.

Here the model=bedrock/agentcore/ tells LiteLLM to call the bedrock InvokeAgentRuntime API.

Model Format to LiteLLM
bedrock/agentcore/{AGENT_RUNTIME_ARN}

Example:

  • bedrock/agentcore/arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-agent-runtime

You can find the Agent Runtime ARN in your AWS Bedrock console under AgentCore.

LiteLLM Python SDKโ€‹

Basic AgentCore Completion
import litellm

# Make a completion request to your AgentCore runtime
response = litellm.completion(
model="bedrock/agentcore/arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-agent-runtime",
messages=[
{
"role": "user",
"content": "Explain machine learning in simple terms"
}
],
)

print(response.choices[0].message.content)
print(f"Usage: {response.usage}")
Streaming AgentCore Responses
import litellm

# Stream responses from your AgentCore runtime
response = litellm.completion(
model="bedrock/agentcore/arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-agent-runtime",
messages=[
{
"role": "user",
"content": "What are the key principles of software architecture?"
}
],
stream=True,
)

for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")

LiteLLM Proxyโ€‹

1. Configure your model in config.yamlโ€‹

LiteLLM Proxy Configuration
model_list:
- model_name: agentcore-runtime-1
litellm_params:
model: bedrock/agentcore/arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-agent-runtime
aws_access_key_id: os.environ/AWS_ACCESS_KEY_ID
aws_secret_access_key: os.environ/AWS_SECRET_ACCESS_KEY
aws_region_name: us-west-2

- model_name: agentcore-runtime-2
litellm_params:
model: bedrock/agentcore/arn:aws:bedrock-agentcore:us-east-1:987654321098:runtime/production-runtime
aws_access_key_id: os.environ/AWS_ACCESS_KEY_ID
aws_secret_access_key: os.environ/AWS_SECRET_ACCESS_KEY
aws_region_name: us-east-1

2. Start the LiteLLM Proxyโ€‹

Start LiteLLM Proxy
litellm --config config.yaml

3. Make requests to your AgentCore runtimesโ€‹

Basic AgentCore Request
curl http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-d '{
"model": "agentcore-runtime-1",
"messages": [
{
"role": "user",
"content": "Summarize the main benefits of cloud computing"
}
]
}'
Streaming AgentCore Request
curl http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-d '{
"model": "agentcore-runtime-2",
"messages": [
{
"role": "user",
"content": "Explain the differences between SQL and NoSQL databases"
}
],
"stream": true
}'

Provider-specific Parametersโ€‹

AgentCore supports additional parameters that can be passed to customize the runtime invocation.

Using AgentCore-specific parameters
from litellm import completion

response = litellm.completion(
model="bedrock/agentcore/arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-agent-runtime",
messages=[
{
"role": "user",
"content": "Analyze this data and provide insights",
}
],
qualifier="production", # PROVIDER-SPECIFIC: Runtime qualifier/version
runtimeSessionId="session-abc-123", # PROVIDER-SPECIFIC: Custom session ID
)

Available Parametersโ€‹

ParameterTypeDescription
qualifierstringOptional runtime qualifier/version to invoke a specific version of the agent runtime
runtimeSessionIdstringOptional custom session ID (must be 33+ characters). If not provided, LiteLLM generates one automatically

Further Readingโ€‹