iToverDose/Software· 25 MAY 2026 · 16:05

Deploy LangGraph Agents Easily with AWS Bedrock AgentCore

Learn how to scale your LangGraph AI agents on AWS without rewriting code using Bedrock AgentCore’s serverless infrastructure and seamless deployment tools.

DEV Community5 min read0 Comments

Deploying a LangGraph agent from your local machine to a production-ready environment presents a common challenge: how to maintain scalability and reliability without overhauling the entire codebase. AWS Bedrock AgentCore provides a solution by offering a serverless platform designed to host, scale, and manage AI agents with minimal operational overhead.

This guide explains how to adapt an existing LangGraph agent for AWS Bedrock AgentCore, set up a functional project, test it locally, deploy it to AWS, and invoke it once live. The process preserves your agent’s core logic while leveraging AWS’s managed infrastructure for deployment, scaling, and monitoring.

Why Use AWS Bedrock AgentCore for AI Agent Deployment?

AWS Bedrock AgentCore is a fully managed service that eliminates the need for manual server setup or infrastructure management. It supports deployment of AI agents built with open-source frameworks such as LangGraph, Strands, CrewAI, or LlamaIndex, and works seamlessly with major large language models including GPT, Gemini, and Claude.

Key benefits include:

  • Serverless hosting — No servers to provision or manage; AWS handles capacity and scaling.
  • Session isolation — Each user session runs in isolation with persistent memory.
  • Observability — Built-in logging and monitoring tools to track agent performance and diagnostics.
  • Security and identity — Integrated identity management for secure authentication and access control.

The deployment process is streamlined through the AgentCore CLI, a Node.js-based command-line tool that scaffolds projects, runs a local development server, and deploys to AWS using AWS CDK under the hood.

Prerequisites: What You Need Before Starting

Before proceeding with deployment, ensure your environment meets the following requirements:

  • Python 3.12 or newer installed.
  • A package manager like uv or pip for Python dependency management.
  • Node.js version 20 or higher for running the AgentCore CLI.
  • AWS Cloud Development Kit (CDK) installed globally (npm install -g aws-cdk).
  • AWS CLI configured locally with valid credentials (aws configure).
  • An existing LangGraph agent with a compiled StateGraph object.

These prerequisites ensure compatibility with the AgentCore runtime and AWS infrastructure.

Step-by-Step: Deploying Your LangGraph Agent with AgentCore

Step 1: Install the AgentCore CLI

Begin by installing the AgentCore command-line tool, which will serve as the central tool for project creation, local testing, and AWS deployment.

Run the following command to install the CLI globally:

npm install -g @aws/agentcore

After installation, verify the CLI is working:

agentcore --help

This should display available commands and options.

Step 2: Add Required Dependencies to Your Project

Your LangGraph agent will need two additional dependencies to integrate with AgentCore:

  • bedrock-agentcore — The Python SDK that provides the BedrockAgentCoreApp wrapper class.
  • aws-opentelemetry-distro — AWS’s distribution of the OpenTelemetry instrumentation framework for Python, enabling observability.

Update your Python project configuration file (e.g., pyproject.toml) to include these dependencies:

[project]
name = "my-agent"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
    "aws-opentelemetry-distro==0.17.0",
    "bedrock-agentcore>=1.6.3",
    "boto3>=1.42.0",
    "langgraph>=1.1.0",
    "langchain-core>=1.2.0",
    # Add other existing dependencies here
]

Install the dependencies using your preferred workflow:

uv sync

or

pip install -e .

Step 3: Create the AgentCore Entrypoint

AgentCore requires a single Python entrypoint file (main.py) that wraps your LangGraph logic using the BedrockAgentCoreApp class. The core agent logic remains unchanged; only the runtime interface is adapted.

Here’s a minimal structure for main.py:

from langchain_core.messages import HumanMessage
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from graphs.my_agent_graph import build_my_agent  # Your existing graph builder

# 1. Create the AgentCore app and get a logger
app = BedrockAgentCoreApp()
log = app.logger

# 2. Initialize the agent graph at module load time
# AgentCore loads this module once and handles concurrent requests
def create_agent():
    log.info("Initializing agent...")
    graph = build_my_agent()  # Returns compiled StateGraph
    log.info("Agent ready")
    return graph

try:
    graph = create_agent()
except Exception as e:
    log.error(f"Critical failure during agent initialization: {e}")
    raise  # Fail fast to prevent broken deployments

# 3. Async function to run the agent and stream responses
async def run_agent(user_input: str, session_id: str = "default-session") -> str:
    responses = []
    config = {"configurable": {"thread_id": session_id}}
    
    async for chunk in graph.astream(
        {"messages": [HumanMessage(content=user_input)]},
        config=config,
        stream_mode="values",
    ):
        messages = chunk.get("messages", [])
        if messages:
            last = messages[-1]
            if getattr(last, "type", None) == "ai":
                responses.append(last)
    
    if not responses:
        return "No response"
    
    content = getattr(responses[-1], "content", "")
    return content if isinstance(content, str) else str(content)

# 4. Define the entrypoint function for AgentCore to invoke
@app.entrypoint
async def invoke(payload, context):
    try:
        log.info("Invoke received")
        user_input = payload.get("prompt", "")
        session_id = payload.get("session_id", "default-session")
        
        if not user_input.strip():
            return {"error": "Prompt cannot be empty"}
        
        response = await run_agent(user_input, session_id)
        return {"response": response}
    except Exception as e:
        log.error(f"Error: {e}")
        return {"error": str(e)}

# 5. Run locally using `agentcore dev`
if __name__ == "__main__":
    app.run()

Key points:

  • BedrockAgentCoreApp() initializes the runtime, including health checks and logging.
  • The graph is built at module load time to catch startup errors early.
  • The @app.entrypoint decorator marks the handler for incoming requests.
  • The session_id is mapped to thread_id in LangGraph for per-session memory.

Step 4: Create an AgentCore Project

Initialize a new AgentCore project using the CLI’s project generator:

agentcore create

The setup assistant will prompt you for basic details such as project name, Python version, and AWS region. It generates a structured project layout optimized for AgentCore development.

Step 5: Deploy the Agent to AWS

With your project scaffolded and entrypoint defined, deploy the agent to AWS:

agentcore deploy

This command uses AWS CDK to provision the necessary cloud resources—Lambda, API Gateway, IAM roles, and logging infrastructure—based on your configuration. The deployment is serverless, scalable, and fully managed by AWS.

Once deployed, you can invoke your agent via the generated API endpoint or AWS console.

Final Thoughts: Focus on AI Logic, Not Infrastructure

Migrating AI agents from local development to production no longer requires deep DevOps expertise or infrastructure redesign. AWS Bedrock AgentCore abstracts away the complexity, allowing developers to concentrate on refining agent behavior and capabilities.

By wrapping your LangGraph agent with AgentCore, you gain access to a robust, scalable, and observable deployment platform—all with minimal code changes. This shift empowers teams to iterate faster, scale seamlessly, and deploy with confidence across global AWS regions.

Start with a small agent, test locally, and scale effortlessly to thousands of concurrent users without lifting a finger on infrastructure management.

AI summary

Learn how to deploy LangGraph AI agents on AWS Bedrock AgentCore using serverless infrastructure and the AgentCore CLI for seamless scaling and management.

Comments

00
LEAVE A COMMENT
ID #OY66S9

0 / 1200 CHARACTERS

Human check

5 + 5 = ?

Will appear after editor review

Moderation · Spam protection active

No approved comments yet. Be first.