You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: agent_framework.exceptions.ServiceResponseException: <class 'agent_framework_azure_ai._client.AzureAIClient'> service failed to complete the prompt: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'ManagerSelectionResponse'.... #2681
I tried to use GroupChatBuilder with a Foundry agent as the manager. But failed with this error agent_framework.exceptions.ServiceResponseException: <class 'agent_framework_azure_ai._client.AzureAIClient'> service failed to complete the prompt: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'ManagerSelectionResponse': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'selected_participant'.", 'type': 'invalid_request_error', 'param': 'text.format.schema', 'code': 'invalid_json_schema'}}.
Basically, I modified this sample python/samples/getting_started/workflows/orchestration/group_chat_agent_manager.py. Instead of using AzureOpenAI client, I use AzureAIClient to create a coordinator manager.
Does GroupChatBuild.set_manager support AzureAIClient ? Or just AzureOpenAIChatClient as used in all group_chat samples`?
changed the title [-]agent_framework.exceptions.ServiceResponseException: <class 'agent_framework_azure_ai._client.AzureAIClient'> service failed to complete the prompt: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'ManagerSelectionResponse'....[/-][+]Python: agent_framework.exceptions.ServiceResponseException: <class 'agent_framework_azure_ai._client.AzureAIClient'> service failed to complete the prompt: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'ManagerSelectionResponse'....[/+]on Dec 7, 2025
Hi @chengyuliu-msft, does your Azure AI deployment support structured outputs? By the error message, it doesn't look like it does. Please let me know which model you're using so I can reproduce it, thanks.
I used gpt-4o for all agents, and gpt-4o does support structed outputs.
I just ran again without modification. Now it shows the same error. Below I also attached the modified python script based on the sample. You can run in your environment and see if you can reproduce.
(.venv-mafv2) azureuser@ci-aml-whisper:~/localfiles/azure-ai-learning/agent-framework/workflows$ python ./workflow-groupchat.py
Starting Group Chat with Agent-Based Manager...
TASK: What are the key benefits of using async/await in Python? Provide a concise summary.
================================================================================
INFO:agent_framework._workflows._runner:Yielding pre-loop events
INFO:agent_framework._workflows._runner:Starting superstep 1
INFO:azure.identity.aio._internal.decorators:AzureCliCredential.get_token_info succeeded
INFO:azure.core.pipeline.policies.http_logging_policy:Request URL: 'https://aifstdswejwg7.services.ai.azure.com/api/projects/proj-defaultjwg7/agents/Coordinator/versions?api-version=REDACTED'
Request method: 'POST'
Request headers:
'Content-Type': 'application/json'
'Content-Length': '1973'
'Accept': 'application/json'
'x-ms-client-request-id': '7462f884-d485-11f0-8c42-77cd6f345267'
'User-Agent': 'azsdk-python-ai-projects/2.0.0b2 Python/3.10.12 (Linux-6.8.0-1026-azure-x86_64-with-glibc2.35)'
'Authorization': 'REDACTED'
A body is sent with the request
INFO:azure.core.pipeline.policies.http_logging_policy:Response status: 200
Response headers:
'Transfer-Encoding': 'chunked'
'Content-Type': 'application/json; charset=utf-8'
'Content-Encoding': 'REDACTED'
'Vary': 'REDACTED'
'request-context': 'REDACTED'
'x-ms-response-type': 'REDACTED'
'x-request-id': 'REDACTED'
'api-supported-versions': 'REDACTED'
'azureml-served-by-cluster': 'REDACTED'
'apim-request-id': 'REDACTED'
'Strict-Transport-Security': 'REDACTED'
'x-content-type-options': 'REDACTED'
'x-ms-region': 'REDACTED'
'Date': 'Mon, 08 Dec 2025 22:30:11 GMT'
INFO:azure.identity.aio._internal.decorators:AzureCliCredential.get_token_info succeeded
INFO:httpx:HTTP Request: POST https://aifstdswejwg7.services.ai.azure.com/api/projects/proj-defaultjwg7/openai/responses?api-version=2025-11-15-preview "HTTP/1.1 400 Bad Request"
Traceback (most recent call last):
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/openai/_responses_client.py", line 147, in _inner_get_streaming_response
response = await client.responses.create(
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/openai/resources/responses/responses.py", line 2476, in create
return await self._post(
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/openai/_base_client.py", line 1794, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/openai/_base_client.py", line 1594, in request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'ManagerSelectionResponse': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'selected_participant'.", 'type': 'invalid_request_error', 'param': 'text.format.schema', 'code': 'invalid_json_schema'}}
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/azureuser/localfiles/azure-ai-learning/agent-framework/workflows/./workflow-groupchat.py", line 161, in <module>
asyncio.run(main())
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/azureuser/localfiles/azure-ai-learning/agent-framework/workflows/./workflow-groupchat.py", line 130, in main
async for event in workflow.run_stream(task):
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_workflow.py", line 524, in run_stream
async for event in self._run_workflow_with_tracing(
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_workflow.py", line 349, in _run_workflow_with_tracing
async for event in self._runner.run_until_convergence():
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_runner.py", line 111, in run_until_convergence
await iteration_task
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_runner.py", line 182, in _run_iteration
await asyncio.gather(*tasks)
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_runner.py", line 178, in _deliver_messages
await asyncio.gather(*tasks)
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_runner.py", line 153, in _deliver_message_inner
return await edge_runner.send_message(message, self._shared_state, self._ctx)
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_edge_runner.py", line 145, in send_message
await self._execute_on_target(target_id, [source_id], message, shared_state, ctx)
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_edge_runner.py", line 76, in _execute_on_target
await target_executor.execute(
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_executor.py", line 270, in execute
await handler(message, context)
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_executor.py", line 541, in wrapper
return await func(self, message, ctx)
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_agent_executor.py", line 119, in run
await self._run_agent_and_emit(ctx)
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_agent_executor.py", line 276, in _run_agent_and_emit
response = await self._run_agent_streaming(cast(WorkflowContext, ctx))
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_workflows/_agent_executor.py", line 333, in _run_agent_streaming
async for update in self._agent.run_stream(
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/observability.py", line 1168, in trace_run_streaming
async for streaming_agent_response in run_streaming_func(self, messages=messages, thread=thread, **kwargs):
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_agents.py", line 1023, in run_stream
async for update in self.chat_client.get_streaming_response(
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_tools.py", line 1800, in streaming_function_invocation_wrapper
async for update in func(self, messages=prepped_messages, **kwargs):
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/observability.py", line 924, in trace_get_streaming_response
async for update in func(self, messages=messages, **kwargs):
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_middleware.py", line 1415, in _stream_generator
async for update in original_get_streaming_response(self, messages, **kwargs):
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/_clients.py", line 673, in get_streaming_response
async for update in self._inner_get_streaming_response(
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/agent_framework/openai/_responses_client.py", line 172, in _inner_get_streaming_response
raise ServiceResponseException(
agent_framework.exceptions.ServiceResponseException: <class 'agent_framework_azure_ai._client.AzureAIClient'> service failed to complete the prompt: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'ManagerSelectionResponse': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'selected_participant'.", 'type': 'invalid_request_error', 'param': 'text.format.schema', 'code': 'invalid_json_schema'}}
Here is my python codes:
# Copyright (c) Microsoft. All rights reserved.
import asyncio
import dotenv
import logging
import os
from typing import cast
from agent_framework import (
AgentRunUpdateEvent,
ChatAgent,
ChatMessage,
GroupChatBuilder,
Role,
WorkflowOutputEvent,
)
from agent_framework.azure import AzureOpenAIChatClient
from azure.identity import AzureCliCredential
from agent_framework.azure import AzureAIClient, AzureOpenAIResponsesClient
from azure.identity.aio import AzureCliCredential
from azure.ai.projects.aio import AIProjectClient
from pydantic import BaseModel, Field
from typing import Any
# For loading the `AZURE_AI_PROJECT_ENDPOINT` environment variable
dotenv.load_dotenv()
logging.basicConfig(level=logging.INFO)
"""
Sample: Group Chat with Agent-Based Manager
What it does:
- Demonstrates the new set_manager() API for agent-based coordination
- Manager is a full ChatAgent with access to tools, context, and observability
- Coordinates a researcher and writer agent to solve tasks collaboratively
Prerequisites:
- OpenAI environment variables configured for OpenAIChatClient
"""
def _get_chat_client() -> AzureOpenAIChatClient:
return AzureOpenAIChatClient(credential=AzureCliCredential())
async def main() -> None:
credential = AzureCliCredential()
client_project = AIProjectClient(endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], credential=credential)
client_openai = client_project.get_openai_client()
client_agent = AzureAIClient(
async_credential=credential,
project_client=client_project,
model_deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
use_latest_version=False,
max_tokens=20000, # Ensure enough tokens for complete JSON response
)
try:
manager = ChatAgent(
chat_client=client_agent,
name="Coordinator",
description="Coordinates multi-agent collaboration by selecting speakers",
instructions="""
You coordinate a team conversation to solve the user's task.
Review the conversation history and select the next participant to speak.
Guidelines:
- Start with Researcher to gather information
- Then have Writer synthesize the final answer
- Only finish after both have contributed meaningfully
- Allow for multiple rounds of information gathering if needed
""",
)
coordinator = ChatAgent(
name="Coordinator",
description="Coordinates multi-agent collaboration by selecting speakers",
instructions="""
You coordinate a team conversation to solve the user's task.
Review the conversation history and select the next participant to speak.
Guidelines:
- Start with Researcher to gather information
- Then have Writer synthesize the final answer
- Only finish after both have contributed meaningfully
- Allow for multiple rounds of information gathering if needed
""",
chat_client=_get_chat_client(),
)
researcher = ChatAgent(
name="Researcher",
description="Collects relevant background information",
instructions="Gather concise facts that help a teammate answer the question.",
chat_client=_get_chat_client(),
)
writer = ChatAgent(
name="Writer",
description="Synthesizes polished answers from gathered information",
instructions="Compose clear and structured answers using any notes provided.",
chat_client=_get_chat_client(),
)
workflow = (
GroupChatBuilder()
.set_manager(manager, display_name="Orchestrator")
.with_termination_condition(lambda messages: sum(1 for msg in messages if msg.role == Role.ASSISTANT) >= 2)
.participants([researcher, writer])
.build()
)
task = "What are the key benefits of using async/await in Python? Provide a concise summary."
print("\nStarting Group Chat with Agent-Based Manager...\n")
print(f"TASK: {task}\n")
print("=" * 80)
final_conversation: list[ChatMessage] = []
last_executor_id: str | None = None
async for event in workflow.run_stream(task):
if isinstance(event, AgentRunUpdateEvent):
eid = event.executor_id
if eid != last_executor_id:
if last_executor_id is not None:
print()
print(f"{eid}:", end=" ", flush=True)
last_executor_id = eid
print(event.data, end="", flush=True)
elif isinstance(event, WorkflowOutputEvent):
final_conversation = cast(list[ChatMessage], event.data)
if final_conversation and isinstance(final_conversation, list):
print("\n\n" + "=" * 80)
print("FINAL CONVERSATION")
print("=" * 80)
for msg in final_conversation:
author = getattr(msg, "author_name", "Unknown")
text = getattr(msg, "text", str(msg))
print(f"\n[{author}]")
print(text)
print("-" * 80)
finally:
# Clean up all async resources
await credential.close()
await client_project.close()
await client_agent.close()
# Close the shared chat client's internal aiohttp session
if __name__ == "__main__":
asyncio.run(main())
Another thing I found was that I added these two lines of codes before workflow definition, then it led to different error. Hard to know what was issue. Maybe this information can help you to find the root cause.
result = await manager.run("hello world.")
print(result)
.......
File "/home/azureuser/.venv-mafv2/lib/python3.10/site-packages/pydantic/main.py", line 766, in model_validate_json
return cls.__pydantic_validator__.validate_json(
pydantic_core._pydantic_core.ValidationError: 1 validation error for ManagerSelectionResponse
Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='Researcher, please ident...async/await` in Python.', input_type=str]
For further information visit https://errors.pydantic.dev/2.12/v/json_invalid
Using 1.0.0rc5, the framework is failing consistently for Response API clients.
agent_framework.exceptions.ChatClientException: <class 'agent_framework.azure._responses_client.AzureOpenAIResponsesClient'> service failed to complete the prompt: 'MockValSer' object is not an instance of 'SchemaSerializer'
Activity
[-]agent_framework.exceptions.ServiceResponseException: <class 'agent_framework_azure_ai._client.AzureAIClient'> service failed to complete the prompt: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'ManagerSelectionResponse'....[/-][+]Python: agent_framework.exceptions.ServiceResponseException: <class 'agent_framework_azure_ai._client.AzureAIClient'> service failed to complete the prompt: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'ManagerSelectionResponse'....[/+]moonbox3 commentedon Dec 8, 2025
Hi @chengyuliu-msft, does your Azure AI deployment support structured outputs? By the error message, it doesn't look like it does. Please let me know which model you're using so I can reproduce it, thanks.
chengyu-liu-cs commentedon Dec 8, 2025
I used gpt-4o for all agents, and gpt-4o does support structed outputs.
I just ran again without modification. Now it shows the same error. Below I also attached the modified python script based on the sample. You can run in your environment and see if you can reproduce.
Here is my python codes:
Another thing I found was that I added these two lines of codes before workflow definition, then it led to different error. Hard to know what was issue. Maybe this information can help you to find the root cause.
moonbox3 commentedon Dec 11, 2025
Thanks for the added context @chengyuliu-msft. Fix is in #2750.
chengyu-liu-cs commentedon Dec 12, 2025
Thanks. Evan Mattson (@moonbox3)
I checked out the latest release and tested again.
Many times it failed with
Invalid JSONerror if I useAzureAIClientclient. However it always works forAzureOpenAIChatClientclient.When I checked DEBUG logs, it shows below.
Hungreeee commentedon Apr 1, 2026
Using 1.0.0rc5, the framework is failing consistently for Response API clients.