Multiple schemas cannot be compiled #142

Closed
opened 2026-02-15 17:16:14 -05:00 by yindo · 2 comments
Owner

Originally created by @phuo1032 on GitHub (Dec 11, 2024).

Following the guide here: https://langchain-ai.github.io/langgraphjs/concepts/low_level/#multiple-schemas

import { Annotation, StateGraph } from "@langchain/langgraph";

const InputStateAnnotation = Annotation.Root({
  user_input: Annotation<string>,
});

const OutputStateAnnotation = Annotation.Root({
  graph_output: Annotation<string>,
});

const OverallStateAnnotation = Annotation.Root({
  foo: Annotation<string>,
  bar: Annotation<string>,
  user_input: Annotation<string>,
  graph_output: Annotation<string>,
});

const node1 = async (state: typeof InputStateAnnotation.State) => {
  // Write to OverallStateAnnotation
  return { foo: state.user_input + " name" };
};

const node2 = async (state: typeof OverallStateAnnotation.State) => {
  // Read from OverallStateAnnotation, write to OverallStateAnnotation
  return { bar: state.foo + " is" };
};

const node3 = async (state: typeof OverallStateAnnotation.State) => {
  // Read from OverallStateAnnotation, write to OutputStateAnnotation
  return { graph_output: state.bar + " Lance" };
};

const graph = new StateGraph({
  input: InputStateAnnotation,
  output: OutputStateAnnotation,
  stateSchema: OverallStateAnnotation,
})
  .addNode("node1", node1)
  .addNode("node2", node2)
  .addNode("node3", node3)
  .addEdge("__start__", "node1")
  .addEdge("node1", "node2")
  .addEdge("node2", "node3")
  .compile();

await graph.invoke({ user_input: "My" });

While this can be run from LangGraph studio, in VSCode there is an error on this line:

  stateSchema: OverallStateAnnotation,
Type 'AnnotationRoot<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>' is not assignable to type 'AnnotationRoot<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.
  Types of property 'Node' are incompatible.
    Type 'NodeType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>' is not assignable to type 'NodeType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.
      Type 'RunnableFunc<StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>, UpdateType<...> | Partial<...>, RunnableCon...' is not assignable to type 'NodeType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.
        Type 'RunnableFunc<StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>, UpdateType<...> | Partial<...>, RunnableCon...' is not assignable to type 'RunnableFunc<StateType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>, UpdateType<...> | Partial<...>, RunnableConfig<...>>'.
          Type 'StateType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>' is missing the following properties from type 'StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>': foo, bar, graph_outputts(2322)
Originally created by @phuo1032 on GitHub (Dec 11, 2024). Following the guide here: https://langchain-ai.github.io/langgraphjs/concepts/low_level/#multiple-schemas ``` import { Annotation, StateGraph } from "@langchain/langgraph"; const InputStateAnnotation = Annotation.Root({ user_input: Annotation<string>, }); const OutputStateAnnotation = Annotation.Root({ graph_output: Annotation<string>, }); const OverallStateAnnotation = Annotation.Root({ foo: Annotation<string>, bar: Annotation<string>, user_input: Annotation<string>, graph_output: Annotation<string>, }); const node1 = async (state: typeof InputStateAnnotation.State) => { // Write to OverallStateAnnotation return { foo: state.user_input + " name" }; }; const node2 = async (state: typeof OverallStateAnnotation.State) => { // Read from OverallStateAnnotation, write to OverallStateAnnotation return { bar: state.foo + " is" }; }; const node3 = async (state: typeof OverallStateAnnotation.State) => { // Read from OverallStateAnnotation, write to OutputStateAnnotation return { graph_output: state.bar + " Lance" }; }; const graph = new StateGraph({ input: InputStateAnnotation, output: OutputStateAnnotation, stateSchema: OverallStateAnnotation, }) .addNode("node1", node1) .addNode("node2", node2) .addNode("node3", node3) .addEdge("__start__", "node1") .addEdge("node1", "node2") .addEdge("node2", "node3") .compile(); await graph.invoke({ user_input: "My" }); ``` While this can be run from LangGraph studio, in VSCode there is an error on this line: ``` stateSchema: OverallStateAnnotation, ``` ``` Type 'AnnotationRoot<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>' is not assignable to type 'AnnotationRoot<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'. Types of property 'Node' are incompatible. Type 'NodeType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>' is not assignable to type 'NodeType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'. Type 'RunnableFunc<StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>, UpdateType<...> | Partial<...>, RunnableCon...' is not assignable to type 'NodeType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'. Type 'RunnableFunc<StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>, UpdateType<...> | Partial<...>, RunnableCon...' is not assignable to type 'RunnableFunc<StateType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>, UpdateType<...> | Partial<...>, RunnableConfig<...>>'. Type 'StateType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>' is missing the following properties from type 'StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>': foo, bar, graph_outputts(2322) ```
yindo closed this issue 2026-02-15 17:16:14 -05:00
Author
Owner

