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

Support streaming events #384

Merged
merged 8 commits into from
Nov 14, 2024
Merged

Support streaming events #384

merged 8 commits into from
Nov 14, 2024

Conversation

jlowin
Copy link
Member

@jlowin jlowin commented Nov 14, 2024

This pull request introduces a new streaming feature to the ControlFlow library, allowing for real-time processing of events during task execution. It also includes significant updates to the documentation and several codebase improvements to support this new functionality.

import controlflow as cf

for event, snapshot, delta in cf.run("Write a poem about AI", stream=True):
    # For complete events, snapshot contains the full content
    if event.event == "agent-content":
        print(f"Agent wrote: {snapshot}")
    
    # For delta events, delta contains just what's new
    elif event.event == "agent-content-delta":
        print(delta, end="", flush=True)

To automatically filter for common event types, use the stream flags

import controlflow as cf

for event, snapshot, delta in cf.run(
    "Write a poem",
    stream=cf.Stream.CONTENT | cf.Stream.TOOLS,
):
    print(delta if delta else snapshot)

New Streaming Feature:

Codebase Enhancements:

Documentation Updates:

  • docs/mint.json: Added the new patterns/streaming-tasks document to the list of documentation patterns.

Event Handling Improvements:

These changes collectively enhance the ControlFlow library by introducing real-time event streaming capabilities, improving the documentation, and refining the event handling mechanisms.

@github-actions github-actions bot added documentation Improvements or additions to documentation tests Adds or improves unit tests labels Nov 14, 2024
@github-actions github-actions bot added enhancement Enhance an existing feature feature New feature that doesn't exist today labels Nov 14, 2024
@jlowin jlowin merged commit b26c8c8 into main Nov 14, 2024
4 checks passed
@jlowin jlowin deleted the stream branch November 14, 2024 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement Enhance an existing feature feature New feature that doesn't exist today tests Adds or improves unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant