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/langgraphwebStateSchema
Class●Since v0.3

StateSchema

StateSchema provides a unified API for defining LangGraph state schemas.

Copy
class StateSchema

Used in Docs

  • Agents
  • Build a custom SQL agent
  • Build a multi-source knowledge base with routing
  • Build a RAG agent with LangChain
  • Build a SQL assistant with on-demand skills
(7 more not shown)

Example

Copy
import { z } from "zod";
import { StateSchema, ReducedValue, MessagesValue } from "@langchain/langgraph";

const AgentState = new StateSchema({
  // Prebuilt messages value
  messages: MessagesValue,
  // Basic LastValue channel from any standard schema
  currentStep: z.string(),
  // LastValue with native default
  count: z.number().default(0),
  // ReducedValue for fields needing reducers
  history: new ReducedValue(
    z.array(z.string()).default(() => []),
    {
      inputSchema: z.string(),
      reducer: (current, next) => [...current, next],
    }
  ),
});

// Extract types
type State = typeof AgentState.State;
type Update = typeof AgentState.Update;

// Use in StateGraph
const graph = new StateGraph(AgentState);

Constructors

constructor
constructor

Properties

property
fields: TFields
property
Node: RunnableLike<InferStateSchemaValue<TFields>, InferStateSchemaUpdate<TFields>>
property
State: InferStateSchemaValue<TFields>

Type declaration for the full state type. Use: typeof myState.State

property
Update: InferStateSchemaUpdate<TFields>

Type declaration for the update type. Use: typeof myState.Update

Methods

method
getAllKeys→ string[]

Get all keys (channels + managed values).

method
getChannelKeys→ string[]

Get the list of channel keys (excluding managed values).

method
getChannels→ Record<string, BaseChannel>

Get the channel definitions for use with StateGraph. This converts the StateSchema fields into BaseChannel instances.

method
getInputJsonSchema→ JsonSchema7Type

Get the JSON schema for the update/input type. All fields are optional in updates.

method
getJsonSchema→ JsonSchema7Type

Get the JSON schema for the full state type. Used by Studio and API for schema introspection.

method
validateInput→ Promise<T>

Validate input data against the schema. This validates each field using its corresponding schema.

method
isInstance→ value is ReducedValue<Value, Input>

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

View source on GitHub