Skip to content

Commit

Permalink
Merge pull request #13 from jlowin/controller
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
jlowin authored Apr 17, 2024
2 parents ed235a9 + 1693dac commit d1f72f0
Show file tree
Hide file tree
Showing 24 changed files with 1,213 additions and 954 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
![image](https://github.com/jlowin/control_flow/assets/153965/c2a8a2f0-8777-49a6-a79b-a0e101bd4a04)



# ControlFlow

ControlFlow is a Python framework for orchestrating AI agents in workflows alongside traditional code. It allows you to seamlessly integrate AI into any workflow, coordinate multiple specialized AI agents, collect of human inputs when needed, and maintain full observability for debugging.
ControlFlow is a Python framework for orchestrating AI agents in workflows alongside traditional code. It allows you to declaratively define AI tasks, assign them to agents, and seamlessly integrate them into larger workflows. By providing a structured way to coordinate multiple AI agents, ControlFlow enables you to build sophisticated applications that leverage the power of AI while maintaining the control and flexibility of traditional programming.

ControlFlow is designed with the belief that AI works best when focused and iterated. It encourages breaking workflows into small, targeted steps, each handled by a dedicated AI agent. This keeps each AI as effective as possible, while maintaining context across the entire ensemble. ControlFlow recognizes that AI should augment traditional development, not replace it. It enables a declarative approach to AI, where the desired outcomes are specified and the framework handles the implementation details. This allows developers to mix AI and traditional code freely, leveraging AI where it's most useful while using standard programming everywhere else.
At its core, ControlFlow is built on the idea of agent orchestration. It provides a way to break down complex workflows into smaller, focused tasks that can be assigned to specialized AI agents. These agents can work autonomously on their assigned tasks, while the framework ensures smooth coordination and information sharing between them. This approach allows each agent to excel at its specific role, while the overall workflow benefits from their combined capabilities.

🚨 ControlFlow requires bleeding-edge versions of [Prefect](https://github.com/prefecthq/prefect) and [Marvin](https://github.com/prefecthq/marvin). Caveat emptor!

## Key Concepts

- **Flow**: A container for an AI-enhanced workflow that maintains consistent context and history. Flows are defined with the `@ai_flow` decorator.
- **Task**: A discrete objective for AI agents to solve. Tasks can be defined with the `@ai_task` decorator or declared inline.
- **Agent**: an AI agent that can be assigned tasks

## Key Features

Expand All @@ -32,7 +36,7 @@ pip install .
## Example

```python
from control_flow import ai_flow, ai_task, run_ai_task, instructions
from control_flow import ai_flow, ai_task, run_ai, instructions
from pydantic import BaseModel


Expand All @@ -54,15 +58,15 @@ def write_poem_about_user(name: Name, interests: list[str]) -> str:

@ai_flow()
def demo():

# set instructions that will be used for multiple tasks
with instructions("talk like a pirate"):

# define an AI task as a function and have it execute it
name = get_user_name()

# define an AI task inline
interests = run_ai_task("ask user for three interests", cast=list[str], user_access=True)
interests = run_ai(
"ask user for three interests", cast=list[str], user_access=True
)

# set instructions for just the next task
with instructions("no more than 8 lines"):
Expand Down
12 changes: 5 additions & 7 deletions examples/readme_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from control_flow import ai_flow, ai_task, instructions, run_ai_task
from control_flow import ai_flow, ai_task, instructions, run_ai
from pydantic import BaseModel


Expand All @@ -12,7 +12,7 @@ def get_user_name() -> Name:
pass


@ai_task()
@ai_task
def write_poem_about_user(name: Name, interests: list[str]) -> str:
"""write a poem based on the provided `name` and `interests`"""
pass
Expand All @@ -26,10 +26,8 @@ def demo():
name = get_user_name()

# define an AI task inline
interests = run_ai_task(
"ask user for three interests",
cast=list[str],
user_access=True,
interests = run_ai(
"ask user for three interests", cast=list[str], user_access=True
)

# set instructions for just the next task
Expand All @@ -39,5 +37,5 @@ def demo():
return poem


if __name__ == "main":
if __name__ == "__main__":
demo()
34 changes: 22 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,31 @@ name = "control_flow"
version = "0.1.0"
description = "AI Workflows"
authors = [
{ name = "Jeremiah Lowin", email = "153965+jlowin@users.noreply.github.com" }
{ name = "Jeremiah Lowin", email = "153965+jlowin@users.noreply.github.com" },
]
dependencies = [
"marvin @ git+https://github.com/prefecthq/marvin@main",
"prefect @ git+https://github.com/prefecthq/prefect@main",
"prefect[dev] @ git+https://github.com/prefecthq/prefect@main",
# can remove when prefect fully migrates to pydantic 2
"pydantic>=2",
]
readme = "README.md"
requires-python = ">= 3.9"
keywords = ["ai", "chatbot", "llm", "NLP", "natural language processing", "prefect", "workflow", "orchestration", "python", "GPT", "openai", "assistant", "agent"]
keywords = [
"ai",
"chatbot",
"llm",
"NLP",
"natural language processing",
"prefect",
"workflow",
"orchestration",
"python",
"GPT",
"openai",
"assistant",
"agent",
]

[project.urls]
Code = "https://github.com/jlowin/ControlFlow"
Expand All @@ -24,24 +38,19 @@ tests = [
"pytest-env>=0.8,<2.0",
"pytest-rerunfailures>=10,<14",
"pytest-sugar>=0.9,<2.0",
"pytest>=8.1.1",
"pytest>=7.0",
"pytest-timeout",
"pytest-xdist",
"pre-commit>=3.7.0",
]
dev = [
"control_flow[tests]",
"ipython>=8.22.2",
"pdbpp>=0.10.3",
"ruff>=0.3.4",
]
dev = ["control_flow[tests]", "ipython>=8.22.2", "pdbpp>=0.10.3", "ruff>=0.3.4"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.rye]
managed = true
managed = true

[tool.hatch.metadata]
allow-direct-references = true
Expand All @@ -62,4 +71,5 @@ skip-magic-trailing-comma = false
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ['I', 'F401', 'E402']
"conftest.py" = ["F401", "F403"]
'tests/fixtures/*.py' = ['F403']
'tests/fixtures/*.py' = ['F401', 'F403']
"src/control_flow/utilities/types.py" = ['F401']
9 changes: 5 additions & 4 deletions src/control_flow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .settings import settings

from .agent import ai_task, Agent, run_ai_task
from .flow import ai_flow
# from .agent_old import ai_task, Agent, run_ai
from .core.flow import Flow
from .core.agent import Agent
from .core.controller.controller import Controller
from .instructions import instructions

from marvin.beta.assistants import Assistant
from .dx import ai_flow, run_ai, ai_task
Loading

0 comments on commit d1f72f0

Please sign in to comment.