From 8228419f327a4438b517e99394b10d962530a0ad Mon Sep 17 00:00:00 2001 From: Roy Belio Date: Sat, 28 Dec 2024 17:18:51 +0200 Subject: [PATCH] fix(magentic-one): Enhance error handling in orchestrate_step to manage invalid ledger formats --- .../_magentic_one/_magentic_one_orchestrator.py | 7 ++++++- 1 file changed, 6 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 d405bab5b13..28a55881fff 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 @@ async def _orchestrate_step(self, cancellation_token: CancellationToken) -> None 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,11 @@ async def _orchestrate_step(self, cancellation_token: CancellationToken) -> None 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.")