General Introduction
ControlFlow is a Python framework developed by PrefectHQ focused on building and managing AI workflows. It provides a structured, developer-oriented framework for defining workflows and delegating tasks to Large Language Model (LLM) agents.ControlFlow is designed to simplify the development of complex AI applications without sacrificing control and transparency. Users can create discrete, observable tasks and assign one or more specialized AI agents to each task. By combining these tasks into a flow, users can orchestrate more complex behavior.
Function List
- Mission Center Architecture: Break down complex AI workflows into manageable, observable steps.
- Structured results: Bridging the gap between AI and traditional software through type-safe, validated outputs.
- Specialized agents: Deploy task-specific AI agents to improve problem solving efficiency.
- Flexible control: Continuously adjusting the balance of control and autonomy in workflows.
- Multi-agent coordination: Coordinate multiple AI agents in a single workflow or task.
- local observability: Monitor and debug AI workflows with full Prefect 3.0 support.
- ecosystem integration: Work seamlessly with existing code, tools, and the broader AI ecosystem.
Using Help
Installation process
- Install ControlFlow using pip:
pip install controlflow
- Configure your LLM provider.ControlFlow's default provider is OpenAI, which requires setting the
OPENAI_API_KEY
Environment variables:
export OPENAI_API_KEY=your-api-key
- If using another LLM provider, see the LLM configuration documentation.
Basic use
The basic use of ControlFlow involves creating tasks, assigning agents, and running workflows. The following is a simple example:
import controlflow as cf
result = cf.run("Write a short poem about artificial intelligence")
print(result)
Advanced Use
Creating structured research proposals
The following examples demonstrate user interaction, multi-step workflows, and structured output:
import controlflow as cf
from pydantic import BaseModel
class ResearchProposal(BaseModel).
title: str
abstract: str
key_points: list[str]
@cf.flow
def research_proposal_flow(): user_input = cf.
user_input = cf.Task("Collaborate with user to select research topic", interactive=True)
proposal = cf.run("Generate structured research proposal", result_type=ResearchProposal, depends_on=[user_input])
return proposal
result = research_proposal_flow()
print(result.model_dump_json(indent=2))
In this example, ControlFlow automatically manages a flow, a shared context for a series of tasks. Users can switch between standard Python functions and agent tasks at any time, building complex workflows step-by-step.
Debugging and Monitoring
ControlFlow provides native observability features that allow users to monitor and debug AI workflows. Users can use the full support of Prefect 3.0 to track task execution and make adjustments as needed.
ecosystem integration
ControlFlow integrates seamlessly with existing code and tools to support a wide range of AI technologies and workflow management approaches. Users can utilize existing AI ecosystem resources to further enhance workflow functionality and efficiency.
With the above steps and examples, users can quickly get started with building and managing AI workflows using ControlFlow to achieve efficient task management and agent coordination.
ControlFlow Core Concepts
Agentic Workflow Building Blocks
ControlFlow is a framework for building AI workflows that bridges the gap between structured programming and the natural language capabilities of the Large Language Model (LLM). This is achieved through three core concepts: Tasks, Agents, and Flows.
To create an Agentic workflow, you define clear goals (tasks), assign intelligent entities to accomplish those goals (agents), and organize their interactions over time (processes). This approach enables you to harness the power of AI while maintaining fine-grained control over your application.
📋 Tasks
Tasks represent the structured part of ControlFlow. They are specific, well-defined goals that form the core of your workflow. Tasks encapsulate the "what" and "how" of AI-driven operations, providing a clear programming structure.
mission-critical characteristics:
- Define specific goals that AI needs to accomplish
- Specify desired result types and validation criteria
- Can contain instructions, contexts and tools required for execution
- As a checkpoint in a workflow
exist mandates section for more information.
🦾 Agent (Agents)
Agents embody the unstructured, natural language portion of ControlFlow. They are AI entities that understand and generate human-like text, bringing flexibility and adaptability to your workflow.
Key features of the agent:
- Represents a configurable AI entity with a unique identity and capabilities
- Can be specialized to accomplish specific tasks or access different tools
- Collaborate on tasks according to instructions provided
- Interactive, allowing communication with users
- Support for configuring different LLM models to drive their responses
Agents can be configured with different LLM models, allowing you to choose the model that best suits your needs based on factors such as performance, latency, and cost.
exist act on behalf of sb. in a responsible position section for more information.
🧩 Flows (Flows)
Processes provide a shared context for all tasks and agents in a workflow. They coordinate the execution of tasks and agent interactions, enabling you to create complex, adaptive AI workflows.
Key characteristics of the process:
- High-level containers that serve as the entire AI-driven workflow
- Consistent status and history across all components
- Shared context for tasks and agents
- Can be nested to create hierarchical workflows
exist workflows section for more information.
synthesize
In a typical ControlFlow application:
- Define a Flow to represent the overall workflow.
- Create Tasks to represent specific goals in the process.
- Assign Agents to handle these tasks.
- Processes are responsible for coordinating the execution of tasks and agent interactions
This structure enables you to create powerful and flexible AI workflows while maintaining control of the process and ensuring that the output meets the requirements of your application.