@azhong-git commented on GitHub (Jan 31, 2025):

+1 on this. It seems that it complains on the overall state schema containing a field in input state (question in this following example):

const InputStateAnnotation = Annotation.Root({
  question: Annotation<string>,
});

const OutputStateAnnotation = Annotation.Root({
  answer: Annotation<string>,
});

const OverallStateAnnotation = Annotation.Root({
  // somehow this following line has to be commented out to prevent warning
  // https://github.com/langchain-ai/langgraphjs/issues/737
  question: Annotation<string>,
  answer: Annotation<string>,
  notes: Annotation<string[]>({
    reducer: (state: string[], update: string[]) => state.concat(update),
  }),
});

const builder = new StateGraph({
  input: InputStateAnnotation,
  output: OutputStateAnnotation,
  // Saw error on this line
  stateSchema: OverallStateAnnotation,
})
Type 'AnnotationRoot<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; answer: { ...; }; notes: BinaryOperatorAggregate<...>; }>' is not assignable to type 'AnnotationRoot<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.
  Types of property 'Node' are incompatible.
    Type 'NodeType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; answer: { ...; }; notes: BinaryOperatorAggregate<...>; }>' is not assignable to type 'NodeType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.
      Type 'RunnableFunc<StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; answer: { ...; }; notes: BinaryOperatorAggregate<...>; }>, UpdateType<...> | Partial<...>, RunnableConf...' is not assignable to type 'NodeType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.
        Type 'RunnableFunc<StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; answer: { ...; }; notes: BinaryOperatorAggregate<...>; }>, UpdateType<...> | Partial<...>, RunnableConf...' is not assignable to type 'RunnableFunc<StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>, UpdateType<...> | Partial<...>, RunnableConfig<...>>'.
          Type 'StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>' is missing the following properties from type 'StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; answer: { ...; }; notes: BinaryOperatorAggregate<...>; }>': answer, notests(2322)

@azhong-git commented on GitHub (Jan 31, 2025): +1 on this. It seems that it complains on the overall state schema containing a field in input state (`question` in this following example): ```typescript const InputStateAnnotation = Annotation.Root({ question: Annotation<string>, }); const OutputStateAnnotation = Annotation.Root({ answer: Annotation<string>, }); const OverallStateAnnotation = Annotation.Root({ // somehow this following line has to be commented out to prevent warning // https://github.com/langchain-ai/langgraphjs/issues/737 question: Annotation<string>, answer: Annotation<string>, notes: Annotation<string[]>({ reducer: (state: string[], update: string[]) => state.concat(update), }), }); const builder = new StateGraph({ input: InputStateAnnotation, output: OutputStateAnnotation, // Saw error on this line stateSchema: OverallStateAnnotation, }) ``` ``` type error Type 'AnnotationRoot<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; answer: { ...; }; notes: BinaryOperatorAggregate<...>; }>' is not assignable to type 'AnnotationRoot<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'. Types of property 'Node' are incompatible. Type 'NodeType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; answer: { ...; }; notes: BinaryOperatorAggregate<...>; }>' is not assignable to type 'NodeType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'. Type 'RunnableFunc<StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; answer: { ...; }; notes: BinaryOperatorAggregate<...>; }>, UpdateType<...> | Partial<...>, RunnableConf...' is not assignable to type 'NodeType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'. Type 'RunnableFunc<StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; answer: { ...; }; notes: BinaryOperatorAggregate<...>; }>, UpdateType<...> | Partial<...>, RunnableConf...' is not assignable to type 'RunnableFunc<StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>, UpdateType<...> | Partial<...>, RunnableConfig<...>>'. Type 'StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>' is missing the following properties from type 'StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; answer: { ...; }; notes: BinaryOperatorAggregate<...>; }>': answer, notests(2322) ```
Author
Owner

@dqbd commented on GitHub (Jun 17, 2025):

Hello! This should be already fixed! Feel free to reopen if the issue still persists

@dqbd commented on GitHub (Jun 17, 2025): Hello! This should be already fixed! Feel free to reopen if the issue still persists
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#142