Skip to content

Bug: "Channel already exists with a different type" error when multiple StateGraphs share field schemas #1820

@Abdurihim

Description

@Abdurihim

Description

Related to langchain-ai/deepagentsjs#75

When using middleware that adds state fields (like filesystem middleware) in both main agents and subagents, a Channel already exists with a different type error is thrown, even though the channel types are identical.

This issue was originally reported in the deepagentsjs repository where users encountered this error when creating agents with middleware.

Minimal Reproduction Repository

🔗 https://github.com/Abdurihim/langgraphjs-issue-1820-reproduction

This repository provides two reproduction methods:

  1. Real-world scenario: Using deepagents library (reproduces the exact error users encounter)
  2. Standalone test: Pure unit test without external APIs

Steps to Reproduce

Method 1: Using deepagents (recommended)

git clone https://github.com/Abdurihim/langgraphjs-issue-1820-reproduction
cd langgraphjs-issue-1820-reproduction
npm install
cp .env.example .env
# Add your OPENAI_API_KEY to .env
npm run reproduce-deepagents

Method 2: Standalone unit test

npm run reproduce-bug

Error Output

Error: Channel "files" already exists with a different type.
    at StateGraph._addSchema (/node_modules/@langchain/langgraph/src/graph/state.ts:516:19)
    at new StateGraph (/node_modules/@langchain/langgraph/src/graph/state.ts:460:10)
    at new ReactAgent (/node_modules/langchain/src/agents/ReactAgent.ts:205:22)
    at createAgent (/node_modules/langchain/src/agents/index.ts:418:10)
    at getSubagents (deepagents/dist/index.js:884:31)
    at createTaskTool (deepagents/dist/index.js:917:73)
    at createSubAgentMiddleware (deepagents/dist/index.js:953:11)
    at createDeepAgent (deepagents/dist/index.js:1897:3)

Expected Behavior

StateGraph should accept schemas that share the same field schema definitions without throwing errors, since the channel types are identical.

Actual Behavior

StateGraph._addSchema uses identity comparison (!==) to check for channel conflicts. Since getChannelsForSchema creates new channel instances each time it's called, even identical channel types fail the identity check.

Environment

  • @langchain/langgraph: 1.0.4
  • deepagents: 1.3.1
  • langchain: 1.2.0
  • zod: 3.24.1
  • Node.js: 20.x

Impact

This prevents using middleware patterns where state fields are shared between main agents and subagents, which is a common use case in multi-agent systems and is blocking users of deepagentsjs.

Fix

A fix is submitted in #1819

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions