Make Flow-Level Context Arguments Explicit and Opt-in #341
Labels
breaking change
The public API changes in a backwards-incompatible way
enhancement
Enhance an existing feature
Enhancement Description
Currently, when arguments are passed to a
@cf.flow
method, they are implicitly added to a flow-wide context, making them available to all tasks within that flow. While this allows for convenient sharing of context between tasks, it can result in redundancy and confusion, especially when certain arguments are only relevant at the flow level and not to individual tasks. For example, arguments passed to the flow can show up twice in the agent’s context, once as a flow argument and again if explicitly passed as a task context.This implicit behavior has led to cases where users have to work around it by defining their
@cf.flow
as an inner method or explicitly managing the task context. As a result, the implicit context addition can feel too “magical” and can cause unintended token usage increases in LLM interactions.Use Case
No response
Proposed Implementation
Two potential solutions:
flow_context
(or similar) keyword argument:Allow users to specify which arguments should be added to the context when calling a flow.
This way, only explicitly defined arguments (e.g., via
context={...}
) are passed, avoiding automatic duplication.@flow(context_kwargs=['x', 'z'])
decorator feature:Allow users to declare which arguments should automatically be added to the flow context at the decorator level.
We are leaning strongly toward option 2, as it permits the full argument convention while remaining explicit and opt-in
The text was updated successfully, but these errors were encountered: