|
| 1 | +""" |
| 2 | +Tool-related exception classes. |
| 3 | +""" |
| 4 | + |
| 5 | +from typing import Any |
| 6 | +from typing import Optional |
| 7 | + |
| 8 | +from grafi.common.exceptions.base import GrafiError |
| 9 | +from grafi.common.models.invoke_context import InvokeContext |
| 10 | + |
| 11 | + |
| 12 | +class ToolInvocationError(GrafiError): |
| 13 | + """Base class for tool invocation failures.""" |
| 14 | + |
| 15 | + def __init__( |
| 16 | + self, |
| 17 | + tool_name: str, |
| 18 | + message: str, |
| 19 | + invoke_context: Optional[InvokeContext] = None, |
| 20 | + cause: Optional[Exception] = None, |
| 21 | + **kwargs: Any, |
| 22 | + ) -> None: |
| 23 | + super().__init__(message, invoke_context, cause, **kwargs) |
| 24 | + self.tool_name = tool_name |
| 25 | + |
| 26 | + |
| 27 | +class LLMToolException(ToolInvocationError): |
| 28 | + """Raised when LLM tool operations fail.""" |
| 29 | + |
| 30 | + def __init__( |
| 31 | + self, |
| 32 | + tool_name: str, |
| 33 | + model: Optional[str] = None, |
| 34 | + message: str = "LLM tool operation failed", |
| 35 | + invoke_context: Optional[InvokeContext] = None, |
| 36 | + cause: Optional[Exception] = None, |
| 37 | + **kwargs: Any, |
| 38 | + ) -> None: |
| 39 | + super().__init__(tool_name, message, invoke_context, cause, **kwargs) |
| 40 | + self.model = model |
| 41 | + self.type = "LLM" |
| 42 | + |
| 43 | + |
| 44 | +class FunctionCallException(ToolInvocationError): |
| 45 | + """Raised when function call tool operations fail.""" |
| 46 | + |
| 47 | + def __init__( |
| 48 | + self, |
| 49 | + tool_name: str, |
| 50 | + function_name: Optional[str] = None, |
| 51 | + message: str = "Function call operation failed", |
| 52 | + invoke_context: Optional[InvokeContext] = None, |
| 53 | + cause: Optional[Exception] = None, |
| 54 | + **kwargs: Any, |
| 55 | + ) -> None: |
| 56 | + super().__init__(tool_name, message, invoke_context, cause, **kwargs) |
| 57 | + self.function_name = function_name |
| 58 | + self.type = "FunctionCall" |
| 59 | + |
| 60 | + |
| 61 | +class FunctionToolException(ToolInvocationError): |
| 62 | + """Raised when generic function tool operations fail.""" |
| 63 | + |
| 64 | + def __init__( |
| 65 | + self, |
| 66 | + tool_name: str, |
| 67 | + operation: Optional[str] = None, |
| 68 | + message: str = "Function tool operation failed", |
| 69 | + invoke_context: Optional[InvokeContext] = None, |
| 70 | + cause: Optional[Exception] = None, |
| 71 | + **kwargs: Any, |
| 72 | + ) -> None: |
| 73 | + super().__init__(tool_name, message, invoke_context, cause, **kwargs) |
| 74 | + self.operation = operation |
| 75 | + self.type = "Function" |
0 commit comments