From c96df2bd9c54904171b1379bb568e0b99c42cf4a Mon Sep 17 00:00:00 2001 From: GabrielVasilescu04 Date: Wed, 17 Dec 2025 17:59:38 +0200 Subject: [PATCH] fix: handle toll call with no input --- pyproject.toml | 2 +- src/uipath_langchain/chat/mapper.py | 53 +++++++++++++++++++++-------- uv.lock | 2 +- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 18c103c9..30ead944 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "uipath-langchain" -version = "0.1.31" +version = "0.1.32" description = "Python SDK that enables developers to build and deploy LangGraph agents to the UiPath Cloud Platform" readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.11" diff --git a/src/uipath_langchain/chat/mapper.py b/src/uipath_langchain/chat/mapper.py index d2bcf667..cf822177 100644 --- a/src/uipath_langchain/chat/mapper.py +++ b/src/uipath_langchain/chat/mapper.py @@ -200,7 +200,6 @@ def map_event( content_part_id=f"chunk-{message.id}-0", chunk=UiPathConversationContentPartChunkEvent( data=text, - content_part_sequence=0, ), ) @@ -218,7 +217,6 @@ def map_event( content_part_id=f"chunk-{message.id}-0", chunk=UiPathConversationContentPartChunkEvent( data=args, - content_part_sequence=0, ), ) # Continue so that multiple tool_call_chunks in the same block list @@ -231,7 +229,6 @@ def map_event( content_part_id=f"content-{message.id}", chunk=UiPathConversationContentPartChunkEvent( data=message.content, - content_part_sequence=0, ), ) @@ -254,10 +251,46 @@ def map_event( else None ) - # If no AI message ID was found, we cannot properly associate this tool result + content_value: Any = message.content + if isinstance(content_value, str): + try: + content_value = json.loads(content_value) + except (json.JSONDecodeError, TypeError): + # Keep as string if not valid JSON + pass + + # If no AI message ID was found, create an empty message to associate the tool_call with if not result_message_id: - logger.warning( - f"Tool message {message.tool_call_id} has no associated AI message ID. Skipping." + result_message_id = str(uuid4()) + + return UiPathConversationMessageEvent( + message_id=result_message_id, + start=UiPathConversationMessageStartEvent( + role="assistant", timestamp=timestamp + ), + content_part=UiPathConversationContentPartEvent( + content_part_id=f"content-{result_message_id}", + start=UiPathConversationContentPartStartEvent( + mime_type="text/plain" + ), + chunk=UiPathConversationContentPartChunkEvent( + data="" + ), + end=UiPathConversationContentPartEndEvent() + ), + tool_call=UiPathConversationToolCallEvent( + tool_call_id=message.tool_call_id, + start=UiPathConversationToolCallStartEvent( + tool_name=message.name, + arguments=None, + timestamp=timestamp, + ), + end=UiPathConversationToolCallEndEvent( + timestamp=timestamp, + output=UiPathInlineValue(inline=content_value), + ), + ), + end=UiPathConversationMessageEndEvent() ) # Clean up the mapping after use @@ -267,14 +300,6 @@ def map_event( ): del self.tool_call_to_ai_message[message.tool_call_id] - content_value: Any = message.content - if isinstance(content_value, str): - try: - content_value = json.loads(content_value) - except (json.JSONDecodeError, TypeError): - # Keep as string if not valid JSON - pass - return UiPathConversationMessageEvent( message_id=result_message_id or str(uuid4()), tool_call=UiPathConversationToolCallEvent( diff --git a/uv.lock b/uv.lock index 9b1faacf..442ab843 100644 --- a/uv.lock +++ b/uv.lock @@ -2863,7 +2863,7 @@ wheels = [ [[package]] name = "uipath-langchain" -version = "0.1.31" +version = "0.1.32" source = { editable = "." } dependencies = [ { name = "aiosqlite" },