• Documentation
  • Pricing
© 2026 Serverless, Inc. All rights reserved.

Framework

  • Overview
  • Documentation
  • Plugins360
  • Pricing

Learn

  • Blog
  • GuidesUpdated
  • Examples240
  • Courses

Resources

  • Support
  • Security
  • Trust Center
  • Status

Community

  • Slack
  • GitHub47k
  • Forum
  • Meetups

Company

  • About
  • Careers
  • Contact
  • Partners

Legal

  • Terms of Service
  • Privacy Policy
  • Trademark
  • DMCA
Serverless, inc.

Bedrock AgentCore: LangGraph Agent with Token Streaming (JavaScript)

by

LangGraph JS agent streaming LLM tokens in real time over SSE via BedrockAgentCoreApp.

  1. Bedrock AgentCore: LangGraph Agent with Token Streaming (JavaScript)

LangGraph JS Streaming Example

A LangGraph JavaScript agent with real-time LLM token streaming deployed to AWS Bedrock AgentCore. Tokens are streamed to the client via Server-Sent Events (SSE) as they are generated, instead of waiting for the full response.

Features

  • LLM Token Streaming: Tokens streamed in real-time via SSE as the model generates them
  • Async Generator Pattern: Uses async function* with yield for streaming through BedrockAgentCoreApp
  • No Dockerfile needed: Container image is built automatically from source code
  • LangGraph JS: ReAct agent pattern with tool calling
  • Claude Sonnet 5: Powered by Amazon Bedrock
  • Simple Tools: Calculator operations and time queries

How It Works

The key difference from the non-streaming langgraph-basic example is how the process handler works:

Non-streaming (langgraph-basic): process is an async function that returns the complete response after the agent finishes.

Streaming (this example): process is an async function* (async generator) that yields each LLM token as it is produced.

async *process(request, context) {
  const stream = await agent.stream(
    { messages: [{ role: 'user', content: request.prompt }] },
    { streamMode: 'messages' },
  )

  for await (const [message, metadata] of stream) {
    if (
      message._getType() === 'ai' &&
      message.content &&
      typeof message.content === 'string'
    ) {
      yield message.content
    }
  }
}

The BedrockAgentCoreApp runtime automatically detects the async generator and streams each yielded value to the client as an SSE event.

LangGraph Stream Modes

LangGraph supports three streaming modes (see LangGraph streaming docs):

ModeDescriptionUse Case
messagesStream individual LLM tokensReal-time text output (used in this example)
updatesEmit events after each graph nodeAgent progress tracking
customEmit custom data from tools via config.writerTool progress updates

This example uses streamMode: "messages" for token-level streaming.

Quick Start

Prerequisites

  • Node.js 20+
  • Docker
  • AWS credentials configured
  • Serverless Framework CLI (npm install -g serverless)

Install Dependencies

npm install

Deploy to AWS

sls deploy

Invoke Deployed Agent

# Via Serverless Framework CLI
sls invoke --agent assistant --data '{"prompt":"Write a haiku about streaming data."}'

# Plain string is also supported:
# sls invoke --agent assistant -d "Write a haiku about streaming data."

Test Streaming Locally

RUNTIME_ARN=<your-runtime-arn> node test-invoke.js

Remove

sls remove

Project Structure

langgraph-streaming/
├── serverless.yml    # Serverless Framework configuration
├── index.js          # LangGraph JS agent with streaming
├── package.json      # npm dependencies
├── test-invoke.js    # Test script for streaming invocation
└── README.md         # This file

Related Examples

  • langgraph-basic - Same agent without streaming (returns complete response)
  • langgraph-basic-dockerfile - Non-streaming agent with a Dockerfile

Contents

  • LangGraph JS Streaming Example
  • Features
  • How It Works
  • LangGraph Stream Modes
  • Quick Start
  • Prerequisites
  • Install Dependencies
  • Deploy to AWS
  • Invoke Deployed Agent
  • Test Streaming Locally
  • Remove
  • Project Structure
  • Related Examples

Related

GuidesPluginsExamplesSlack CommunitySupport