Skip to content

symfonic.agent.response_presentation

response_presentation

Pure final-text presentation: extraction directives and citation tags.

The legacy engine turns a raw model reply into user-visible text with _parse_and_strip_extraction followed by _strip_citation_tags. The kernel-backed :class:~symfonic.agent.facade.Agent returns the raw reply. This module is the same transformation as a dependency-free function, so a caller can opt into it without importing the closed engine module.

The extraction patterns are copies, not imports, on purpose: engine.py is closed to new surface and heavy to import. The citation-tag strip is not a copy: it delegates to core.streaming.citation_filter, the single whole-text spelling, which is neither closed nor heavy. Drift against the legacy strip is caught by the differential tests in tests/agent/presentation/test_response_presentation_parity.py, which run both implementations over the same inputs.

Not covered: the legacy activation_log_mode footer strip, which is configuration-driven and has no facade-side configuration to read.

PresentedText dataclass

PresentedText(visible: str, ops: tuple[dict[str, Any], ...] = (), directive_seen: bool = False)

The visible text and the extraction ops that were removed from it.

ops is empty both when no directive was present and when one was present but malformed. Unlike the legacy parser, malformed scalar operation collections are not forwarded to a caller hook. The visible directive text is still stripped.

present_response

present_response(text: str) -> PresentedText

Apply the legacy extraction strip, then the citation-tag strip.

Source code in src/symfonic/agent/response_presentation.py
def present_response(text: str) -> PresentedText:
    """Apply the legacy extraction strip, then the citation-tag strip."""
    clean, ops, seen = _strip_extraction(text)
    return PresentedText(strip_citation_tags(clean), tuple(ops), seen)

strip_citation_tags

strip_citation_tags(text: str) -> str

The citation-tag half alone, for text whose directive was already removed.

Legacy strips one directive per reply: once a tagged block matched, a bare object left in the text is visible content, not a second directive.

Delegates to the core whole-text spelling so the vocabulary lives once.

Source code in src/symfonic/agent/response_presentation.py
def strip_citation_tags(text: str) -> str:
    """The citation-tag half alone, for text whose directive was already removed.

    Legacy strips one directive per reply: once a tagged block matched, a bare
    object left in the text is visible content, not a second directive.

    Delegates to the core whole-text spelling so the vocabulary lives once.
    """
    return _strip_tags_once(text)