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

Graph run_stream #732

Open
asaf opened this issue Jan 21, 2025 · 7 comments
Open

Graph run_stream #732

asaf opened this issue Jan 21, 2025 · 7 comments
Labels
question Further information is requested

Comments

@asaf
Copy link

asaf commented Jan 21, 2025

Hey,

Graphs may take long time to execute, especially when dealing with multi agents with iterations,

Would love to see streaming graph execition

Effects #704 #695

@samuelcolvin samuelcolvin added the question Further information is requested label Jan 21, 2025
@samuelcolvin
Copy link
Member

I think you want Graph.next.

If you want to implement streaming within a node, you can just implement that as a new method on the node. I'll try to add an example soon.

@dmontagu
Copy link
Contributor

Also, if you want within-node streaming, I think our current plan is to combine the Graph.next referenced by Samuel above with a user-defined method on the node that does streaming, and then manually handling the streaming in the code that loops over the nodes via Graph.next. I am planning to take this approach to handling streaming in the Graph-based refactoring of pydantic_ai.Agent, so hopefully there will be an example soon.

@asaf
Copy link
Author

asaf commented Jan 24, 2025

I guess having stream() on the graph level could be nice but raises more complexity such when graphs should be interrupted (e.g., when human in the loop is required), so I see your point of the Graph.next.

Next() moves the execution flow entirely to the control of the user, which probably would work with any usecase.

Currently the Question Graph blocks until the entire result is returned.

@samuelcolvin invoking next() executes run of the current node, I assume we can:

  1. Add a new method on the node such stream()
  2. Invoke the stream() method manually and await for it to complete, which may modify the current node's object local state with the result of the stream.
  3. Invoke next() that invokes the run method on the current node, which can use the local object state set by the stream.
  4. Decide where to go next based on the object state plus optionally copy some state from local object to the graph's state.

@dmontagu
Copy link
Contributor

dmontagu commented Jan 24, 2025

Yes, this is precisely what we had in mind. It's reassuring to see someone else independently working out the details in the same way!

If you run into any issues achieving your goals while taking this approach, we'll definitely want to address them — please let us know.

@asaf
Copy link
Author

asaf commented Jan 24, 2025

I see your point :)
I'll keep this issue opened as a reminder to create a graph sample with streaming! 10x guys!

Copy link

github-actions bot commented Feb 1, 2025

This issue is stale, and will be closed in 3 days if no reply is received.

@github-actions github-actions bot added the Stale label Feb 1, 2025
@xflashxx
Copy link

xflashxx commented Feb 4, 2025

Eagerly waiting for this! ❤️

@github-actions github-actions bot removed the Stale label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants