Repository navigation
Conversation
BlueX888
force-pushed
the
fix/prep-perplexity-merge-drops-tool-call-messages
branch
from
October 8, 2026 10:13
cded9a7 to
9e70409
Compare
…essages Merging two consecutive same-role messages keeps the tool_calls and the content carried by the message it absorbs, so a tool message that answers a call still finds that call in the request. Consecutive tool messages are left as they are, since each names the call its result answers in tool_call_id and a merge would leave both results on the first call's id.
BlueX888
force-pushed
the
fix/prep-perplexity-merge-drops-tool-call-messages
branch
from
October 8, 2026 10:16
9e70409 to
420f80f
Compare
This branch has not been deployed
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.
PerplexityLLMAdaptermerges consecutive same-role messages so the request satisfies Perplexity's strict role alternation. The merge moved onlycontentoff the message it absorbed before dropping it, so a message carryingtool_callslost them — and two consecutivetoolmessages collapsed into one that answers only the first call.Why
In step 2 of
_transform_messages(src/pipecat/adapters/services/perplexity_adapter.py:151), any two adjacent same-role messages are merged:next_msg["content"]is extended intocurrent(:158-161), thennext_msgis popped (:162). Nothing carriestool_callsacross the merge, and nothing treats atoolmessage specially — yet itstool_call_idis the only thing tying its result to a call.A history in OpenAI message shape therefore comes out of the adapter wrong in two ways:
[assistant(text), assistant(tool_calls: c1), tool(c1)]->[assistant(text), tool(c1)]. The tool message answers a call that is no longer in the request.[assistant(tool_calls: c1, c2), tool(c1), tool(c2)]->[assistant(tool_calls: c1, c2), tool(c1)]. Both results land onc1, andc2is left unanswered.Changes
tool_callsfrom the absorbed message onto the surviving one, and movescontentinto it when the surviving message has none — the call can precede the text it was made alongside.toolmessages are left as they are, since merging them would leave both results on the first call's id.Testing
On the tree with the source change reverted, the three new tests fail:
With the change:
Notes
No issue to reference; this is not from a report. I left
changelog/alone because the fragment filename is the PR number — say the word and I'll add<this PR>.fixed.md.