Skip to content
Draft
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
1 change: 1 addition & 0 deletions src/uipath_langchain/agent/exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions src/uipath_langchain/agent/exceptions/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions tests/agent/test_llm_client_error_mapping.py
Original file line number Diff line number Diff line change
@@ -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))
Loading