Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry multiple times when M1 selects an invalid agent. Make agent sel… #5079

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading