fix: remove tool message mapping and fix tool result#603
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.
| Converts UiPathConversationMessage list to LangChain messages (UserMessage/AIMessage list). | |
| Converts UiPathConversationMessage list to LangChain messages | |
| (e.g., HumanMessage/AIMessage BaseMessage instances). |
JoshParkSJ
left a comment
There was a problem hiding this comment.
I think you have to bump up pyproject version in toml file and uv lock it before pushing though
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):
