From 00b06ab2e18d189dc145cdb43fef18c16dfae5a6 Mon Sep 17 00:00:00 2001 From: Roy Belio <34023431+r-bit-rry@users.noreply.github.com> Date: Wed, 8 Jan 2025 04:18:42 +0200 Subject: [PATCH] fix(magentic-one): Enhance error handling in orchestrate_step to manage invalid ledger formats (#4845) * fix(magentic-one): Enhance error handling in orchestrate_step to manage invalid ledger formats * formatting --------- Co-authored-by: Roy Belio Co-authored-by: Jack Gerrits Co-authored-by: Jack Gerrits --- .../_group_chat/_magentic_one/_magentic_one_orchestrator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py index d405bab5b..8d3b64ff3 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py @@ -297,6 +297,7 @@ class MagenticOneOrchestrator(BaseGroupChatManager): for key in required_keys: if ( key not in progress_ledger + or not isinstance(progress_ledger[key], dict) or "answer" not in progress_ledger[key] or "reason" not in progress_ledger[key] ): @@ -305,7 +306,9 @@ class MagenticOneOrchestrator(BaseGroupChatManager): if not key_error: break await self._log_message(f"Failed to parse ledger information, retrying: {ledger_str}") - except json.JSONDecodeError: + except (json.JSONDecodeError, TypeError): + key_error = True + await self._log_message("Invalid ledger format encountered, retrying...") continue if key_error: raise ValueError("Failed to parse ledger information after multiple retries.")