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

AgentChat port of MagenticOneOrchestrator needs to validate json #4177

Open
afourney opened this issue Nov 14, 2024 · 0 comments · May be fixed by #4430
Open

AgentChat port of MagenticOneOrchestrator needs to validate json #4177

afourney opened this issue Nov 14, 2024 · 0 comments · May be fixed by #4430
Assignees
Milestone

Comments

@afourney
Copy link
Member

AgentChat port of MagenticOneOrchestrator needs to validate json here:

https://github.com/microsoft/autogen/blob/a27a130b4553c9002797e82a29bbc6db90b1bc92/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py#L214C4-L215C55

The original version has code for this:

assert max_json_retries > 0
for _ in range(max_json_retries):
ledger_response = await self._model_client.create(
self._system_messages + self._chat_history + ledger_user_messages,
json_output=True,
cancellation_token=cancellation_token,
)
ledger_str = ledger_response.content
try:
assert isinstance(ledger_str, str)
ledger_dict: Dict[str, Any] = json.loads(ledger_str)
required_keys = [
"is_request_satisfied",
"is_in_loop",
"is_progress_being_made",
"next_speaker",
"instruction_or_question",
]
key_error = False
for key in required_keys:
if key not in ledger_dict:
ledger_user_messages.append(AssistantMessage(content=ledger_str, source="self"))
ledger_user_messages.append(
UserMessage(content=f"KeyError: '{key}'", source=self.metadata["type"])
)
key_error = True
break
if "answer" not in ledger_dict[key]:
ledger_user_messages.append(AssistantMessage(content=ledger_str, source="self"))
ledger_user_messages.append(
UserMessage(content=f"KeyError: '{key}.answer'", source=self.metadata["type"])
)
key_error = True
break
if key_error:
continue
return ledger_dict
except json.JSONDecodeError as e:
self.logger.info(
OrchestrationEvent(
f"{self.metadata['type']} (error)",
f"Failed to parse ledger information: {ledger_str}",
)
)
raise e

@afourney afourney self-assigned this Nov 14, 2024
@ekzhu ekzhu added this to the 0.4.0 milestone Nov 14, 2024
@husseinmozannar husseinmozannar linked a pull request Nov 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants