LangGraph Comprehensive Agent
A LangGraph agent demonstrating multiple AgentCore capabilities in a single deployment: custom Lambda tools, a direct MCP server connection, web browsing, code execution, and conversation memory.
What This Example Shows
- Gateway Tools: Lambda function (calculator) via AgentCore Gateway
- Direct MCP Server: AWS Knowledge MCP connected directly from agent code (public endpoint, no gateway needed)
- Default Browser: Web navigation and content extraction via
PlaywrightBrowser - Default Code Interpreter: Sandboxed code execution via
CodeInterpreter - Memory: Conversation persistence with
list_eventstool and automatic saving - Auto-build: No Dockerfile needed -- the framework builds the image from source via buildpacks
agents/directory: Agent code lives inagents/index.js, not the project root
Architecture
User Request --> AgentCore Runtime --> agents/index.js
|
LangGraph ReAct Agent
|
Claude Sonnet
|
+----------+----------+----------+----------+------+
| | | | | |
Gateway MCP Direct MCP Browser Code Interp. Memory Direct
| | Response
Calculator AWS Knowledge
(Lambda) (public MCP)
Prerequisites
- AWS account with Bedrock model access (Claude Sonnet)
- Enable
global.anthropic.claude-sonnet-5(the default; override via theMODEL_IDenv var) in the Bedrock console - Docker installed
- Serverless Framework v4+
- AWS credentials configured
Quick Start
1. Deploy
serverless deploy
The framework will:
- Auto-build a Docker image from source (no Dockerfile needed)
- Push to Amazon ECR
- Deploy the Calculator Lambda function
- Create an AgentCore Gateway with the calculator tool
- Create AgentCore Memory (30-day expiration)
- Deploy AgentCore Runtime
2. Test
RUNTIME_ARN=<your-runtime-arn> node test-invoke.js
Get the runtime ARN from serverless info.
3. Local Development
serverless dev
How It Works
Configuration
The serverless.yml defines a calculator Lambda tool in the gateway:
ai:
tools:
calculator:
function: calculatorFunction # Lambda tool via gateway
toolSchema: [...]
agents:
assistant:
memory:
expiration: 30
The calculator tool is automatically placed in an auto-created default gateway. The AWS Knowledge MCP server is connected directly from the agent code (no gateway needed).
Tool Sources
The agent in agents/index.js combines six tool sources:
- Gateway tools -- calculator Lambda discovered via
BEDROCK_AGENTCORE_GATEWAY_URLusing MCP protocol with SigV4 auth - Direct MCP tools -- AWS Knowledge MCP server (
https://knowledge-mcp.global.api.aws) connected directly (public endpoint, no auth) - Browser tools --
PlaywrightBrowserwrapped as LangChain tools (navigate, get_text, click, screenshot) - Code interpreter tools --
CodeInterpreterwrapped as LangChain tools (execute_code, execute_command) - Memory tool --
list_eventsusingListEventsCommandfrom the AWS SDK - Memory saving -- automatic
CreateEventCommandafter each response
All tools are merged and passed to createAgent, which lets Claude decide which tool to use.
Auto-build
With no Dockerfile present, the framework uses Heroku buildpacks to build the image. It reads package.json and uses the scripts.start field (node agents/index.js) as the entry point.
Requirements for auto-build:
package.jsonwith astartscript- A lockfile (
package-lock.json)
Files
| File | Purpose |
|---|---|
serverless.yml | Infrastructure configuration |
agents/index.js | LangGraph agent combining all tool sources |
handlers/calculator.js | Calculator Lambda function (gateway tool) |
package.json | Dependencies and start script for auto-build |
test-invoke.js | Test script exercising each tool type |
Cleanup
serverless remove
Related Examples
- LangGraph Gateway -- Gateway tools only
- LangGraph Browser -- Browser only
- LangGraph Code Interpreter -- Code interpreter only
- LangGraph Memory -- Memory only
- LangGraph Multi-Gateway -- Multiple gateways with different authorization