LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Agent
  • Middleware
  • Backends
  • Sandboxes
  • Skills
  • Subagents
  • Types
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
  • Vitest
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentstypesInferOptionalMiddleware
Type●Since v1.14

InferOptionalMiddleware

Middleware that createDeepAgent mounts only when the corresponding option is passed, expressed at the type level so the agent's state reflects it.

skills mounts SkillsMiddleware, which contributes skillsMetadata to state. Callers therefore get skillsMetadata on invoke/updateState purely from skills: [...], with no need to mount the middleware manually.

Mirrors the runtime condition skills != null && skills.length > 0: an omitted option or an empty literal (skills: []) mounts nothing and contributes no state. A non-literal string[] has no statically known length, so it is treated as mounting the middleware.

Copy
InferOptionalMiddleware: [TSkills] extends [undefined]  readonly [] : [TSkills] extends [readonly []]  readonly [] : readonly [SkillsMiddleware]
View source on GitHub