-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from PrefectHQ/orchestrator
Add top level `run` fns and support orchestrators with no agent
- Loading branch information
Showing
11 changed files
with
290 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
documentation: | ||
- changed-files: | ||
- any-glob-to-any-file: 'docs/*' | ||
- changed-files: | ||
- any-glob-to-any-file: "docs/*" | ||
|
||
tests: | ||
- changed-files: | ||
- any-glob-to-any-file: "tests/*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from controlflow.flows import Flow, get_flow | ||
from controlflow.orchestration.orchestrator import Orchestrator, TurnStrategy | ||
from controlflow.tasks.task import Task | ||
|
||
|
||
def run( | ||
objective: str, | ||
*, | ||
turn_strategy: TurnStrategy = None, | ||
max_calls_per_turn: int = None, | ||
max_turns: int = None, | ||
**task_kwargs, | ||
): | ||
task = Task( | ||
objective=objective, | ||
**task_kwargs, | ||
) | ||
return task.run( | ||
turn_strategy=turn_strategy, | ||
max_calls_per_turn=max_calls_per_turn, | ||
max_turns=max_turns, | ||
) | ||
|
||
|
||
async def run_async( | ||
objective: str, | ||
*, | ||
turn_strategy: TurnStrategy = None, | ||
max_calls_per_turn: int = None, | ||
max_turns: int = None, | ||
**task_kwargs, | ||
): | ||
task = Task( | ||
objective=objective, | ||
**task_kwargs, | ||
) | ||
return await task.run_async( | ||
turn_strategy=turn_strategy, | ||
max_calls_per_turn=max_calls_per_turn, | ||
max_turns=max_turns, | ||
) | ||
|
||
|
||
def run_tasks( | ||
tasks: list[Task], | ||
flow: Flow = None, | ||
turn_strategy: TurnStrategy = None, | ||
**run_kwargs, | ||
): | ||
""" | ||
Convenience function to run a list of tasks to completion. | ||
""" | ||
flow = flow or get_flow() or Flow() | ||
orchestrator = Orchestrator(tasks=tasks, flow=flow, turn_strategy=turn_strategy) | ||
return orchestrator.run(**run_kwargs) | ||
|
||
|
||
async def run_tasks_async( | ||
tasks: list[Task], | ||
flow: Flow = None, | ||
turn_strategy: TurnStrategy = None, | ||
**run_kwargs, | ||
): | ||
""" | ||
Convenience function to run a list of tasks to completion asynchronously. | ||
""" | ||
flow = flow or get_flow() or Flow() | ||
orchestrator = Orchestrator(tasks=tasks, flow=flow, turn_strategy=turn_strategy) | ||
return await orchestrator.run_async(**run_kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .task import Task, run, run_async | ||
from .task import Task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.