fix(longtext): avoid split interfering with multi-chain agent responses

Use query variable '_longtext_split_extra_chains' to pass extra split
segments instead of appending to resp_message_chain directly. This
prevents agent tool-call multi-round responses from being misidentified
as split results and sent repeatedly.

respback.py reverts to original single-chain logic and appends split
extra chains after the main response.
This commit is contained in:
RockChinQ
2026-03-12 09:52:59 -04:00
parent c92d3d7ad7
commit 662e6a4815
2 changed files with 37 additions and 40 deletions
@@ -97,10 +97,15 @@ class LongTextProcessStage(stage.PipelineStage):
original_text = str(query.resp_message_chain[-1])
threshold = query.pipeline_config['output']['long-text-processing']['threshold']
segments = self.strategy_impl.split_text(original_text, threshold)
query.resp_message_chain.pop()
for segment in segments:
query.resp_message_chain.append(
platform_message.MessageChain([platform_message.Plain(text=segment)])
# Replace the last chain with the first segment, store extra segments separately
# to avoid interfering with existing multi-chain scenarios (e.g. agent tool calls)
query.resp_message_chain[-1] = platform_message.MessageChain(
[platform_message.Plain(text=segments[0])]
)
if len(segments) > 1:
query.set_variable(
'_longtext_split_extra_chains',
[platform_message.MessageChain([platform_message.Plain(text=seg)]) for seg in segments[1:]],
)
else:
query.resp_message_chain[-1] = platform_message.MessageChain(