The plan function in ControlFlow extends the capabilities of AI workflows by allowing dynamic generation of tasks. This feature allows you to leverage AI for creating structured, goal-oriented task sequences programmatically.

Purpose of AI planning

While ControlFlow allows manual creation of tasks for AI workflows, there are scenarios where automatically generating tasks can be beneficial:

  1. Dynamic Task Generation: When the specific steps to achieve a goal aren’t known in advance.
  2. Complex Problem Decomposition: For objectives that require breaking down into subtasks based on context or intermediate results.
  3. Adaptive Workflows: In processes that need to adjust based on changing conditions or new information.

The plan function

The plan function takes a high-level objective and generates a structured sequence of tasks to achieve that goal. Here’s a basic example:

import controlflow as cf

tasks = cf.plan(
    objective="Analyze customer feedback data",
    n_tasks=3  # Optionally specify the number of tasks
)

# Execute the generated plan
cf.run_tasks(tasks)

In this example, plan will generate a list of 3 tasks that, when completed, should result in an analysis of customer feedback data. These tasks might include steps like “Load data”, “Preprocess text”, “Perform sentiment analysis”, etc.

Dependencies

If appropriate, plan can generate tasks that depend on each other or have parent/child relationships. You can influence this behavior by providing instructions.

Agents and tools

You can pass a list of agents or tools to the plan function. It will take these into account when generating tasks and assign agents or tools to tasks as needed.