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 <robelio@microsoft.com>
Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com>
Co-authored-by: Jack Gerrits <jack@jackgerrits.com>
This commit is contained in:
Roy Belio 2025-01-08 04:18:42 +02:00 committed by GitHub
parent 52c2a70e95
commit 00b06ab2e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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.")