feat(core): stream_parsed_repr — streaming parsed representation on the MOT

Abierto
#1,442 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
python
Área
backend

Línea de trabajo

Start with ModelOutputThunk.parsed_repr, Component._parse, and the stream() primitive in issue #1440; the issue does not identify file paths or tests. First settle the incremental parsing contract, including yielded values, parser ownership, emission timing, errors, and multi-modal output. Done means the MOT exposes parsed values as output streams and streaming completion agrees with the existing whole-output parse across output types.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

area/stdlib area/streaming enhancement

Add a streaming counterpart to ModelOutputThunk.parsed_repr: expose the MOT's typed parsed representation incrementally as the stream arrives, rather than only once at completion. stream_parsed_repr is to parsed_repr what astream() is to value.

This work is independent of the other Phase 2 issues. It depends only on the stream() primitive (#1440) and can proceed in parallel with per-validator chunking (#1441) and sampling (#403).

parsed_repr today

ModelOutputThunk is Generic[S]; parsed_repr: S | None is the typed interpretation of the output, populated exactly once at completion:

  • Component action: parsed_repr = action._parse(computed_mot) — the component's parser turns the finished output into its typed form S.
  • CBlock / ModelOutputThunk action: parsed_repr = value (raw string).

_parse is therefore a whole-output operation: it runs once, on the complete text, and yields the final S.

Scope

This issue covers only the streaming parsed representation. It is separate from:

  • chunking — how a stream is split for validation (issues 1 and 2); a different concern with a different owner.
  • validation — stream_validate and the requirement flow are unaffected.

The original epic framing conflated MOT-owned chunking with stream_parsed_repr; these are now separate. This issue is strictly the parsed-representation stream.

Multi-modal output (audio segments, image regions, video) is in scope here, not a separate issue. A multi-modal MOT parses its stream into typed units the same way a text MOT parses into S, so the incremental-parse contract must admit non-text S. Multi-modal is a case of stream_parsed_repr, not a follow-on to it.

The core problem: incremental parsing

_parse is defined on the complete output. Producing meaningful intermediate S values from partial output is fundamentally harder than streaming raw text:

  • A partial output may not be a valid S yet — half a JSON object, a truncated structured value.
  • Each output type parses differently. Prose, JSON, structured outputs, and multi-modal each have their own notion of a partial parse.

The deliverable is therefore not a single function but a contract for parsing incrementally that each output type implements, plus the plumbing to expose it on the MOT.

Open questions

  1. Yielded type. Bare S (assuming every intermediate is a valid S), or a typed envelope carrying a best-effort partial parse plus a "settled vs. still forming" flag? Multi-modal and partial-JSON push toward an envelope; text-only is fine with bare S. (This is the A-vs-C fork from the epic notes, scoped to parsing.)
  2. Parser source. _parse is whole-output today. Does each Component gain an incremental-parse method, with a fallback that parses the accumulated text each time? Where does the default live?
  3. Emit timing. On every delta, on a type-defined boundary (which risks re-tangling with chunking), or on demand when the caller asks?
  4. Relationship to stream(). Is stream_parsed_repr consumed through Streamer or directly off the MOT alongside astream()? It needs the same single-consumer discipline as astream() / __aiter__ (#1440's guard).
  5. Backpressure. If parsing lags the raw token stream, where does the partial state live? _GenerationState (from #909's structural cleanup) is a candidate.
  6. Error handling. If incremental parsing fails on a not-yet-valid partial stream, does it surface, wait for more data, or fall back to raw?
  7. Testability. Each output type's stream_parsed_repr must be verifiable against its non-streaming parsed_repr: streaming then completing must agree with parsing the whole output. Needs a shared harness and multi-modal fixtures.
Lenguaje dominante
Python
Estrellas
1.8k
Forks
161
Merge medio
4 d 3 h
PR fusionados (30 d)
45

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de generative-computing/mellea

Todos los issues de generative-computing/mellea

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.