Skip to content

Commit

Permalink
Merge branch 'main' into version
Browse files Browse the repository at this point in the history
  • Loading branch information
jlowin authored Sep 24, 2024
2 parents bc4f9af + eac3c56 commit 793cb5f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ dependencies = [
"prefect>=3.0",
"jinja2>=3.1.4",
"langchain_core>=0.3",
"langchain_openai>=0.1.8",
"langchain-anthropic>=0.1.19",
"langchain_openai>=0.2",
"langchain-anthropic>=0.2",
"markdownify>=0.12.1",
"pydantic-settings>=2.2.1",
"textual>=0.61.1",
Expand Down
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 793cb5f

Please sign in to comment.