---
title: Core Concepts
---

ControlFlow is a Python framework for building AI-powered applications using large language models (LLMs). It provides a structured, task-centric approach to create sophisticated workflows that leverage the power of AI while adhering to traditional software engineering best practices.

At the core of ControlFlow are three key concepts: Tasks, Agents, and Flows. Understanding how these elements work together is crucial to building effective AI workflows.

## Tasks: The Building Blocks

Tasks are the fundamental building blocks of ControlFlow workflows. Each task represents a discrete objective or goal that needs to be accomplished, such as generating text, classifying data, or extracting information from a document. Tasks define WHAT needs to be done in your AI workflow.

Key characteristics of tasks include:

- Clear objectives and expected result types
- Declarative definition of requirements and constraints
- Integration with traditional software through validated outputs

ControlFlow provides two ways to create tasks:

1. Using the `Task` class for explicit definition of all task properties.
2. Using the `@task` decorator on Python functions, which automatically infers task properties from the function definition.

## Agents: The Performers

Agents in ControlFlow are AI "workers" responsible for executing tasks. They determine HOW tasks are accomplished. Each agent can have distinct instructions, personality, and capabilities, tailored to specific roles or domains.

Key aspects of agents include:

- Specialized configuration for different types of tasks
- Access to specific tools or APIs
- Ability to interact with users and other agents when necessary

Agents are assigned to tasks based on their suitability and availability. This separation of "what" (tasks) and "how" (agents) allows for flexible and powerful workflows.

## Flows: The Orchestrators

Flows are high-level containers that encapsulate and orchestrate entire AI-powered workflows. They provide a structured way to manage tasks, agents, tools, and shared context.

Key features of flows include:

- Maintaining a consistent state across all components
- Managing the execution order of tasks based on dependencies
- Providing a shared context for agent collaboration

## Putting It All Together

When designing workflows in ControlFlow:

1. Break down your application logic into discrete tasks.
2. Define the dependencies and relationships between tasks.
3. Create specialized agents as needed for specific types of tasks.
4. Use flows to orchestrate the execution of tasks and manage agent interactions.

ControlFlow seamlessly integrates with existing Python codebases, treating AI tasks as first-class citizens. You can mix imperative and declarative programming styles, leverage Python's control flow and error handling capabilities, and gradually adopt AI capabilities into your applications.

Under the hood, ControlFlow utilizes Prefect, a popular workflow orchestration tool, to provide observability, monitoring, and management features. This allows you to track the progress of your workflows, identify bottlenecks, and optimize performance.

By adhering to software engineering best practices such as modularity, error handling, and clear interfaces between AI and traditional code, ControlFlow enables you to build robust, maintainable, and trustworthy AI-powered applications.