From d1b000820f6ecaf0d1e7728efa190a77de1c7568 Mon Sep 17 00:00:00 2001 From: Vlad Cimpeanu Date: Wed, 19 Aug 2026 15:54:00 +0300 Subject: [PATCH] feat(agent): map EXECUTION_DEADLINE_EXCEEDED to a clear runtime error (PC-4871) When an LLM call fails with uipath-llm-client's UiPathExecutionDeadlineError (the run's execution deadline has passed), the agent now surfaces a dedicated AGENT_RUNTIME.EXECUTION_DEADLINE_EXCEEDED error with the original detail instead of the generic unexpected-error message (should_wrap=False). Requires uipath-llm-client >= 1.18.0. Co-Authored-By: Claude Fable 5 --- .../agent/exceptions/exceptions.py | 1 + src/uipath_langchain/agent/exceptions/llm.py | 12 +++++++++ tests/agent/test_llm_client_error_mapping.py | 25 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 tests/agent/test_llm_client_error_mapping.py 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))