Skip to content

Commit e142faf

Browse files
authored
Merge pull request #51 from jlowin/docs
New concepts docs
2 parents 422df4a + 017a107 commit e142faf

File tree

8 files changed

+506
-63
lines changed

8 files changed

+506
-63
lines changed

docs/concepts.mdx

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,39 @@
22
title: Core Concepts
33
---
44

5-
**ControlFlow is built on three core concepts** that are essential to understanding how the framework works. These concepts are designed to make it easy to build and manage complex AI workflows, while also providing a clear structure for developers to follow.
65

7-
## 🚦 Task
8-
**Tasks are the building blocks of ControlFlow workflows**. Each task represents a discrete objective for agents to solve, such as generating text, classifying data, or extracting information from a document. In addition, tasks can specify instructions, tools for agents to use, a schema for the expected output, and more.
6+
ControlFlow is a Python framework for building AI-powered applications using large language models (LLMs). It provides a structured and intuitive way to create sophisticated workflows that leverage the power of AI while adhering to traditional software engineering best practices.
97

10-
Tasks can depend on each other in various ways, creating complex workflows that are easy to understand and manage:
11-
- **sequential** dependencies: one task must be completed before another can start
12-
- **context** dependencies: the result of one task is used as input for another
13-
- **subtask** dependencies: a task has subtasks that must be completed before the task can be considered done
8+
At the core of ControlFlow are three key concepts: Tasks, Flows, and Agents.
149

15-
By specifying the parameters of each task and how they relate to each other, developers can create complex workflows that are easy to understand and manage.
10+
## Tasks
1611

17-
## 🌊 Flow
18-
**A flow represents an entire agentic workflow.** It is a "container" for the workflow that maintains consistent context and state across all tasks and agents. Each flow executes on a different thread, meaning all agents in the flow see the same state and can communicate with each other.
12+
Tasks are the building blocks of ControlFlow workflows. Each task represents a discrete objective or goal that an AI agent needs to solve, such as generating text, classifying data, or extracting information from a document. Tasks are defined using a declarative approach, specifying the objective, instructions, expected result type, and any required context or tools.
1913

20-
## 🤖 Agent
21-
**Agents are the AI "workers" that complete tasks.** Each agent can have distinct instructions, personality, and capabilities, and they are responsible for completing any tasks assigned to them. Agents can be specialized for specific tasks or more general-purpose, depending on the requirements of the workflow.
14+
ControlFlow provides two ways to create tasks:
15+
16+
1. Using the `Task` class, which allows you to explicitly define all properties of a task.
17+
2. Using the `@task` decorator on a Python function, which automatically infers task properties from the function definition.
18+
19+
Tasks can depend on each other in various ways, such as sequential dependencies (one task must be completed before another can start), context dependencies (the result of one task is used as input for another), or subtask dependencies (a task has subtasks that must be completed before the parent task can be considered done).
20+
21+
22+
## Agents
23+
24+
Agents are the AI "workers" responsible for executing tasks within a flow. Each agent can have distinct instructions, personality, and capabilities, tailored to specific roles or domains. Agents are assigned to tasks based on their suitability and availability.
25+
26+
ControlFlow allows you to create specialized agents equipped with relevant tools and instructions to tackle specific tasks efficiently. Agents can interact with each other and with human users (if given user access) to gather information, make decisions, and complete tasks collaboratively.
27+
28+
## Flows
29+
30+
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. A flow maintains a consistent state across all its components, allowing agents to communicate and collaborate effectively.
31+
32+
## Putting It All Together
33+
34+
When designing workflows in ControlFlow, you break down your application logic into discrete tasks, define the dependencies and relationships between them, and assign suitable agents to execute them. Flows provide a high-level orchestration mechanism to manage the execution of tasks, handle data flow, and maintain a shared context.
35+
36+
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.
37+
38+
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.
39+
40+
By adhering to software engineering best practices, such as modularity, error handling, and documentation, ControlFlow enables you to build robust, maintainable, and trustworthy AI-powered applications.

