fix: remove tool message mapping and fix tool result#603
Open
fix: remove tool message mapping and fix tool result#603
Conversation
There was a problem hiding this comment.
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 ontoAIMessage.tool_callsonly (noToolMessagecreation). - Update mapper tests to reflect that
map_messages()returns onlyHumanMessage/AIMessageentries. - Change
analyze_filesinternal 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). |
There was a problem hiding this comment.
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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:

Before (last ToolMessage being the problem):
After:
For coded (passes from running sample tool and from uipath dev):
