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

BREAKING CHANGE: Remove state generic from graphs #824

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

samuelcolvin
Copy link
Member

This is passing except docs which I will update once we've agreed it's a good idea.

this is a step towards storing graph state in a database. My realization was that previously the graph had two things which defined state:

  • ctx.state
  • the node that was just run or is about to be run

If we get rid of ctx.state:

  • we remove one generic from basically everywhere graphs or nodes are defined
  • state is now encapsulated in just one object - the node
  • we have less weirdness around how to serialize/snapshot state

The point is, if you want a "state" object has we had before, you just need to pass it between nodes, which was happening under the hood anyway.

I think this makes graphs less complicated and less magic without adding significantly more ceremony or boilerplate.

@dmontagu let's discuss when you're online.

@Finndersen
Copy link

But doesn't this mean that now nodes have a state attribute that may contain content that's not even relevant/required by that node, and there's no real clear distinction between that state and the nodes other state attributes?

@samuelcolvin
Copy link
Member Author

But doesn't this mean that now nodes have a state attribute that may contain content that's not even relevant/required by that node, and there's no real clear distinction between that state and the nodes other state attributes?

That's kind of the point the "state" of a fsm IS which node it's on.

Having two states (the state thing, and the current node) makes many things including persisting state much more complex and messy.

Copy link
Contributor

@hyperlint-ai hyperlint-ai bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 total issue(s) found.

docs/graph.md Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to deploy-preview February 6, 2025 05:04 Inactive
Copy link
Contributor

@hyperlint-ai hyperlint-ai bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 total issue(s) found.

The style guide flagged several spelling errors that seemed like false positives. We skipped posting inline suggestions for the following words:

  • [Dd]eps

@samuelcolvin samuelcolvin changed the title Remove state generic from graphs BREAKING CHANGE: Remove state generic from graphs Feb 6, 2025
Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com>
@samuelcolvin samuelcolvin requested a review from dmontagu February 6, 2025 05:18
@samuelcolvin
Copy link
Member Author

@dmontagu please review.

@github-actions github-actions bot temporarily deployed to deploy-preview February 6, 2025 05:19 Inactive
Copy link
Member

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Wow, this really simplifies things. Nice to have 2 generics instead of 3.

uv.lock Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for catching this in this PR 👍

"""The node that was run."""
start_ts: datetime = field(default_factory=_utils.now_utc)
"""The timestamp when the node started running."""
duration: float | None = None
"""The duration of the node run in seconds."""
kind: Literal['node'] = 'node'
"""The kind of history step, can be used as a discriminator when deserializing history."""
# TODO waiting for https://github.com/pydantic/pydantic/issues/11264, should be an InitVar
Copy link
Member

Choose a reason for hiding this comment

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

Btw, PR merged and pc released with this fix, just not yet a major pydantic version :)

@github-actions github-actions bot temporarily deployed to deploy-preview February 6, 2025 20:07 Inactive
@dmontagu dmontagu force-pushed the remove-state-generic branch from cd35bae to 959946a Compare February 6, 2025 22:49
@github-actions github-actions bot temporarily deployed to deploy-preview February 6, 2025 22:53 Inactive
@Finndersen
Copy link

@samuelcolvin my point was more about how there's now less of a clear distinction between graph state and node state. Like when should a state attribute be put in GraphState vs a node attribute? When it needs to be used by more than one node?

Maybe it's a dumb idea but what if the distinction between "graph"and "node" state was removed so there's just node-level state attributes? I.e. Each Node only has the state info it either needs directly or to provide to another node

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.

4 participants