Repository navigation
feat(model-runtime): expose incremental LLM result accumulation - #355
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The narrow API exposure preserves existing behavior, includes focused documentation and regression coverage, and has no unresolved findings.
No open issues 🎉
What changed in this PR
Exposes the existing model-response accumulator as LLMResultAccumulator, allowing hosts to display streamed chunks while retaining a complete response for replay and persistence.
Changes:
- Publishes the accumulator without changing aggregation behavior or non-stream normalization.
- Documents incremental usage and one accumulator per invocation.
- Adds a public API regression covering content order, tool-call arguments, and provider-state preservation through JSON serialization.
| File | Description |
|---|---|
tests/model_runtime/test_llm_result_accumulator.py |
Adds public API and JSON round-trip regression coverage. |
src/graphon/model_runtime/README.md |
Documents incremental accumulation and invocation lifetime. |
src/graphon/model_runtime/model_providers/base/large_language_model.py |
Publishes the accumulator and updates its internal use. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
!Related Issue
Closes #354
Summary
Host agent loops need to retain complete model responses while displaying streamed chunks.
Expose the existing
_LLMChunkAccumulatorasLLMResultAccumulatorso callers can reuse itsconsume()andto_result()methods for replay and JSON persistence.Non-stream normalization continues to use the same implementation.
Document one accumulator per invocation and add a public API regression covering mixed content order, an empty content block carrying provider state, exact tool-call arguments, and false-valued assistant state through JSON serialization.
The downstream consumers are in langgenius/dify#44502.
Validation
4389ea1because the public class is absent; the existing private implementation satisfies its behavior assertions.PYTEST_ADDOPTS='-n 4' just test: 995 passed on Python 3.12.just check: passed, including lockfile, formatting, lint, types, and import boundaries.uv run --python 3.12 pytest -n 0 tests/test_repository_docs.py: 29 passed.Checklist
!