diff --git a/src/langbot/pkg/pipeline/longtext/longtext.py b/src/langbot/pkg/pipeline/longtext/longtext.py index 47f00843..32f0d416 100644 --- a/src/langbot/pkg/pipeline/longtext/longtext.py +++ b/src/langbot/pkg/pipeline/longtext/longtext.py @@ -76,6 +76,10 @@ class LongTextProcessStage(stage.PipelineStage): self.ap.logger.debug('Long message processing strategy is not set, skip long message processing.') return entities.StageProcessResult(result_type=entities.ResultType.CONTINUE, new_query=query) + if not query.resp_message_chain: + self.ap.logger.debug('Response message chain is empty, skip long message processing.') + return entities.StageProcessResult(result_type=entities.ResultType.CONTINUE, new_query=query) + # 检查是否包含非 Plain 组件 contains_non_plain = False diff --git a/tests/unit_tests/pipeline/test_longtext.py b/tests/unit_tests/pipeline/test_longtext.py index 8110fd71..7d0fb689 100644 --- a/tests/unit_tests/pipeline/test_longtext.py +++ b/tests/unit_tests/pipeline/test_longtext.py @@ -166,6 +166,29 @@ class TestLongTextProcessStageProcess: assert isinstance(components[0], platform_message.Plain) assert components[0].text == 'short response' + @pytest.mark.asyncio + async def test_empty_response_message_chain_continues_without_processing(self): + """Empty response chains should be a no-op for long text processing.""" + longtext = get_longtext_module() + entities = get_entities_module() + + app = FakeApp() + stage = longtext.LongTextProcessStage(app) + + pipeline_config = make_longtext_config(strategy='forward', threshold=1) + + await stage.initialize(pipeline_config) + + query = text_query("hello") + query.pipeline_config = pipeline_config + query.resp_message_chain = [] + + result = await stage.process(query, 'LongTextProcessStage') + + assert result.result_type == entities.ResultType.CONTINUE + assert result.new_query is query + assert query.resp_message_chain == [] + @pytest.mark.asyncio async def test_non_plain_component_skips(self): """resp_message_chain with non-Plain components should skip processing."""