Orchestrating tasks and agents in your AI workflows.
Flow
object as a context manager, or using the @flow
decorator.
In both cases, the goal is to instantiate a flow that provides a shared context for all tasks and agents within the flow. The @flow decorator is the most portable and flexible way to create a flow, as it encapsulates the entire flow within a function that gains additional capabilities as a result, because it becomes a Prefect flow as well. However, the Flow
context manager can be used to quickly create flows for ad-hoc purposes.
@flow
decorator for most flows, as it is more capable, flexible, and portable. You should use the Flow
context manager primarily for nested or ad-hoc flows, when your primary goal is to create a shared thread for a few tasks.@flow
decorator@cf.flow
to any function. Any tasks run inside the decorated function will execute within the context of the same flow.
Flow property | Inferred from |
---|---|
name | The function’s name |
description | The function’s docstring |
context | The function’s arguments, if specified as context_kwargs (keyed by argument name) |
context_kwargs
when decorating your flow:
@flow
decorator or to the flow_kwargs
parameter when calling the decorated function.
Flow
object and context managerFlow
object directly. Most commonly, you’ll use the flow as a context manager to create a new thread for one or more tasks.
Flow
constructor, the flow will load any existing history (subject to the limitations of how you’ve configured history storage).
If you don’t provide a thread ID, one will be automatically generated for you.