Python: Properly configure structured outputs based on new options dict (#3213)

* Properly configure structured outputs based on new options dict

* Fix mypy
This commit is contained in:
Evan Mattson
2026-01-15 11:41:46 +09:00
committed by GitHub
Unverified
parent 620da7a829
commit 15d0c34d9f
18 changed files with 56 additions and 55 deletions
@@ -100,7 +100,7 @@ class Reviewer(Executor):
messages.append(ChatMessage(role=Role.USER, text="Please review the agent's responses."))
print("Reviewer: Sending review request to LLM...")
response = await self._chat_client.get_response(messages=messages, response_format=_Response)
response = await self._chat_client.get_response(messages=messages, options={"response_format": _Response})
parsed = _Response.model_validate_json(response.messages[-1].text)
@@ -138,7 +138,7 @@ def create_spam_detector_agent() -> ChatAgent:
"Include the original email content in email_content."
),
name="spam_detection_agent",
response_format=DetectionResult,
default_options={"response_format": DetectionResult},
)
@@ -152,7 +152,7 @@ def create_email_assistant_agent() -> ChatAgent:
"Return JSON with a single field 'response' containing the drafted reply."
),
name="email_assistant_agent",
response_format=EmailResponse,
default_options={"response_format": EmailResponse},
)
@@ -190,7 +190,7 @@ def create_email_analysis_agent() -> ChatAgent:
"and 'reason' (string)."
),
name="email_analysis_agent",
response_format=AnalysisResultAgent,
default_options={"response_format": AnalysisResultAgent},
)
@@ -199,7 +199,7 @@ def create_email_assistant_agent() -> ChatAgent:
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
instructions=("You are an email assistant that helps users draft responses to emails with professionalism."),
name="email_assistant_agent",
response_format=EmailResponse,
default_options={"response_format": EmailResponse},
)
@@ -208,7 +208,7 @@ def create_email_summary_agent() -> ChatAgent:
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
instructions=("You are an assistant that helps users summarize emails."),
name="email_summary_agent",
response_format=EmailSummaryModel,
default_options={"response_format": EmailSummaryModel},
)
@@ -243,7 +243,8 @@ async def main() -> None:
)
workflow = (
workflow_builder.set_start_executor("store_email")
workflow_builder
.set_start_executor("store_email")
.add_edge("store_email", "email_analysis_agent")
.add_edge("email_analysis_agent", "to_analysis_result")
.add_multi_selection_edge_group(
@@ -162,7 +162,7 @@ def create_spam_detection_agent() -> ChatAgent:
"and 'reason' (string)."
),
name="spam_detection_agent",
response_format=DetectionResultAgent,
default_options={"response_format": DetectionResultAgent},
)
@@ -171,7 +171,7 @@ def create_email_assistant_agent() -> ChatAgent:
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
instructions=("You are an email assistant that helps users draft responses to emails with professionalism."),
name="email_assistant_agent",
response_format=EmailResponse,
default_options={"response_format": EmailResponse},
)
@@ -171,28 +171,28 @@ async def main() -> None:
self_service_agent = chat_client.create_agent(
name="SelfServiceAgent",
instructions=SELF_SERVICE_INSTRUCTIONS,
response_format=SelfServiceResponse,
default_options={"response_format": SelfServiceResponse},
)
ticketing_agent = chat_client.create_agent(
name="TicketingAgent",
instructions=TICKETING_INSTRUCTIONS,
tools=plugin.get_functions(),
response_format=TicketingResponse,
default_options={"response_format": TicketingResponse},
)
routing_agent = chat_client.create_agent(
name="TicketRoutingAgent",
instructions=TICKET_ROUTING_INSTRUCTIONS,
tools=[plugin.get_ticket],
response_format=RoutingResponse,
default_options={"response_format": RoutingResponse},
)
windows_support_agent = chat_client.create_agent(
name="WindowsSupportAgent",
instructions=WINDOWS_SUPPORT_INSTRUCTIONS,
tools=[plugin.get_ticket],
response_format=SupportResponse,
default_options={"response_format": SupportResponse},
)
resolution_agent = chat_client.create_agent(
@@ -205,7 +205,7 @@ async def main() -> None:
name="TicketEscalationAgent",
instructions=ESCALATION_INSTRUCTIONS,
tools=[plugin.get_ticket, plugin.send_notification],
response_format=EscalationResponse,
default_options={"response_format": EscalationResponse},
)
# Agent registry for lookup
@@ -139,7 +139,7 @@ async def main() -> None:
manager_agent = chat_client.create_agent(
name="ManagerAgent",
instructions=MANAGER_INSTRUCTIONS,
response_format=ManagerResponse,
default_options={"response_format": ManagerResponse},
)
summary_agent = chat_client.create_agent(
@@ -154,7 +154,7 @@ def create_guessing_agent() -> ChatAgent:
"No explanations or additional text."
),
# response_format enforces that the model produces JSON compatible with GuessOutput.
response_format=GuessOutput,
default_options={"response_format": GuessOutput},
)
@@ -162,7 +162,7 @@ def create_spam_detection_agent() -> ChatAgent:
"You are a spam detection assistant that identifies spam emails. "
"Always return JSON with fields is_spam (bool) and reason (string)."
),
response_format=DetectionResultAgent,
default_options={"response_format": DetectionResultAgent},
# response_format enforces structured JSON from each agent.
name="spam_detection_agent",
)
@@ -176,7 +176,7 @@ def create_email_assistant_agent() -> ChatAgent:
"Return JSON with a single field 'response' containing the drafted reply."
),
# response_format enforces structured JSON from each agent.
response_format=EmailResponse,
default_options={"response_format": EmailResponse},
name="email_assistant_agent",
)