From d2b36807d34dacf645807d810fd69f3ef47d808a Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Wed, 12 Jun 2024 20:52:28 -0400 Subject: [PATCH] Add debug option for raising on tool error --- src/controlflow/llm/tools.py | 5 +++++ src/controlflow/settings.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/controlflow/llm/tools.py b/src/controlflow/llm/tools.py index c80a2fe0..43ad208e 100644 --- a/src/controlflow/llm/tools.py +++ b/src/controlflow/llm/tools.py @@ -10,6 +10,7 @@ from prefect.utilities.asyncutils import run_coro_as_sync from pydantic import Field, create_model +import controlflow from controlflow.llm.messages import InvalidToolMessage if TYPE_CHECKING: @@ -117,6 +118,8 @@ def handle_tool_call(tool_call: ToolCall, tools: list[Tool]) -> "ToolMessage": except Exception as exc: fn_output = f'Error calling function "{fn_name}": {exc}' metadata["is_failed"] = True + if controlflow.settings.raise_on_tool_error: + raise from controlflow.llm.messages import ToolMessage @@ -146,6 +149,8 @@ async def handle_tool_call_async( except Exception as exc: fn_output = f'Error calling function "{fn_name}": {exc}' metadata["is_failed"] = True + if controlflow.settings.raise_on_tool_error: + raise from controlflow.llm.messages import ToolMessage diff --git a/src/controlflow/settings.py b/src/controlflow/settings.py index 672cb229..3800d255 100644 --- a/src/controlflow/settings.py +++ b/src/controlflow/settings.py @@ -51,7 +51,7 @@ def apply(self): class Settings(ControlFlowSettings): max_task_iterations: Optional[int] = Field( - default=100, + default=100, description="The maximum number of iterations to attempt to complete a task " "before raising an error. If None, the task will run indefinitely. " "This setting can be overridden by the `max_iterations` attribute " @@ -110,6 +110,10 @@ class Settings(ControlFlowSettings): # ------------ Debug settings ------------ + raise_on_tool_error: bool = Field( + True, description="If True, an error in a tool call will raise an exception." + ) + print_handler_width: Optional[int] = Field( default=None, description="The number of coloumns to use for the print handler. If None, the width of "