- 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: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. Thecf.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.
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.
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