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

Streaming section of Using ControlFlow - Running Tasks fails #402

Open
bw-matthew opened this issue Jan 20, 2025 · 0 comments
Open

Streaming section of Using ControlFlow - Running Tasks fails #402

bw-matthew opened this issue Jan 20, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@bw-matthew
Copy link

Description

When I run the example code for streaming responses I get a pydantic type validation error.

The pydantic type for the Task has changed since this was written and the stream property was removed.
As the cf.run method passes all unrecognized keyword arguments to the Task constructor, and the Task type rejects additional properties, the code now causes an exception.

The error follows:

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[7], line 4
      1 import controlflow as cf
      3 # Stream all events
----> 4 for event, snapshot, delta in cf.run("Write a poem", stream=True, handlers=[]):
      5     print(f"Event type: {event.event}")
      7     if event.event == "agent-content":

File [~/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/controlflow/run.py:127](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/controlflow/run.py#line=126), in run(objective, turn_strategy, max_llm_calls, max_agent_turns, raise_on_failure, handlers, model_kwargs, run_until, **task_kwargs)
    115 def run(
    116     objective: str,
    117     *,
   (...)
    125     **task_kwargs,
    126 ) -> Any:
--> 127     task = Task(objective=objective, **task_kwargs)
    128     results = run_tasks(
    129         tasks=[task],
    130         raise_on_failure=raise_on_failure,
   (...)
    136         run_until=run_until,
    137     )
    138     return results[0]

File [~/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/controlflow/tasks/task.py:224](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/controlflow/tasks/task.py#line=223), in Task.__init__(self, objective, user_access, **kwargs)
    218     warnings.warn(
    219         "The `user_access` argument is deprecated. Use `interactive=True` instead.",
    220         DeprecationWarning,
    221     )
    222     kwargs["interactive"] = True
--> 224 super().__init__(**kwargs)
    226 # create dependencies to tasks passed in as depends_on
    227 for task in self.depends_on:

File [~/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/pydantic/main.py:212](http://127.0.0.1:8889/home/matthew/.cache/pypoetry/virtualenvs/ask-anything-d4NqA-em-py3.12/lib/python3.12/site-packages/pydantic/main.py#line=211), in BaseModel.__init__(self, **data)
    210 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    211 __tracebackhide__ = True
--> 212 validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
    213 if self is not validated_self:
    214     warnings.warn(
    215         'A custom validator is returning a value other than `self`.\n'
    216         "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n"
    217         'See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
    218         category=None,
    219     )

ValidationError: 1 validation error for Task
stream
  Extra inputs are not permitted [type=extra_forbidden, input_value=True, input_type=bool]
    For further information visit https://errors.pydantic.dev/2.9/v/extra_forbidden

Fundamentally this is because the 0.12.0 version of control flow has not been released to pypi!
https://pypi.org/project/controlflow/#history

Example Code

import controlflow as cf

# Stream all events
for event, snapshot, delta in cf.run("Write a poem", stream=True, handlers=[]):
    print(f"Event type: {event.event}")
    
    if event.event == "agent-content":
        print(f"Agent said: {snapshot}")
    elif event.event == "agent-tool-call":  
        print(f"Tool called: {snapshot}")

Version Information

ControlFlow version: 0.11.4
       Prefect version: 3.1.13
LangChain Core version: 0.3.30
        Python version: 3.12.7
              Platform: Linux-6.8.0-51-generic-x86_64-with-glibc2.39

Additional Context

No response

@bw-matthew bw-matthew added the bug Something isn't working label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant