Skip to content

Langgraph / InternalAnnotation typing issue #1651

@hitmands

Description

@hitmands

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).

Example Code

const PrivateAnnotation = Annotation.Root({
  ...MessagesAnnotation.spec,
  count: Annotation<number>,
});

type State = typeof PrivateAnnotation.State;

const graph = new StateGraph(MessagesAnnotation);

graph
  .addNode('a', (state: State) => ({ count: 5 }), { input: PrivateAnnotation })
  .addNode('b', (state: State) => state, { input: PrivateAnnotation })
  .addNode('c', (state: State) => state, { input: PrivateAnnotation })
;

graph
  .addEdge('__start__', 'a')

  // Cannot be typed, although the private state is passed.
  .addConditionalEdge('a', (state: State) => random() > state.count ? 'b' : 'c');

graph.compile();

Error Message and Stack Trace (if applicable)

Type 'StateType<{ messages: BinaryOperatorAggregate<BaseMessage[], Messages>; }>' is missing the following properties from ...

Description

In scenarios like the Supervisor pattern, subgraphs are required to share the same parent-graph annotation... Although, it's useful for some subgraphs to also have an internal state. This is possible and it works fine, but it's not typesafe.

System Info

{
  "@langchain/core": "^0.3.75",
  "@langchain/langgraph": "^0.4.9",
  "@langchain/langgraph-checkpoint": "^0.1.1",
  "@langchain/langgraph-supervisor": "^0.0.19",
  "@langchain/mcp-adapters": "^0.6.0",
  "@langchain/openai": "0.6.11",
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions