Skip to content
Open
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
53 changes: 39 additions & 14 deletions src/uipath_langchain/chat/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ def map_event(
content_part_id=f"chunk-{message.id}-0",
chunk=UiPathConversationContentPartChunkEvent(
data=text,
content_part_sequence=0,
),
)

Expand All @@ -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
Expand All @@ -231,7 +229,6 @@ def map_event(
content_part_id=f"content-{message.id}",
chunk=UiPathConversationContentPartChunkEvent(
data=message.content,
content_part_sequence=0,
),
)

Expand All @@ -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
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading