LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • 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
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServer
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

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
(6 more not shown)

Constructors

Properties

Methods

View source on GitHub

Example

constructor
constructor
property
fields: TFields
property
Node: RunnableLike<InferStateSchemaValue<TFields>, InferStateSchemaUpdate<TFields>>
property
State: InferStateSchemaValue<TFields>
property
Update: InferStateSchemaUpdate<TFields>
method
getAllKeys→ string[]
method
getChannelKeys→ string[]
method
getChannels→ Record<string, BaseChannel>
method
getInputJsonSchema→ JsonSchema7Type
method
getJsonSchema→ JsonSchema7Type
method
validateInput→ Promise<T>
method
isInstance→ value is Overwrite<ValueType>

StateSchema provides a unified API for defining LangGraph state schemas.

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

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

Get all keys (channels + managed values).

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

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

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

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

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

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);