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

State Management doesn't works for objects #691

Open
alanlozano-coru opened this issue Nov 27, 2024 · 0 comments
Open

State Management doesn't works for objects #691

alanlozano-coru opened this issue Nov 27, 2024 · 0 comments

Comments

@alanlozano-coru
Copy link

When I use state management for the messages array it works, but when I'm trying to used them with an object doesn't works, actually I have my object like this:

const information = await bd.getInformation();
const GraphState = Annotation.Root({
    messages: Annotation<BaseMessage[]>({
      reducer: (x, y) => x.concat(y),
      default: () => [],
    }),
    userInfo: Annotation<UserInfo>({
      reducer: (x, y) => ({ ...x, ...y }),
      default: () => {
        console.log("SET INFO", information);
        return {
           name: information.name || "",
           age: information.age || 0,
        }
     },
    }),
});

The userInfo state is only used to read the default information, actually i don't want to update it, but the value that I ever get when I used on the node is the same:

SET INFO
{
name: "Bob",
age: 25
}

SUPERVISOR INFO
{
name: "user",
age: 0
}

This is an example about how I'm trying to use the state:

async function Supervisor(state: typeof GraphState.State) {
      const { messages, userInfo } = state;
      console.log("--- START SUPERVISOR ---");
      console.log("SUPERVISOR INFO", userInfo);

      const prompt = ChatPromptTemplate.fromTemplate(`... `);
      const llm = new ChatOpenAI({
        apiKey: openai_key,
        model: "gpt-4o-mini",
      });
      const response = await prompt.pipe(llm).invoke({ messages, userInfo });
      return {
        messages: [response],
      };
    }
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