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

There's no way to update state with updates that are different from the state type #121

Open
davidfant opened this issue Apr 25, 2024 · 1 comment

Comments

@davidfant
Copy link

Moving from Slack: https://langchainpart-saq4831.slack.com/archives/C06PTQF6MCK/p1714034843538009

Current types for the state:

export type BinaryOperator<Value> = (a: Value, b: Value) => Value;

export interface StateGraphArgs<Channels extends Record<string, any>> {
    channels: {
        [K in keyof Channels]: {
            value: BinaryOperator<Channels[K]> | null;
            default?: () => Channels[K];
        } | string;
    } | {
        value: BinaryOperator<unknown> | null;
        default?: () => unknown;
    };
}

What I want to do:

interface AgentState {
  messages: Messages[];
}

// this looks like how you suggest managing msgs in examples
const channels = {
  messages: (oldMsgs, newMsgs) => [...oldMsgs, ...newMsgs],
}

// to add a message, i'd return a state update like
return { messages: [newMessage] };

However, if I want to update messages in a different way than just appending (say e.g. clearing all msgs) I can't do that bc the BinaryOperator type requires a (curr value) and b (the update value, which could in theory have a different shape) to be the same

@davidfant
Copy link
Author

@functorism might have some good ideas on typing for this

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