Quickstart
Build your first agentic workflow in less than a minute.
Welcome to ControlFlow! This quickstart guide will walk you through the basics of using ControlFlow to create AI-powered workflows.
You’ll learn how to:
- Run simple tasks with
cf.run()
- Create specialized agents for specific tasks
- Compose tasks into complex workflows using flows
Install ControlFlow
Install ControlFlow with pip:
Next, set up your LLM provider. By default, ControlFlow uses OpenAI, so you’ll need to configure an OpenAI API key:
To use another provider, see the docs on configuring LLMs.
Create some data
In this quickstart, we’re going to build an email processing pipelines, so let’s create some sample data to work with. Execute this code in your Python interpreter to set up the (very simple) example emails we’ll use throughout the quickstart:
Try changing the emails to your own content to see how ControlFlow works with different inputs.
Running a single task
Let’s start with the basics. We’re going to create a task that generates a reply to an email.
The cf.run()
function is the main entry point for ControlFlow. It creates a task, assigns it to the default agent, and runs it to completion.
Here, we create a task that generates a simple email reply, and provide the content of an email as additional context:
Recap
What we learned:
- Create and run tasks with
cf.run()
- Provide additional
context
as necessary
Creating specialized agents
Now let’s create a task to identify whether an email is spam.
For classification tasks, we want to use a smaller, faster LLM. In ControlFlow, Agents
are used to represent portable LLM configurations, including model choice, tools, specialized instructions, and more.
You may have noticed that in the last example, we didn’t assign an agent to the task. In that case, ControlFlow uses a general-purpose default agent.
Agents are sort of like portable configurations for how to perform tasks, which could include specific LLMs, tools, instructions, and more. For our spam classifier, we’ll create a new agent that uses a smaller, faster LLM and specialized instructions.
In addition, note that the result_type
of this task is a list of labels, indicating that the agent must choose one of the provided options. This is the simplest way to create a classification task, but you can require more complex output formats as well.
This example uses an OpenAI model, but you can use any LangChain-compatible LLM here. Follow the instructions in the LLM docs to learn more.
Our agent correctly identifies the first and third emails as important, and the second as spam.
Recap
What we learned:
- Create specialized agents to configure LLMs, tools, or instructions
- Use
result_type
to define the task’s output format - Use
agents
to specify which agent to use for the task
Composing tasks into a flow
Thus far, each of our tasks has run as a one-off operation. To create a more complex workflow, we can use a ControlFlow flow.
A flow provides a shared context and history for all agents, even across multiple tasks. The easiest way to create a flow is to use the @cf.flow
decorator on a function with ControlFlow agents working inside it.
Recap
What we learned:
- Use
@cf.flow
to create a shared context for multiple tasks - Use task results to dynamically adjust your workflow
Conclusion
Congratulations! You’ve completed the ControlFlow quickstart. You’ve learned how to:
- Run simple tasks with
cf.run()
- Create specialized agents for specific tasks
- Compose tasks into complex workflows using flows
This email processing example showcases how ControlFlow can be used to create sophisticated AI-powered applications. As you continue to explore ControlFlow, you’ll discover even more ways to leverage AI in your projects.