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

Add debug option for raising on tool error #106

Merged
merged 1 commit into from
Jun 13, 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
5 changes: 5 additions & 0 deletions src/controlflow/llm/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/controlflow/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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 "
Expand Down
Loading