diff --git a/src/uipath_langchain/agent/exceptions/exceptions.py b/src/uipath_langchain/agent/exceptions/exceptions.py index 5ac66e3d7..fd243114b 100644 --- a/src/uipath_langchain/agent/exceptions/exceptions.py +++ b/src/uipath_langchain/agent/exceptions/exceptions.py @@ -30,6 +30,7 @@ class AgentRuntimeErrorCode(str, Enum): UNEXPECTED_ERROR = "UNEXPECTED_ERROR" HTTP_ERROR = "HTTP_ERROR" LICENSE_NOT_AVAILABLE = "LICENSE_NOT_AVAILABLE" + EXECUTION_DEADLINE_EXCEEDED = "EXECUTION_DEADLINE_EXCEEDED" # Routing ROUTING_ERROR = "ROUTING_ERROR" diff --git a/src/uipath_langchain/agent/exceptions/llm.py b/src/uipath_langchain/agent/exceptions/llm.py index 3a1c95453..a6fbfeec5 100644 --- a/src/uipath_langchain/agent/exceptions/llm.py +++ b/src/uipath_langchain/agent/exceptions/llm.py @@ -22,3 +22,15 @@ def raise_for_llm_client_error(error: UiPathError) -> None: ), category=UiPathErrorCategory.USER, ) from error + + if error.error_code == UiPathLLMErrorCode.EXECUTION_DEADLINE_EXCEEDED: + raise AgentRuntimeError( + code=AgentRuntimeErrorCode.EXECUTION_DEADLINE_EXCEEDED, + title="Agent run reached its execution time limit.", + detail=( + error.detail + or "The run's execution time limit was reached before the LLM call could complete." + ), + category=UiPathErrorCategory.SYSTEM, + should_wrap=False, + ) from error diff --git a/tests/agent/test_llm_client_error_mapping.py b/tests/agent/test_llm_client_error_mapping.py new file mode 100644 index 000000000..4066afecb --- /dev/null +++ b/tests/agent/test_llm_client_error_mapping.py @@ -0,0 +1,25 @@ +"""Tests for raise_for_llm_client_error.""" + +import pytest +from uipath.llm_client import UiPathError, UiPathExecutionDeadlineError +from uipath.runtime.errors import UiPathErrorCategory + +from uipath_langchain.agent.exceptions import AgentRuntimeError, AgentRuntimeErrorCode +from uipath_langchain.agent.exceptions.llm import raise_for_llm_client_error + + +def test_execution_deadline_maps_to_agent_runtime_error(): + error = UiPathExecutionDeadlineError() + + with pytest.raises(AgentRuntimeError) as exc_info: + raise_for_llm_client_error(error) + + error_info = exc_info.value.error_info + assert AgentRuntimeErrorCode.EXECUTION_DEADLINE_EXCEEDED.value in error_info.code + assert error_info.category == UiPathErrorCategory.SYSTEM + assert error_info.detail == error.detail + assert exc_info.value.__cause__ is error + + +def test_unknown_error_code_does_not_raise(): + raise_for_llm_client_error(UiPathError("boom", error_code=None))