[fix] Emit ReasoningContentDeltaEvent for native model reasoning content - #8924
ProgrammerPlus1998 wants to merge 1 commit into
Conversation
…reaming When a model (e.g. MiMo, DeepSeek, OpenAI o-series) returns reasoning_content in streaming chunks, handle_model_response_chunk() now yields a ReasoningContentDeltaEvent for each delta when stream_events=True. Previously, reasoning_content was accumulated onto run_response but only emitted as part of RunContentEvent, so downstream consumers like AG-UI never received REASONING_* events for native model reasoning. This is a minimal fix (15 lines) that: - Does NOT change RunContentEvent construction (zero regression risk) - Does NOT add state tracking variables - Emits the per-chunk delta (not accumulated) for correct streaming semantics - Preserves backward compat: stream_events=False behavior is unchanged Fixes agno-agi#8400
PR TriagePossible duplicate: The following open PRs also reference the same issue(s):
If this is intentional, please explain in your PR description why this approach is preferred. Otherwise, consider collaborating on the existing PR instead. This PR has been automatically closed. There is already an open PR addressing this issue. If you believe your contribution is valuable, please comment on the original issue explaining your approach and why it might be preferred. A maintainer can reopen this PR if appropriate. |
|
@github-actions[bot] This is NOT a duplicate of #8418. The approaches are fundamentally different: #8418 (77 lines, 3 functions changed):
This PR (#8924, 15 lines, 1 function changed):
Both fix #8400 but this approach is strictly less invasive. The AG-UI handler already processes correctly (merged in #7429), so no handler changes are needed here. Please reopen this PR for maintainer review. |
SummaryFixes #8400 Models that stream reasoning content from the main call (Claude w/ thinking, OpenAI o-series, Gemini thinking, MiMo) emit This PR emits Changes (3 files, +46 lines)Agent path (
Team path (
Tests (
What this does NOT change
Why not existing PRs?
Type of change
Checklist
Duplicate and AI-Generated PR Check
Additional NotesTest results: 20/20 passed in How it works: The fix adds a |
Summary
Fixes #8400
When an OpenAI-compatible model (MiMo, DeepSeek, OpenAI o-series, Claude extended thinking, etc.) returns
reasoning_contentin streaming chunks,handle_model_response_chunk()accumulates it ontorun_response.reasoning_contentbut only emits a genericRunContentEvent. Downstream consumers like AG-UI (/agui) never receiveReasoningContentDelta/REASONING_MESSAGE_CONTENTevents, so the frontend cannot display the model's thinking process.This fix adds a
ReasoningContentDeltaEventyield after the reasoning content accumulation, gated onstream_events=True. The per-chunk delta (not the accumulated value) is emitted, preserving correct streaming semantics.Why this approach over #8418?
#8418 takes a heavier approach: it adds 3 state variables (
reasoning_started,reasoning_content_streamed,reasoning_completed), modifies theRunContentEventconstruction (stripsreasoning_contentwhenstream_events=True), and changes 3 functions. This PR:reasoning_content is not NonecheckRunContentEventconstruction — zero regression risk for existing consumersThe AG-UI handler already correctly processes
ReasoningContentDeltaEvent(merged in #7429), so no handler changes are needed.Type of change
Checklist
./scripts/format.shand./scripts/validate.sh)Duplicate and AI-Generated PR Check
Additional Notes
Testing: 2 new unit tests added to
libs/agno/tests/unit/reasoning/test_reasoning_streaming.py:test_handle_model_response_chunk_emits_reasoning_delta_when_streaming— verifiesReasoningContentDeltaEventis yielded whenstream_events=Truetest_handle_model_response_chunk_no_reasoning_delta_when_not_streaming— verifies backward compat whenstream_events=FalseAll 20 tests in the file pass.