Bedrock AgentCore Starter Toolkit

repository·main·Indexed 19 days ago

https://github.com/aws/bedrock-agentcore-starter-toolkit

A starter toolkit for using Amazon Bedrock AgentCore, a modular platform for deploying and managing AI agents. It provides infrastructure for memory, tool execution, and governance, supporting frameworks like LangGraph and Strands. The toolkit includes a MemoryManager for lifecycle and strategy management of memory resources and a CLI for importing existing Amazon Bedrock Agents. Note: The Starter Toolkit CLI is legacy; users are encouraged to migrate to the AgentCore CLI (@aws/agentcore).

Tokens
123.6K
Snippets
332
Records
441
Agent score
67%

What's inside bedrock-agentcore-starter-toolkit

  1. Overview of Amazon Bedrock AgentCore Services

    main

    Amazon Bedrock AgentCore is a modular platform for deploying and operating AI agents securely and at scale. It provides purpose-built infrastructure that works with popular open-source frameworks (like LangGraph, CrewAI, and Strands) and any model.

    Core modular services include:

    • Runtime: A secure, serverless runtime for deploying and scaling dynamic agents and tools.
    • Memory: Provides short-term (multi-turn conversation) and long-term (shared across sessions) memory management.
    • Gateway: A managed Model Context Protocol (MCP) server that converts APIs and Lambda functions into MCP tools.
    • Code Interpreter: Enables secure code execution in isolated sandbox environments.
    • Browser: A cloud-based browser runtime for agents to interact with websites.
    • Observability: Provides OpenTelemetry-compatible telemetry and dashboards for tracing and debugging.
    • Evaluation: Tools for assessing agent quality (helpfulness, correctness, etc.) via on-demand or continuous monitoring.
    • Identity: Secure agent identity and access management compatible with existing identity providers.
    • Policy: Real-time, deterministic control over agent actions using natural language or Cedar policy language.
    • Import-Agent: Facilitates migrating existing Amazon Bedrock Agents to AgentCore frameworks (LangChain/LangGraph or Strands).
  2. Map Bedrock Agent features to AgentCore primitives

    main

    When using the import-agent utility to migrate from Amazon Bedrock Agents to AgentCore (using either Langchain or Strands), the following feature mappings apply:

    Bedrock Agent FeatureAgentCore MappingAgentCore Primitive
    Action GroupsSupportedAgentCore Gateway
    OrchestrationSupportedReAcT pattern
    GuardrailsSupportedModel-level guardrails
    Knowledge BasesSupportedKB retrieval tools via AWS SDK
    Code InterpreterSupportedAgentCore Code Interpreter
    Short Term MemorySupportedIn-memory store (Langchain) / Sliding Conversation Manager (Strands)
    Long Term MemorySupportedAgentCore Memory
    Pre/Post-ProcessingSupportedPrompt-based injection
    User InputSupportedHuman input tool (CLI-based)
    TracesSupportedAgentCore Observability (OTEL logs)
    Multi-Agent CollaborationSupportedAgents-as-Tools approach
  3. Overview of Bedrock AgentCore Platform Services

    main

    Bedrock AgentCore provides the following enterprise-grade services:

    • AgentCore Runtime: Serverless deployment and scaling.
    • AgentCore Memory: Persistent knowledge via event and semantic memory.
    • AgentCore Code Interpreter: Secure, isolated sandbox code execution.
    • AgentCore Browser: Cloud-based browser for web interaction.
    • AgentCore Gateway: API-to-tool transformation.
    • AgentCore Observability: Real-time monitoring and tracing.
    • AgentCore Identity: Secure authentication and access management.
  4. What is MemoryManager and how does it work?

    main

    The MemoryManager class is a high-level client for managing AWS Bedrock AgentCore Memory resources. It handles the full lifecycle of memory resources, allowing AI agents to retain and recall information across conversations and sessions.

    Key capabilities include:

    • Lifecycle Management: Create, read, update, and delete memories with automatic status polling (waiting for resources to become ACTIVE).
    • Strategy Management: Add, modify, or delete memory strategies (e.g., Semantic, Summary, User Preference) to define how information is extracted and stored.
    • Type Safety: Uses strongly-typed strategy objects (like SemanticStrategy) for validation, while maintaining backward compatibility with dictionary-based configurations.
    • Automatic Polling: Methods suffixed with _and_wait automatically poll the resource state until the operation is complete.
  5. Overview of Bedrock AgentCore Platform Components

    main

    The platform is divided into two primary developer interfaces:

    Bedrock AgentCore SDK

    Provides Python primitives for agent development, including:

    • Runtime: Converts functions into API servers.
    • Memory: Persistent storage for conversation history and context.
    • Tools: Clients for code interpretation and browser automation.
    • Identity: Authentication and access management.

    Bedrock AgentCore Starter Toolkit

    Provides CLI tools and high-level abstractions for:

    • Deployment: Deploying Python agents to AWS (via direct_code_deploy) or containerizing them.
    • Import Agent: Migrating existing Bedrock Agents to AgentCore.
    • Gateway Integration: Transforming existing APIs into agent tools.
    • Configuration Management: Managing environment and deployment settings.
    • Observability: Monitoring agents in production.
  6. Configure AgentCore primitives and execution options

    main

    When importing an agent, you can control which AgentCore primitives are included and how the agent is executed:

    Primitives

    By default, Memory, Code Interpreter, and Observability primitives are enabled. To exclude them, use:

    • --disable-memory
    • --disable-code-interpreter
    • --disable-observability

    Execution and Deployment

    • Deployment: Use --deploy-runtime to deploy the agent to AgentCore Runtime. If this flag is omitted, the CLI will prompt you for a decision.
    • Run Options: Use --run-option to specify the execution mode. If omitted, the CLI will prompt you. Valid values are:
      • locally: Run the agent locally.
      • runtime: Run on AgentCore Runtime (requires --deploy-runtime).
      • none: Do not run the agent.
  7. Write Cedar policies for tool access

    main

    Policies are written in the Cedar language to permit or forbid access to gateway tools. A policy consists of a Who (principal), What (action), Which (resource), and When (conditions).

    Authorization Semantics

    Cedar follows a forbid-overrides-permit model:

    1. Default Deny: If no policies match, the result is DENY.
    2. Forbid Wins: If any forbid policy matches, the result is DENY, even if a permit policy also matches.
    3. At Least One Permit Required: If at least one permit policy matches and no forbid policies match, the result is ALLOW.

    Policy Enforcement Modes

    • LOG_ONLY: Evaluates and logs decisions without blocking actions (ideal for testing).
    • ENFORCE: Actively allows or denies agent operations based on the decision.
    permit(
      principal is AgentCore::OAuthUser,
      action == AgentCore::Action::"RefundTool__process_refund",
      resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/refund-gateway"
    )
    when {
      principal.hasTag("username") &&
      principal.getTag("username") == "refund-agent" &&
      context.input.amount < 500
    };
  8. Supported Target Platforms for Import Agent

    main

    When using the import-agent utility, you can choose between two primary target platforms for your migrated agent:

    • LangChain + LangGraph: Best for teams already utilizing the LangChain ecosystem or requiring extensive third-party integrations.
    • Strands: Best for teams seeking an AWS-native agent development experience with streamlined patterns.
  9. Handle Asynchronous Background Tasks

    main

    For long-running tasks, use AgentCore's asynchronous processing to avoid blocking the main response.

    Key Features:

    • Automatic Status Management: The agent status automatically switches to HealthyBusy during background processing and returns to Healthy upon completion.
    • Session Termination: Sessions terminate after 15 minutes of inactivity.

    Two Approaches:

    1. Manual Task Management: Use app.add_async_task(name, payload) to get a task_id, then call app.complete_async_task(task_id) when finished.
    2. Custom Ping Handler: Implement a @app.ping decorator that returns PingStatus.HEALTHY_BUSY if the system is currently processing data.
    @app.entrypoint
    def handler(event):
        task_id = app.add_async_task("data_processing", {"batch": 100})
    
        def background_work():
            import time
            time.sleep(30)
            app.complete_async_task(task_id)
    
        import threading
        threading.Thread(target=background_work, daemon=True).start()
        return {"task_id": task_id}
  10. How AgentCore Policy components work together

    main

    AgentCore Policy provides a deterministic authorization layer that sits outside of the agent's code. The core components are:

    • Policy Engines: Containers used to organize and manage related Cedar policies. They act as the evaluation unit.
    • Cedar Policies: Fine-grained authorization rules written in the Amazon Cedar language. They define who (principal) can perform what (action) on which resource under what when conditions.
    • Gateway Integration: The AgentCore Gateway intercepts tool calls at runtime. When a Policy Engine is attached to a Gateway in ENFORCE mode, the Gateway evaluates every request against the engine's policies before allowing the tool execution.

    Cedar Policy Syntax Example

    To allow a specific tool call only if the input amount is below a threshold, use a statement like this:

    permit(principal, 
      action == AgentCore::Action::"RefundTarget___process_refund", 
      resource == AgentCore::Gateway::"<gateway-arn>") 
    when { context.input.amount < 1000 };

    Enforcement Modes

    When attaching a Policy Engine to a Gateway via update_gateway_policy_engine, you can specify a mode. In ENFORCE mode:

    • Every tool call is intercepted.
    • All actions are denied by default unless explicitly permitted.
    • If any forbid policy matches, access is denied (forbid-wins semantics).
    • Decisions are logged to CloudWatch.
  11. Model Provider Authentication patterns

    main

    Authentication behavior depends on the provider and environment:

    • Amazon Bedrock: Uses IAM automatically.
    • Third-party providers:
      • Deployed environments: Use AgentCore Identity (recommended) or AWS Secrets Manager.
      • Local development: Uses a .env.local fallback when LOCAL_DEV=1 is set.

    For production templates, you are responsible for implementing secure API key handling.

  12. How Amazon Bedrock AgentCore supports A2A

    main

    Amazon Bedrock AgentCore acts as a transparent proxy layer for Agent-to-Agent (A2A) servers. It enables seamless integration by passing JSON-RPC payloads from the InvokeAgentRuntime API directly to the A2A container without modification. This architecture preserves standard A2A features like built-in agent discovery via Agent Cards while adding enterprise-grade session isolation, scalability, and authentication (SigV4/OAuth 2.0).

    A2A Server Requirements

    To be compatible with AgentCore Runtime, your A2A container must meet these specifications:

    • Port: Must run on port 9000.
    • Path: Must serve requests at the root path (0.0.0.0:9000/).
    • Protocol: Uses JSON-RPC for communication.
    • Discovery: Must support agent discovery through Agent Cards located at /.well-known/agent-card.json.