Skip to content

Commit e4f96c5

Browse files
committed
fix: allow payload handler to be non-determinable without erroring
1 parent 5bb4cfc commit e4f96c5

2 files changed

Lines changed: 10 additions & 21 deletions

File tree

src/uipath_langchain/agent/react/llm_node.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ async def llm_node(state: StateT):
9393
f"LLM returned {type(response).__name__} instead of AIMessage"
9494
)
9595

96-
payload_handler.check_stop_reason(response)
96+
if payload_handler is not None:
97+
payload_handler.check_stop_reason(response)
9798

9899
# filter out flow control tools when multiple tool calls exist
99100
if response.tool_calls:

src/uipath_langchain/chat/handlers/handler_factory.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from langchain_core.language_models import BaseChatModel
44

5-
from uipath_langchain.chat import UiPathBaseLLMClient
65
from uipath_langchain.chat.types import (
76
APIFlavor,
87
LLMProvider,
@@ -30,30 +29,19 @@
3029
}
3130

3231

33-
def get_payload_handler(model: BaseChatModel) -> ModelPayloadHandler:
32+
def get_payload_handler(model: BaseChatModel) -> ModelPayloadHandler | None:
3433
"""Get the appropriate payload handler for a model.
3534
3635
Args:
37-
model: A UiPath chat model instance with llm_provider and api_flavor.
36+
model: A UiPath chat model instance with llm_provider and api_flavor.
3837
3938
Returns:
40-
A ModelPayloadHandler instance for the model.
41-
42-
Raises:
43-
TypeError: If the model doesn't implement UiPathBaseLLMClient.
44-
ValueError: If no handler is registered for the model's provider/API flavor.
39+
A ModelPayloadHandler instance for the model or None if could not be determined.
4540
"""
46-
if not isinstance(model, UiPathBaseLLMClient):
47-
raise TypeError(
48-
f"Model {type(model).__name__} does not implement UiPathBaseLLMClient"
49-
)
50-
key = (model.api_config.vendor_type, model.api_config.api_flavor)
51-
handler_class = _HANDLER_REGISTRY.get(key)
52-
53-
if handler_class is None:
54-
raise ValueError(
55-
f"No payload handler registered for provider={model.api_config.vendor_type}, "
56-
f"api_flavor={model.api_config.api_flavor}"
57-
)
41+
try:
42+
key = (model.api_config.vendor_type, model.api_config.api_flavor)
43+
handler_class = _HANDLER_REGISTRY[key]
44+
except (AttributeError, KeyError) as _:
45+
return None
5846

5947
return handler_class()

0 commit comments

Comments
 (0)