fix: clean citation leaks and duplicate agent output in thinking process#1094
Open
Ayaz-Microsoft wants to merge 2 commits into
Open
fix: clean citation leaks and duplicate agent output in thinking process#1094Ayaz-Microsoft wants to merge 2 commits into
Ayaz-Microsoft wants to merge 2 commits into
Conversation
- Strip citation markers (【x:y†source】) from agent streams (cross-chunk buffered) and the Group Chat Manager's final answer - Group AI Thinking Process output per agent (keep-latest snapshot) and switch frontend buffer from append to replace, fixing duplicated agent names/responses across manager rounds - Reset streaming section on each turn boundary to fix consecutive same-agent repetition (e.g. Triage repeated 7x) - Add per-round [ROUND N] next_speaker/satisfied/loop/progress log
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes streaming/orchestration “AI Thinking Process” rendering issues by cleaning citation markers across chunk boundaries, emitting a grouped per-agent snapshot (instead of append-only deltas), and adding per-round diagnostics in the Magentic round loop.
Changes:
- Backend: add cross-chunk citation stripping + grouped per-agent thinking snapshot state (with turn-boundary resets).
- Backend: clean citations from the Group Chat Manager’s final answer and add per-round
[ROUND N] ...diagnostic logging. - Frontend: treat streamed messages as full snapshots and replace (not append) the streaming buffer.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/backend/orchestration/orchestration_manager.py | Resets thinking state per run, cleans citations on final manager output, adds per-round logs, and marks turn boundaries for streaming snapshot behavior. |
| src/backend/callbacks/response_handlers.py | Implements citation buffering across streamed chunks and builds/emits grouped “thinking” snapshots per user. |
| src/App/src/hooks/usePlanWebSocket.tsx | Updates client buffering to replace with the latest backend snapshot instead of concatenating. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ce in orchestration manager
Ayaz-Microsoft
marked this pull request as ready for review
July 16, 2026 11:32
Ayaz-Microsoft
requested review from
Avijit-Microsoft,
Fr4nc3,
Roopan-Microsoft,
aniaroramsft,
dgp10801,
nchandhi and
toherman-msft
as code owners
July 16, 2026 11:32
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.
Purpose
Fix citation leaks and duplicated agent output in the AI Thinking Process
Summary
Fixes four related issues in the multi-agent streaming/orchestration layer: citation markers leaking into responses, agent names/responses duplicating in the "AI Thinking Process", the same agent repeating across consecutive rounds, and a lack of diagnostics for the Magentic manager's round loop.
Background
The Magentic orchestrator re-invokes agents across rounds by design, and streaming output arrives in partial deltas. The previous handling assumed append-only rendering and per-chunk cleaning, which broke down for multi-round runs and split markers.
Changes
Backend — src/backend/callbacks/response_handlers.py
• Cross-chunk citation cleaning: buffer a trailing, not-yet-closed 【… marker until its closing 】 arrives in a later delta, then strip it. Prevents markers like 【5:0†source】 from leaking when split across streaming chunks.
• Per-agent grouped "thinking" snapshot: accumulate output into an ordered {agent → latest text} map and emit the full grouped snapshot each delta, so each agent appears once with its latest response.
• Turn-boundary reset: mark_streaming_turn_complete() resets the current section at each agent turn boundary, so consecutive same-agent rounds don't concatenate.
Backend — src/backend/orchestration/orchestration_manager.py
• Apply clean_citations() to the Group Chat Manager's final answer, which previously bypassed citation cleaning entirely.
• Call mark_streaming_turn_complete() at each executor_completed turn boundary.
• Add a per-round diagnostic log: [ROUND N] next_speaker=… satisfied=… in_loop=… progress=… from the manager's progress ledger.
Frontend — src/App/src/hooks/usePlanWebSocket.tsx
• Replace the streaming buffer with the latest backend snapshot instead of appending, matching the new backend grouping.
Issues fixed:
• Citation markers ( 【5:0†source】 ) leaking in agent responses — fixed by cross-chunk citation buffering.
• Same markers leaking in the Group Chat Manager final answer — fixed by applying clean_citations() to final_text .
• Agent names/responses duplicated in the AI Thinking Process — fixed by the backend grouped snapshot + frontend replace.
• Same agent repeated ×N in consecutive rounds (e.g. Triage ×7) — fixed by the turn-boundary section reset.
• No visibility into the manager round loop — fixed by the per-round [ROUND N] log.
Does this introduce a breaking change?
How to Test
What to Check
Verify that the following are valid
Other Information