Skip to content

symfonic.agent.presentation_stream

presentation_stream

Incremental release of stream text that final presentation will not retract.

Presentation removes extraction directives and citation tags, and it can do so retroactively: a bare trailing JSON object is only recognisable once the reply ends. So a delta is released only up to the first character that could begin something presentation might remove, minus trailing whitespace (the legacy strip rstrips and its directive patterns consume leading whitespace). What is released is therefore always a prefix of the final visible text.

The cost is latency, not content: text from the first <, backtick, {, [ or GRAPH_OPERATIONS onward arrives at the end of the turn.

HoldBackStream

HoldBackStream()

Feeds raw deltas in; yields only text the final answer keeps.

Source code in src/symfonic/agent/presentation_stream.py
def __init__(self) -> None:
    self._raw = ""
    self._released = 0

finish

finish(final_raw: str) -> tuple[str, PresentedText]

Return the not-yet-released tail of the visible text and its parse.

final_raw is the result's text. If the streamed deltas did not sum to it, the released prefix cannot be trusted and no tail is emitted: the done event still carries the correct final text.

Source code in src/symfonic/agent/presentation_stream.py
def finish(self, final_raw: str) -> tuple[str, PresentedText]:
    """Return the not-yet-released tail of the visible text and its parse.

    ``final_raw`` is the result's text. If the streamed deltas did not sum
    to it, the released prefix cannot be trusted and no tail is emitted:
    the ``done`` event still carries the correct final text.
    """
    presented = present_response(final_raw)
    released = self._raw[: self._released]
    if not presented.visible.startswith(released):
        return "", presented
    return presented.visible[self._released :], presented