Amazon Bedrock AgentCore Python SDK

1.6.0 · active · verified Thu Apr 09

The Amazon Bedrock AgentCore Python SDK provides a higher-level abstraction for developing and deploying AI agents on Amazon Bedrock AgentCore. This SDK simplifies operations related to agent runtime, memory, authentication, and tools, offering framework-agnostic primitives. It is actively maintained with frequent releases, currently at version 1.6.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a simple AI agent using the `bedrock-agentcore` SDK. It initializes a `BedrockAgentCoreApp` and registers a handler function with the `@entrypoint` decorator. The agent echoes back the received prompt. The `app.run()` method allows for local testing by starting an HTTP server. Remember to set your AWS region and configure AWS credentials for local execution.

import os
from bedrock_agentcore.agent import BedrockAgentCoreApp, entrypoint

# Initialize the AgentCore application
app = BedrockAgentCoreApp(
    region_name=os.environ.get('AWS_REGION', 'us-east-1')
)

# Define your agent's entrypoint
@app.entrypoint()
def handler(event):
    """Handles incoming agent invocations."""
    prompt = event.prompt
    # In a real agent, you would process the prompt, use tools, or interact with memory.
    response_content = f"Hello from your AgentCore agent! You said: {prompt}"
    
    # The response must be a dictionary with a 'response' key for simple text responses
    return {"response": response_content}

# To run the agent locally (for development and testing)
# Make sure to set AWS_REGION and have AWS credentials configured.
# The `app.run()` method starts a local HTTP server on port 8080.
# You can test it with `curl -X POST http://localhost:8080/invocations -H "Content-Type: application/json" -d '{"prompt": "What's up?"}'`
if __name__ == "__main__":
    print("Starting Bedrock AgentCore agent locally. Access at http://localhost:8080/invocations")
    print("Ensure AWS_REGION environment variable is set and AWS credentials are configured.")
    app.run()

view raw JSON →