Skip to content

Commit

Permalink
Retry multiple times when M1 selects an invalid agent. Make agent sel…
Browse files Browse the repository at this point in the history
…ection deterministic when the team is a singleton (corner case).
  • Loading branch information
afourney committed Jan 16, 2025
1 parent 115fefa commit 76ea271
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,23 @@ async def _orchestrate_step(self, cancellation_token: CancellationToken) -> None
try:
assert isinstance(ledger_str, str)
progress_ledger = json.loads(ledger_str)

# If the team consists of a single agent, deterministically set the next speaker
if len(self._participant_topic_types) == 1:
progress_ledger["next_speaker"] = {
"reason": "The team consists of only one agent.",
"answer": self._participant_topic_types[0],
}

# Validate the structure
required_keys = [
"is_request_satisfied",
"is_progress_being_made",
"is_in_loop",
"instruction_or_question",
"next_speaker",
]

key_error = False
for key in required_keys:
if (
Expand All @@ -303,6 +313,15 @@ async def _orchestrate_step(self, cancellation_token: CancellationToken) -> None
):
key_error = True
break

# Validate the next speaker if the task is not yet complete
if (
not progress_ledger["is_request_satisfied"]["answer"]
and progress_ledger["next_speaker"]["answer"] not in self._participant_topic_types
):
key_error = True
break

if not key_error:
break
await self._log_message(f"Failed to parse ledger information, retrying: {ledger_str}")
Expand All @@ -313,6 +332,7 @@ async def _orchestrate_step(self, cancellation_token: CancellationToken) -> None
if key_error:
raise ValueError("Failed to parse ledger information after multiple retries.")
await self._log_message(f"Progress Ledger: {progress_ledger}")

# Check for task completion
if progress_ledger["is_request_satisfied"]["answer"]:
await self._log_message("Task completed, preparing final answer...")
Expand Down

0 comments on commit 76ea271

Please sign in to comment.