Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change raise_on_error to raise_on_failure #327

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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