Skip to content

Commit

Permalink
Merge pull request #327 from PrefectHQ/raise_on_failure
Browse files Browse the repository at this point in the history
Change raise_on_error to raise_on_failure
  • Loading branch information
jlowin authored Sep 23, 2024
2 parents 25c6498 + 50b4714 commit 8ac8a76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/controlflow/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def run_tasks(
flow: Flow = None,
agent: Agent = None,
turn_strategy: TurnStrategy = None,
raise_on_error: bool = True,
raise_on_failure: bool = True,
max_llm_calls: int = None,
max_agent_turns: int = None,
handlers: list[Handler] = None,
Expand All @@ -47,7 +47,7 @@ def run_tasks(
max_agent_turns=max_agent_turns,
)

if raise_on_error and any(t.is_failed() for t in tasks):
if raise_on_failure and any(t.is_failed() for t in tasks):
errors = [f"- {t.friendly_name()}: {t.result}" for t in tasks if t.is_failed()]
if errors:
raise ValueError(
Expand All @@ -64,7 +64,7 @@ async def run_tasks_async(
flow: Flow = None,
agent: Agent = None,
turn_strategy: TurnStrategy = None,
raise_on_error: bool = True,
raise_on_failure: bool = True,
max_llm_calls: int = None,
max_agent_turns: int = None,
handlers: list[Handler] = None,
Expand All @@ -85,7 +85,7 @@ async def run_tasks_async(
max_agent_turns=max_agent_turns,
)

if raise_on_error and any(t.is_failed() for t in tasks):
if raise_on_failure and any(t.is_failed() for t in tasks):
errors = [f"- {t.friendly_name()}: {t.result}" for t in tasks if t.is_failed()]
if errors:
raise ValueError(
Expand All @@ -102,14 +102,14 @@ def run(
turn_strategy: TurnStrategy = None,
max_llm_calls: int = None,
max_agent_turns: int = None,
raise_on_error: bool = True,
raise_on_failure: bool = True,
handlers: list[Handler] = None,
**task_kwargs,
) -> Any:
task = Task(objective=objective, **task_kwargs)
results = run_tasks(
tasks=[task],
raise_on_error=raise_on_error,
raise_on_failure=raise_on_failure,
turn_strategy=turn_strategy,
max_llm_calls=max_llm_calls,
max_agent_turns=max_agent_turns,
Expand All @@ -126,7 +126,7 @@ async def run_async(
turn_strategy: TurnStrategy = None,
max_llm_calls: int = None,
max_agent_turns: int = None,
raise_on_error: bool = True,
raise_on_failure: bool = True,
handlers: list[Handler] = None,
**task_kwargs,
) -> Any:
Expand All @@ -138,7 +138,7 @@ async def run_async(
turn_strategy=turn_strategy,
max_llm_calls=max_llm_calls,
max_agent_turns=max_agent_turns,
raise_on_error=raise_on_error,
raise_on_failure=raise_on_failure,
handlers=handlers,
)
return results[0]
10 changes: 6 additions & 4 deletions src/controlflow/tasks/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def run(
max_llm_calls: int = None,
max_agent_turns: int = None,
handlers: list["Handler"] = None,
raise_on_failure: bool = True,
) -> T:
"""
Run the task
Expand All @@ -372,13 +373,13 @@ def run(
turn_strategy=turn_strategy,
max_llm_calls=max_llm_calls,
max_agent_turns=max_agent_turns,
raise_on_error=False,
raise_on_failure=False,
handlers=handlers,
)

if self.is_successful():
return self.result
elif self.is_failed():
elif raise_on_failure and self.is_failed():
raise ValueError(f"{self.friendly_name()} failed: {self.result}")

@prefect_task(task_run_name=get_task_run_name)
Expand All @@ -390,6 +391,7 @@ async def run_async(
max_llm_calls: int = None,
max_agent_turns: int = None,
handlers: list["Handler"] = None,
raise_on_failure: bool = True,
) -> T:
"""
Run the task
Expand All @@ -402,13 +404,13 @@ async def run_async(
turn_strategy=turn_strategy,
max_llm_calls=max_llm_calls,
max_agent_turns=max_agent_turns,
raise_on_error=False,
raise_on_failure=False,
handlers=handlers,
)

if self.is_successful():
return self.result
elif self.is_failed():
elif raise_on_failure and self.is_failed():
raise ValueError(f"{self.friendly_name()} failed: {self.result}")

@contextmanager
Expand Down

0 comments on commit 8ac8a76

Please sign in to comment.