docs/concepts/agents.mdx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
Agents are a key concept in ControlFlow, representing the AI entities responsible for executing tasks within a workflow. Each agent has its own set of properties, methods, and capabilities that define its behavior and role in the flow.
3+
4+
## Creating an Agent
5+
6+
To create an agent, you can use the `Agent` class provided by ControlFlow. Here's an example of how to create an agent:
7+
8+
```python
9+
from controlflow import Agent
10+
11+
agent = Agent(
12+
name="DataAnalyst",
13+
description="An AI agent specialized in data analysis",
14+
instructions="Perform data analysis tasks efficiently and accurately",
15+
tools=[pandas_tool, matplotlib_tool]
16+
)
17+
```
18+
19+
In this example, we create an agent named "DataAnalyst" with a description and specific instructions. The `tools` parameter is used to provide the agent with a list of tools it can use during task execution. These tools are essentially Python functions that the agent can call at any time.
20+
21+
## Agent Properties
22+
23+
An agent has the following key properties:
24+
25+
- `name` (str): The name of the agent, which serves as an identifier and is visible to other agents in the workflow.
26+
- `description` (str, optional): A brief description of the agent's role or specialization, which is also visible to other agents.
27+
- `instructions` (str, optional): Specific instructions or guidelines for the agent to follow during task execution. These instructions are private to the agent and not visible to other agents.
28+
- `tools` (List[ToolType], optional): A list of tools available to the agent. Tools are Python functions that the agent can call to perform specific actions or computations.
29+
- `user_access` (bool, default=False): Indicates whether the agent has access to user interactions. If set to `True`, the agent will be provided with the `talk_to_human` tool to communicate with users.
30+
31+
These properties help define the agent's characteristics, behavior, and capabilities within the flow.
32+
33+
## Assigning Agents to Tasks
34+
35+
To assign an agent to a task, you can use the `agents` parameter when creating a task. Here's an example:
36+
37+
```python
38+
from controlflow import Task
39+
40+
task = Task(
41+
objective="Analyze sales data",
42+
agents=[data_analyst, data_visualizer]
43+
)
44+
```
45+
46+
In this example, we create a task with the objective "Analyze sales data" and assign two agents, `data_analyst` and `data_visualizer`, to it. Agents can only work on tasks they are assigned to.
47+
48+
## Running Agents
49+
50+
The `Agent` class provides a `run()` method to take low-level control of an agent's execution. Here's an example of how to run an agent:
51+
52+
```python
53+
from controlflow import Agent, Task
54+
55+
agent = Agent(name="DataAnalyst")
56+
task = Task(objective="Analyze sales data", agents=[agent])
57+
58+
while task.is_incomplete():
59+
agent.run(task)
60+
```
61+
62+
In this example, we create an agent and a task, and assign the agent to the task. We then use a while loop to run the agent repeatedly until the task is marked as complete.
63+
64+
## User Access and Interaction
65+
66+
Agents with the `user_access` flag set to `True` have the ability to interact with users using the `talk_to_human` tool. This tool allows agents to send messages to users and receive responses.
67+
68+
```python
69+
from controlflow import Agent
70+
71+
agent = Agent(
72+
name="UserAssistant",
73+
description="An AI agent that interacts with users",
74+
user_access=True
75+
)
76+
```
77+
78+
In this example, we create an agent named "UserAssistant" with the `user_access` flag set to `True`. This agent will have access to the `talk_to_human` tool to communicate with users when necessary.
79+
80+
## Best Practices
81+
82+
When working with agents in ControlFlow, consider the following best practices:
83+
84+
- Create specialized agents tailored to specific tasks or equipped with relevant tools.
85+
- Provide clear and concise instructions to guide the agent's behavior and decision-making process.
86+
- Assign agents to tasks based on their capabilities and the task's requirements.
87+
- Use the `user_access` flag judiciously and ensure proper handling of user interactions.
88+
- Monitor and debug agent execution to identify and resolve any issues or inefficiencies.
89+
90+
By designing and deploying agents effectively, you can build powerful and efficient workflows that leverage the strengths of AI in task execution and decision-making.

0 commit comments

Comments
 (0)