LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemote
LangGraph SDK
ClientAuthReactLoggingReact UiServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraphindexReducedValue
Class●Since v0.3

ReducedValue

Represents a state field whose value is computed and updated using a reducer function.

ReducedValue allows you to define accumulators, counters, aggregators, or other fields whose value is determined incrementally by applying a reducer to incoming updates.

Each time a new input is provided, the reducer function is called with the current output and the new input, producing an updated value. Input validation can be controlled separately from output validation by providing an explicit input schema.

Copy
class ReducedValue

Used in Docs

  • Build a multi-source knowledge base with routing
  • Graph API overview
  • INVALID_CONCURRENT_GRAPH_UPDATE
  • Persistence
  • Quickstart

Example 1

Copy
// Accumulator with distinct input validation
const Sum = new ReducedValue(z.number(), {
  inputSchema: z.number().min(1),
  reducer: (total, toAdd) => total + toAdd
});

Example 2

Copy
// Simple running max, using only the value schema
const Max = new ReducedValue(z.number(), {
  reducer: (current, next) => Math.max(current, next)
});

Constructors

constructor
constructor

Properties

property
inputSchema: SerializableSchema<unknown, Value | Input>

The schema used to validate reducer inputs. If not specified explicitly, this defaults to valueSchema.

property
InputType: Input

Represents the type that may be provided as input on each update.

property
jsonSchemaExtra: Record<string, unknown>
property
reducer: (current: Value, next: Input) => Value
property
valueSchema: SerializableSchema<unknown, Value>

The schema that describes the type of value stored in state (i.e., after reduction). Note: We use unknown for the input type to allow schemas with .default() wrappers, where the input type includes undefined.

property
ValueType: Value

Methods

method
isInstance→ value is ReducedValue<Value, Input>

Type guard to check if a value is a ReducedValue instance.

View source on GitHub