Repository navigation
Python: Parse fenced JSON from the group chat orchestrator agent - #8850
Conversation
When a provider ignores response_format, the orchestrator agent can return its AgentOrchestrationOutput as JSON wrapped in a Markdown code fence. The parser rejected it, so terminate=true was never applied and the group chat ran until max_rounds. _parse_agent_output now also tries the body of the last fenced block as a parse candidate, after the raw text, so existing behavior is unchanged. Fixes microsoft#8814 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/review |
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 780d5b320174
Model: gpt-5.6-sol
Overview
The change preserves structured and raw JSON precedence, validates every extracted candidate through the existing Pydantic contract, and adds end-to-end coverage for common fenced responses. The fallback still fails for MIME-style fence tags, and its backtracking regex can synchronously stall the event loop on malformed model output. Both risks are confined to text-fallback responses but can prevent the manager decision from being applied.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
2 verified findings remained after source verification (2 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/orchestrations/agent_framework_orchestrations/_group_chat.py
…ntic Replace the group chat fence regex with extract_markdown_fence_bodies in _orchestrator_helpers.py, which both group chat and Magentic's _extract_json now use. - A closing fence must be at least as long as the opening one and end its line, so backticks inside a JSON string value (for example a fenced code block in final_message) no longer end the block, and an outer fence may use four or more backticks. - The whole info string is consumed, so MIME tags such as application/json parse. - The scan never backtracks, so an unterminated fence followed by whitespace no longer stalls the event loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Motivation & Context
AgentBasedGroupChatOrchestratorasks the orchestrator agent for anAgentOrchestrationOutputviaresponse_format. Providers that don't honorresponse_format(for example Claude on Bedrock through an OpenAI-compatible Chat Completions endpoint) return the JSON as plain text wrapped in a Markdown code fence._parse_agent_outputcan't decode fenced JSON, so the orchestration decision, includingterminate: true, is never applied and the group chat runs untilmax_rounds.Description & Review Guide
_parse_agent_outputnow also tries the body of the last Markdown code fence (```json, a bare```, or any language tag) as a parse candidate.ValueError.response_formatnow honor the manager's decisions instead of degrading tomax_rounds. No public API changes._parse_last_json_object).This covers suggested fix (1) from the issue. Fixes (2), exposing
retry_attemptsonGroupChatBuilder, and (3), documentation, are left for separate changes.Related Issue
Fixes #8814
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.🤖 Generated with Claude Code