Skip to content

Commit c96df2b

Browse files
fix: handle toll call with no input
1 parent e8ba143 commit c96df2b

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-langchain"
3-
version = "0.1.31"
3+
version = "0.1.32"
44
description = "Python SDK that enables developers to build and deploy LangGraph agents to the UiPath Cloud Platform"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

src/uipath_langchain/chat/mapper.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ def map_event(
200200
content_part_id=f"chunk-{message.id}-0",
201201
chunk=UiPathConversationContentPartChunkEvent(
202202
data=text,
203-
content_part_sequence=0,
204203
),
205204
)
206205

@@ -218,7 +217,6 @@ def map_event(
218217
content_part_id=f"chunk-{message.id}-0",
219218
chunk=UiPathConversationContentPartChunkEvent(
220219
data=args,
221-
content_part_sequence=0,
222220
),
223221
)
224222
# Continue so that multiple tool_call_chunks in the same block list
@@ -231,7 +229,6 @@ def map_event(
231229
content_part_id=f"content-{message.id}",
232230
chunk=UiPathConversationContentPartChunkEvent(
233231
data=message.content,
234-
content_part_sequence=0,
235232
),
236233
)
237234

@@ -254,10 +251,46 @@ def map_event(
254251
else None
255252
)
256253

257-
# If no AI message ID was found, we cannot properly associate this tool result
254+
content_value: Any = message.content
255+
if isinstance(content_value, str):
256+
try:
257+
content_value = json.loads(content_value)
258+
except (json.JSONDecodeError, TypeError):
259+
# Keep as string if not valid JSON
260+
pass
261+
262+
# If no AI message ID was found, create an empty message to associate the tool_call with
258263
if not result_message_id:
259-
logger.warning(
260-
f"Tool message {message.tool_call_id} has no associated AI message ID. Skipping."
264+
result_message_id = str(uuid4())
265+
266+
return UiPathConversationMessageEvent(
267+
message_id=result_message_id,
268+
start=UiPathConversationMessageStartEvent(
269+
role="assistant", timestamp=timestamp
270+
),
271+
content_part=UiPathConversationContentPartEvent(
272+
content_part_id=f"content-{result_message_id}",
273+
start=UiPathConversationContentPartStartEvent(
274+
mime_type="text/plain"
275+
),
276+
chunk=UiPathConversationContentPartChunkEvent(
277+
data=""
278+
),
279+
end=UiPathConversationContentPartEndEvent()
280+
),
281+
tool_call=UiPathConversationToolCallEvent(
282+
tool_call_id=message.tool_call_id,
283+
start=UiPathConversationToolCallStartEvent(
284+
tool_name=message.name,
285+
arguments=None,
286+
timestamp=timestamp,
287+
),
288+
end=UiPathConversationToolCallEndEvent(
289+
timestamp=timestamp,
290+
output=UiPathInlineValue(inline=content_value),
291+
),
292+
),
293+
end=UiPathConversationMessageEndEvent()
261294
)
262295

263296
# Clean up the mapping after use
@@ -267,14 +300,6 @@ def map_event(
267300
):
268301
del self.tool_call_to_ai_message[message.tool_call_id]
269302

270-
content_value: Any = message.content
271-
if isinstance(content_value, str):
272-
try:
273-
content_value = json.loads(content_value)
274-
except (json.JSONDecodeError, TypeError):
275-
# Keep as string if not valid JSON
276-
pass
277-
278303
return UiPathConversationMessageEvent(
279304
message_id=result_message_id or str(uuid4()),
280305
tool_call=UiPathConversationToolCallEvent(

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)