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

createReactAgent does not support stateModifier with custom stateSchema types #803

Open
luizzappa opened this issue Jan 25, 2025 · 1 comment

Comments

@luizzappa
Copy link

Issue Description

The createReactAgent function does not accept a stateSchema different from MessagesAnnotation.

Current Behavior

When trying to use a custom stateSchema, the linter throws an error as shown below:

Image

Image

import { ChatOpenAI } from "@langchain/openai";
import { Annotation} from "@langchain/langgraph";
import { MessagesAnnotation } from "@langchain/langgraph";
import { createReactAgent } from '@langchain/langgraph/prebuilt';

const StateAnnotation = Annotation.Root({
  ...MessagesAnnotation.spec,
  // user provided
  lastName: Annotation<string>,
  // updated by the tool
  userInfo: Annotation<Record<string, any>>,
  });

const stateModifier = (state: typeof StateAnnotation.State) => {
  const userInfo = state.userInfo;
  if (userInfo == null) {
    return state.messages;
  }
  const systemMessage = `User name is ${userInfo.name}. User lives in ${userInfo.location}`;
  return [{
    role: "system",
    content: systemMessage,
  }, ...state.messages];
};

const model = new ChatOpenAI({
  model: "gpt-4o",
});

const agent = createReactAgent({
  llm: model,
  stateSchema: StateAnnotation,
  stateModifier: stateModifier,
})

Additional Information

Repository Version: "@langchain/langgraph": "^0.2.38",

@jacoblee93
Copy link
Collaborator

Thanks for flagging, will have a look

@jacoblee93 jacoblee93 changed the title createReactAgent does not support custom stateSchema types createReactAgent does not support stateModifier with custom stateSchema types Jan 29, 2025
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

2 participants