A framework for building agentic LLM workflows
Project description
ControlFlow
ControlFlow is a Python framework for building agentic LLM workflows. It provides a structured approach to orchestrating AI agents alongside traditional code, making AI applications easier to build, maintain, and trust.
ControlFlow uses a structured, declaratiave approach to building AI workflows. You define the objectives you want your agents to complete, and the framework coordinates their activity to achieve them. You can think of ControlFlow as a high-level orchestrator for AI agents, allowing you to focus on the logic of your application while ControlFlow manages the details of agent selection, data flow, and error handling.
Why ControlFlow?
Building AI workflows often involves wrestling with complex, unpredictable AI agents that can be difficult to control or integrate into existing software. ControlFlow offers a more targeted and developer-friendly approach:
- Break your workflow into small, well-defined tasks
- Assign tasks to specialized AI agents, providing clear instructions and constraints
- Seamlessly integrate AI-generated results back into your application logic
ControlFlow's design reflects the opinion that AI agents are most effective when they are given clear, well-defined tasks and constraints. By structuring your application in this way, you can leverage the power of autonomous AI while maintaining visibility and control over its behavior.
Key Concepts
-
Task: A discrete objective for AI agents to solve. Use tasks to describe the work you want your agents to perform, including any expected outputs, dependencies, and constraints.
-
Flow: A shared context for AI workflows. Flows track dependencies and maintain consistent history across tasks, allowing agents to collaborate and share information as they work towards a common goal.
-
Agent: An AI agent that can be assigned to tasks. Each agent has specific instructions, tools, or even an LLM model that it uses to complete tasks. By assigning agents to tasks, you can control which AI tools are used for each part of your workflow.
Get Started
Please note that ControlFlow is under active development.
git clone https://github.com/PrefectHQ/ControlFlow.git
cd controlflow
pip install .
Development
To install for development:
git clone https://github.com/PrefectHQ/ControlFlow.git
cd controlflow
pip install -e ".[dev]"
To run tests:
cd controlflow
pytest -vv
The ControlFlow documentation is built with Mintlify. To build the documentation, first install mintlify
:
npm i -g mintlify
Then run the local build:
cd controlflow/docs
mintlify dev
Example
import controlflow as cf
from pydantic import BaseModel
class Name(BaseModel):
first_name: str
last_name: str
@cf.flow
def demo_flow():
name_task = cf.Task(
objective="Get the user's name",
user_access=True,
result_type=Name,
)
# add ad-hoc instructions and run the task immediately
with cf.instructions("Talk like a pirate"):
name_task.run()
# create two dependent tasks
interests_task = cf.Task(
objective="Ask user for three interests",
result_type=list[str],
user_access=True,
)
poem_task = cf.Task(
objective="Write a poem based on the provided name and interests",
agents=[cf.Agent(name="poetry-bot", instructions="loves limericks")],
context={"name": name_task, "interests": interests_task},
)
# return the final task; it will be run and its result will be returned
return poem_task
if __name__ == "__main__":
poem = demo_flow()
print(poem)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for controlflow-0.7.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d39667f55482248fc63c77f916cb6c26bcd770c7c3bb9c5f495171e8d552359a |
|
MD5 | d10a554f904a5ad2f46e5e5e8136ca58 |
|
BLAKE2b-256 | 7a2113df0e832de6f826128a75ca5f14d423576457c6145b83097ca5a8b2b392 |