Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple schemas cannot be compiled #737

Open
phuo1032 opened this issue Dec 12, 2024 · 0 comments
Open

Multiple schemas cannot be compiled #737

phuo1032 opened this issue Dec 12, 2024 · 0 comments

Comments

@phuo1032
Copy link

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant