Skip to content

Rename empty() to fromCheckpoint() to match LangGraph Python#118

Merged
Nuno Campos (nfcampos) merged 6 commits intolangchain-ai:mainfrom
andrewnguonly:migrate-channels
Apr 18, 2024
Merged

Rename empty() to fromCheckpoint() to match LangGraph Python#118
Nuno Campos (nfcampos) merged 6 commits intolangchain-ai:mainfrom
andrewnguonly:migrate-channels

Conversation

@andrewnguonly
Copy link
Copy Markdown
Contributor

@andrewnguonly Andrew Nguonly (andrewnguonly) commented Apr 17, 2024

Summary

All files in the channels directory are updated to match the corresponding naming and implementation in LangGraph Python.

Implementation

  1. Rename empty() to fromCheckpoint() in BaseChannel class.
  2. Update implementation of update() methods to return last element of values array.

To Do

  • Figure out if BaseChannel.createCheckpoint() is equivalent to the Python implementation.
  • Do we want to remove initialValueFactory API from BaseChannel? The API doesn't exist in the Python implementation. Static function StateGraph._getChannels() depends on this interface.

Future

  1. Remove guard API from EphemeralValue. It's not needed anymore.
  2. Make NamedBarrierValue.update() transactional (this.seen can be partially updated).

I'm keeping track of these items separately.


// eslint-disable-next-line prefer-destructuring
this.value = values[0];
this.value = values[values.length - 1];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// eslint-disable-next-line prefer-destructuring
this.value = values[0];
this.value = values[values.length - 1];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// eslint-disable-next-line prefer-destructuring
this.value = values[0];
this.value = values[values.length - 1];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
abstract empty(
checkpoint?: CheckpointType,
initialValueFactory?: () => CheckpointType
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialValueFactory is removed from BaseChannel, but it remains in BinaryOperatorAggregate.

channelValues: { ...checkpoint.channelValues },
channelVersions: { ...checkpoint.channelVersions },
versionsSeen: { ...checkpoint.versionsSeen },
channelValues: deepCopy(checkpoint.channelValues),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkpoint.channelValues and checkpoint.channelVersions don't need to be deep copied. They can be set to an empty object so previous channel values aren't carried over. This is equivalent to Python implementation.

@nfcampos Nuno Campos (nfcampos) merged commit 79345a0 into langchain-ai:main Apr 18, 2024
@andrewnguonly Andrew Nguonly (andrewnguonly) deleted the migrate-channels branch April 18, 2024 17:32
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

Successfully merging this pull request may close these issues.

2 participants