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/langgraph-sdkreactInferSubagentState
Type●Since v1.6

InferSubagentState

Infer the state type for a specific subagent by extracting and merging its middleware state schemas, plus the base agent state (messages).

Copy
InferSubagentState: InferSubagentByName<
  T,
  TName
> extends never  Record<string, unknown> : InferSubagentByName<T, TName> extends SA  BaseSubagentState<ToolCall>  InferMiddlewareStatesFromArray<ExtractSubAgentMiddleware<SA>> : Record<string, unknown>

Example

Copy
const agent = createDeepAgent({
  subagents: [
    { name: "researcher", middleware: [ResearchMiddleware] }
  ] as const,
});

type ResearcherState = InferSubagentState<typeof agent, "researcher">;
// ResearcherState includes { messages: Message<ToolCall>[], ...ResearchMiddleware state }
View source on GitHub