From 6c0fe31bc67016d64a0547229e87c8784695fcbb Mon Sep 17 00:00:00 2001 From: Cosmin Maria Date: Fri, 22 May 2026 09:40:38 +0300 Subject: [PATCH] feat(langchain): route INVOKE + AnthropicClaude to UiPathChatAnthropicBedrock The AWSBEDROCK factory branch now picks UiPathChatAnthropicBedrock when api_flavor is INVOKE and discovery reports modelFamily=AnthropicClaude. Other INVOKE families still use UiPathChatBedrock, and None/CONVERSE continue to use UiPathChatBedrockConverse. Co-Authored-By: Claude Opus 4.7 (1M context) --- packages/uipath_langchain_client/CHANGELOG.md | 5 ++ .../uipath_langchain_client/__version__.py | 2 +- .../src/uipath_langchain_client/factory.py | 19 +++++++- .../features/test_factory_function.py | 46 +++++++++++++++++-- 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/packages/uipath_langchain_client/CHANGELOG.md b/packages/uipath_langchain_client/CHANGELOG.md index 2d55dcb..77cc2bb 100644 --- a/packages/uipath_langchain_client/CHANGELOG.md +++ b/packages/uipath_langchain_client/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to `uipath_langchain_client` will be documented in this file. +## [1.12.1] - 2026-05-22 + +### Changed +- `get_chat_model` once again routes to `UiPathChatAnthropicBedrock` when `api_flavor == ApiFlavor.INVOKE` and discovery reports `modelFamily == AnthropicClaude`. Other INVOKE families still use `UiPathChatBedrock`, and `None`/`CONVERSE` continue to use `UiPathChatBedrockConverse`. + ## [1.12.0] - 2026-05-21 ### Changed diff --git a/packages/uipath_langchain_client/src/uipath_langchain_client/__version__.py b/packages/uipath_langchain_client/src/uipath_langchain_client/__version__.py index b167423..0267bb6 100644 --- a/packages/uipath_langchain_client/src/uipath_langchain_client/__version__.py +++ b/packages/uipath_langchain_client/src/uipath_langchain_client/__version__.py @@ -1,3 +1,3 @@ __title__ = "UiPath LangChain Client" __description__ = "A Python client for interacting with UiPath's LLM services via LangChain." -__version__ = "1.12.0" +__version__ = "1.12.1" diff --git a/packages/uipath_langchain_client/src/uipath_langchain_client/factory.py b/packages/uipath_langchain_client/src/uipath_langchain_client/factory.py index 7063f86..6982068 100644 --- a/packages/uipath_langchain_client/src/uipath_langchain_client/factory.py +++ b/packages/uipath_langchain_client/src/uipath_langchain_client/factory.py @@ -64,8 +64,10 @@ def get_chat_model( If not provided, auto-detected from the model discovery endpoint. api_flavor: Vendor-specific API flavor to use. Effects: - OpenAI: ApiFlavor.RESPONSES sets use_responses_api=True. - - Bedrock: ApiFlavor.INVOKE uses UiPathChatBedrock; otherwise - (None or ApiFlavor.CONVERSE) uses UiPathChatBedrockConverse. + - Bedrock: ApiFlavor.INVOKE with model_family=ANTHROPIC_CLAUDE uses + UiPathChatAnthropicBedrock; ApiFlavor.INVOKE otherwise uses + UiPathChatBedrock; None or ApiFlavor.CONVERSE uses + UiPathChatBedrockConverse. custom_class: A custom class to use for instantiating the chat model instead of the auto-detected one. Must be a subclass of UiPathBaseChatModel. When provided, the factory skips vendor detection and uses this class directly. @@ -189,6 +191,19 @@ def get_chat_model( ) case VendorType.AWSBEDROCK: if api_flavor == ApiFlavor.INVOKE: + if model_family == ModelFamily.ANTHROPIC_CLAUDE: + from uipath_langchain_client.clients.bedrock.chat_models import ( + UiPathChatAnthropicBedrock, + ) + + return UiPathChatAnthropicBedrock( + model=model_name, + settings=client_settings, + byo_connection_id=byo_connection_id, + model_details=model_details, + **model_kwargs, + ) + from uipath_langchain_client.clients.bedrock.chat_models import ( UiPathChatBedrock, ) diff --git a/tests/langchain/features/test_factory_function.py b/tests/langchain/features/test_factory_function.py index 428eb3a..cc507cb 100644 --- a/tests/langchain/features/test_factory_function.py +++ b/tests/langchain/features/test_factory_function.py @@ -131,12 +131,11 @@ def test_openai_chat_respects_discovered_byom_chat_completions( class TestFactoryBedrockApiFlavorRouting: - """The AWSBEDROCK branch routes purely on ``api_flavor``: + """The AWSBEDROCK branch routes on ``api_flavor`` and ``model_family``: - - ``ApiFlavor.INVOKE`` -> ``UiPathChatBedrock`` + - ``ApiFlavor.INVOKE`` + ``ANTHROPIC_CLAUDE`` -> ``UiPathChatAnthropicBedrock`` + - ``ApiFlavor.INVOKE`` (other families) -> ``UiPathChatBedrock`` - ``ApiFlavor.CONVERSE`` or ``None`` -> ``UiPathChatBedrockConverse`` - - Model family (e.g. ANTHROPIC_CLAUDE) no longer influences the choice. """ def _patch_bedrock_classes(self, monkeypatch: pytest.MonkeyPatch) -> dict: @@ -217,6 +216,45 @@ def test_invoke_api_flavor_uses_bedrock_invoke(self, monkeypatch: pytest.MonkeyP ) assert chosen["class"] == "UiPathChatBedrock" + def test_invoke_api_flavor_with_anthropic_claude_uses_anthropic_bedrock( + self, monkeypatch: pytest.MonkeyPatch + ): + chosen = self._patch_bedrock_classes(monkeypatch) + settings = self._settings_with_model_info( + { + "modelName": "anthropic.claude-3-5-sonnet-20240620-v1:0", + "vendor": "AwsBedrock", + "apiFlavor": None, + "modelFamily": "AnthropicClaude", + } + ) + get_chat_model( + model_name="anthropic.claude-3-5-sonnet-20240620-v1:0", + client_settings=settings, + api_flavor=ApiFlavor.INVOKE, + ) + assert chosen["class"] == "UiPathChatAnthropicBedrock" + + def test_converse_api_flavor_with_anthropic_claude_still_uses_converse( + self, monkeypatch: pytest.MonkeyPatch + ): + """ANTHROPIC_CLAUDE only diverts to AnthropicBedrock on INVOKE — CONVERSE still wins.""" + chosen = self._patch_bedrock_classes(monkeypatch) + settings = self._settings_with_model_info( + { + "modelName": "anthropic.claude-3-5-sonnet-20240620-v1:0", + "vendor": "AwsBedrock", + "apiFlavor": None, + "modelFamily": "AnthropicClaude", + } + ) + get_chat_model( + model_name="anthropic.claude-3-5-sonnet-20240620-v1:0", + client_settings=settings, + api_flavor=ApiFlavor.CONVERSE, + ) + assert chosen["class"] == "UiPathChatBedrockConverse" + class TestFactoryAgentHubConfig: """The ``agenthub_config`` factory kwarg overrides ``client_settings.agenthub_config``