Skip to content

append_to_context=False on TextFrame not propagated through TTS service #4068

@jamsea

Description

@jamsea

Summary

When a TextFrame (or LLMTextFrame) with append_to_context=False passes through the TTS service, the flag is silently dropped. The resulting TTSTextFrame always has append_to_context=True, so the text still gets added to the LLM context by the assistant aggregator.

The TTSSpeakFrame path works correctly since it explicitly passes frame.append_to_context through to _push_tts_frames().

Steps to reproduce

  1. Create a custom FrameProcessor positioned between the LLM and TTS
  2. Emit a TextFrame or LLMTextFrame with append_to_context = False
  3. Observe the text still appears in the LLM assistant context

Root cause

In tts_service.py, _process_text_frame() (line 803) creates new AggregatedTextFrame objects from the incoming text but does not forward frame.append_to_context to _push_tts_frames():

async def _process_text_frame(self, frame: TextFrame):
    async for aggregate in self._text_aggregator.aggregate(frame.text):
        # ...
        await self._push_tts_frames(
            AggregatedTextFrame(aggregate.text, aggregate.type),
            includes_inter_frame_spaces,
            # append_tts_text_to_context is not passed, defaults to True
        )

By contrast, the TTSSpeakFrame path correctly propagates the flag:

await self._push_tts_frames(
    AggregatedTextFrame(frame.text, AggregationType.SENTENCE),
    append_tts_text_to_context=frame.append_to_context,  # properly forwarded
    push_assistant_aggregation=push_assistant_aggregation,
)

Suggested fix

Pass frame.append_to_context through in _process_text_frame():

async def _process_text_frame(self, frame: TextFrame):
    async for aggregate in self._text_aggregator.aggregate(frame.text):
        includes_inter_frame_spaces = (
            frame.includes_inter_frame_spaces
            if aggregate.type == AggregationType.TOKEN
            else False
        )
        if aggregate.type != AggregationType.TOKEN:
            await self.stop_text_aggregation_metrics()
        await self._push_tts_frames(
            AggregatedTextFrame(aggregate.text, aggregate.type),
            includes_inter_frame_spaces,
            append_tts_text_to_context=frame.append_to_context,
        )

Versions

  • pipecat-ai 0.0.104

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions