Use structured output for m1 orchestrator (#6540)

Use structured output when available in m1 orchestrator

Co-authored-by: Victor Dibia <victordibia@microsoft.com>
This commit is contained in:
Eric Zhu 2025-06-02 12:11:24 -07:00 committed by GitHub
parent cd49d71f2a
commit b0c800255a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -47,6 +47,7 @@ from ._prompts import (
ORCHESTRATOR_TASK_LEDGER_FULL_PROMPT, ORCHESTRATOR_TASK_LEDGER_FULL_PROMPT,
ORCHESTRATOR_TASK_LEDGER_PLAN_PROMPT, ORCHESTRATOR_TASK_LEDGER_PLAN_PROMPT,
ORCHESTRATOR_TASK_LEDGER_PLAN_UPDATE_PROMPT, ORCHESTRATOR_TASK_LEDGER_PLAN_UPDATE_PROMPT,
LedgerEntry,
) )
trace_logger = logging.getLogger(TRACE_LOGGER_NAME) trace_logger = logging.getLogger(TRACE_LOGGER_NAME)
@ -309,7 +310,18 @@ class MagenticOneOrchestrator(BaseGroupChatManager):
assert self._max_json_retries > 0 assert self._max_json_retries > 0
key_error: bool = False key_error: bool = False
for _ in range(self._max_json_retries): for _ in range(self._max_json_retries):
response = await self._model_client.create(self._get_compatible_context(context), json_output=True) if self._model_client.model_info.get("structured_output", False):
response = await self._model_client.create(
self._get_compatible_context(context), json_output=LedgerEntry
)
elif self._model_client.model_info.get("json_output", False):
response = await self._model_client.create(
self._get_compatible_context(context), cancellation_token=cancellation_token, json_output=True
)
else:
response = await self._model_client.create(
self._get_compatible_context(context), cancellation_token=cancellation_token
)
ledger_str = response.content ledger_str = response.content
try: try:
assert isinstance(ledger_str, str) assert isinstance(ledger_str, str)

View File

@ -1,3 +1,5 @@
from pydantic import BaseModel
ORCHESTRATOR_SYSTEM_MESSAGE = "" ORCHESTRATOR_SYSTEM_MESSAGE = ""
@ -98,6 +100,24 @@ Please output an answer in pure JSON format according to the following schema. T
""" """
class LedgerEntryBooleanAnswer(BaseModel):
reason: str
answer: bool
class LedgerEntryStringAnswer(BaseModel):
reason: str
answer: str
class LedgerEntry(BaseModel):
is_request_satisfied: LedgerEntryBooleanAnswer
is_in_loop: LedgerEntryBooleanAnswer
is_progress_being_made: LedgerEntryBooleanAnswer
next_speaker: LedgerEntryStringAnswer
instruction_or_question: LedgerEntryStringAnswer
ORCHESTRATOR_TASK_LEDGER_FACTS_UPDATE_PROMPT = """As a reminder, we are working to solve the following task: ORCHESTRATOR_TASK_LEDGER_FACTS_UPDATE_PROMPT = """As a reminder, we are working to solve the following task:
{task} {task}