Fix _mentioned_agents() to ignore reasoning tags in speaker selection#7219
Fix _mentioned_agents() to ignore reasoning tags in speaker selection#7219veeceey wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
All checks passing, DCO signed, ready for merge |
|
Hey @ekzhu, I noticed your comments on #6891 about preferring structured output / JSON mode and the That said, this PR is meant to handle the case where users haven't configured those options -- when they're just using a model that happens to emit thinking tags (like Qwen with default settings), the speaker selector still picks up those mentions and makes bad choices. This is basically a fallback for the "unstructured" path. Totally understand if you'd prefer to just point users toward structured output / |
|
Friendly ping @ekzhu - just checking if you had a chance to see my earlier comment about the approach here. Totally understand if you'd prefer to point users toward structured output / family: "r1" instead -- happy to close this if that's the preferred direction, or make any changes you'd like. Thanks for your time! |
|
@veeceey I don't work at Microsoft anymore. Cc @victordibia |
|
Thanks for the heads up @ekzhu! @victordibia would appreciate a look at this whenever you get a chance. |
Fixes microsoft#6891 When LLMs use reasoning tags like <thinking>, <reflection>, <planning>, etc., agent mentions inside these blocks should not affect speaker selection. This change filters out common reasoning blocks before counting agent mentions. The issue occurred because models like Qwen would mention agents in their internal reasoning (e.g., "<thinking>Maybe AgentA or AgentB could help</thinking>I suggest AgentC"), and the selector would count those mentions, leading to incorrect speaker selection. Changes: - Add _strip_reasoning_blocks() method to remove common reasoning tags - Update _mentioned_agents() to use cleaned content - Add test case for thinking tag handling Signed-off-by: Varun Chawla <varun_6april@hotmail.com>
d64b1e7 to
d1c7830
Compare
|
Rebased on latest main. @victordibia any thoughts on this one? happy to adjust the approach if you'd prefer a different direction. |
|
hey @victordibia, just a friendly bump on this - any thoughts on the approach? |
Summary
Fixes #6891
When LLMs use reasoning tags like
<thinking>,<reflection>,<planning>, etc., agent mentions inside these blocks should not affect speaker selection. This PR filters out common reasoning blocks before counting agent mentions.Problem
The issue occurred because models like Qwen would mention agents in their internal reasoning (e.g.,
"<thinking>Maybe AgentA or AgentB could help</thinking>I suggest AgentC"), and the selector would incorrectly count those mentions, leading to wrong speaker selection.Solution
_strip_reasoning_blocks()method to remove common reasoning tags:thinking,thought,reflection,reasoninganalysis,internal,scratch,planning_mentioned_agents()to use cleaned content before countingTesting
test_selector_group_chat_ignores_thinking_tagsExample
Before:
Would count: agent1=1, agent2=1, agent3=1 (incorrect)
After:
Would count: agent3=1 only (correct)