Skip to content

Comments

fix: remove tool message mapping and fix tool result#603

Open
norman-le wants to merge 4 commits intomainfrom
fix/cas_tool_mapping_and_analyze_files_result
Open

fix: remove tool message mapping and fix tool result#603
norman-le wants to merge 4 commits intomainfrom
fix/cas_tool_mapping_and_analyze_files_result

Conversation

@norman-le
Copy link
Contributor

@norman-le norman-le commented Feb 19, 2026

Thread: https://uipath-product.slack.com/archives/C090NH84361/p1771451814067549?thread_ts=1771451799.784589&cid=C090NH84361

Noticed an issue with ToolMessage mapping when continuing a conversation (seems to be mapping duplicate tool messages - one from the Assistant message with the tool call results and another from the Assistant message with content parts. But both have the same tool ID, and the second one comes right after an AIMessage without a tool call.

Error:
image

Before (last ToolMessage being the problem):

  [0] SystemMessage: You are Agent.
[2026-02-18 16:04:23,094][INFO] The current date is: 2026-02-18T21:03Z.
[2026-02-18 16:04:23,094][INFO] Understand user goals through conversation an
[2026-02-18 16:04:23,095][INFO]   [1] HumanMessage: [{'type': 'text', 'text': 'whats the tallest animal', 'id': 'FCF7666B-8DF0-4A32-88A1-E467FAF6D1E8'}]
[2026-02-18 16:04:23,095][INFO]   [2] AIMessage: 
[2026-02-18 16:04:23,095][INFO]        tool_calls: ['Web_Search']
[2026-02-18 16:04:23,095][INFO]   [3] ToolMessage: {"results": [{"snippet": "Giraffe ... Standing between 14 and 19 feet, these leggy and lovable giant
[2026-02-18 16:04:23,095][INFO]        tool_call_id: tooluse_yZmZLnoxEKR1Bl4YTN2Pa4
[2026-02-18 16:04:23,095][INFO]   [4] AIMessage: <uip:cite sources='[{"title":"7 Tallest Animals In The World That Tower Above All","url":"https://my/
[2026-02-18 16:04:23,095][INFO]   [5] ToolMessage: {"results": [{"snippet": "Giraffe ... Standing between 14 and 19 feet, these leggy and lovable giant.  <--- problem
[2026-02-18 16:04:23,095][INFO]        tool_call_id: tooluse_yZmZLnoxEKR1Bl4YTN2Pa4
[2026-02-18 16:04:23,095][INFO]   [6] HumanMessage: [{'type': 'text', 'text': 'what about the tallest sea animal', 'id': '07BAEBA7-BA5A-47EF-B4DE-061B28

After:

[2026-02-18 15:54:17,973][INFO]   [0] SystemMessage: You are Agent.
[2026-02-18 15:54:17,973][INFO] The current date is: 2026-02-18T20:53Z.
[2026-02-18 15:54:17,973][INFO]   [1] HumanMessage: [{'type': 'text', 'text': 'whats the tallest animal', 'id': 'BCFE4396-1255-4E08-AF5B-562EA9185699'}]
[2026-02-18 15:54:17,973][INFO]   [2] AIMessage: 
[2026-02-18 15:54:17,973][INFO]        tool_calls: ['Web_Search']
[2026-02-18 15:54:17,973][INFO]   [3] ToolMessage: {"results": [{"snippet": "Giraffe ... Standing between 14 and 19 feet, these leggy and lovable giant
[2026-02-18 15:54:17,973][INFO]        tool_call_id: tooluse_lRZbJ3qJIyt4DuZHjUZgQc
[2026-02-18 15:54:17,973][INFO]   [4] AIMessage: <uip:cite sources='[{"title":"The Tallest Animals on Earth - Business Insider","url":"https://www.bu/
[2026-02-18 15:54:17,973][INFO]   [5] HumanMessage: [{'type': 'text', 'text': 'what about the tallest sea animal', 'id': '881350A9-5D6F-42BA-B0D5-2F1714

For coded (passes from running sample tool and from uipath dev):
image

image

Copilot AI review requested due to automatic review settings February 19, 2026 02:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the runtime message mapping behavior to stop synthesizing LangChain ToolMessage objects from UiPath tool call results, and adjusts an internal tool’s return shape to be structured rather than a raw string.

Changes:

  • Update UiPathChatMessagesMapper._map_messages_internal() to map assistant tool calls onto AIMessage.tool_calls only (no ToolMessage creation).
  • Update mapper tests to reflect that map_messages() returns only HumanMessage/AIMessage entries.
  • Change analyze_files internal tool to return a structured object ({"analysisResult": ...}) and update one test expectation accordingly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/runtime/chat_message_mapper.py Updates expectations so tool calls remain on AIMessage and no ToolMessage items are produced by map_messages().
tests/agent/tools/internal_tools/test_analyze_files_tool.py Updates one test to expect structured tool output.
src/uipath_langchain/runtime/messages.py Removes conversion of UiPath tool call results into LangChain ToolMessage objects during message mapping.
src/uipath_langchain/agent/tools/internal_tools/analyze_files_tool.py Returns a structured dict payload (analysisResult) instead of a plain string.

) -> list[BaseMessage]:
"""
Converts UiPathConversationMessage list to LangChain messages (UserMessage/AIMessage/ToolMessage list).
Converts UiPathConversationMessage list to LangChain messages (UserMessage/AIMessage list).
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring says the mapper returns "UserMessage" instances, but the implementation actually constructs HumanMessage for user role messages. Update the wording to reflect the actual LangChain message types returned (e.g., HumanMessage/AIMessage) to avoid misleading documentation.

Suggested change
Converts UiPathConversationMessage list to LangChain messages (UserMessage/AIMessage list).
Converts UiPathConversationMessage list to LangChain messages
(e.g., HumanMessage/AIMessage BaseMessage instances).

Copilot uses AI. Check for mistakes.
@norman-le norman-le marked this pull request as draft February 19, 2026 02:35
@norman-le norman-le marked this pull request as ready for review February 19, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant