Repository navigation
Closed
Labels
agentspythonPull requests for the Python Semantic KernelPull requests for the Python Semantic Kernel
Description
Description
When running a group chat between a critic (ChatCompletionAgent) and a data scientist (AzureAssistantAgent), the AzureChatCompletion service fails with a "Missing required parameter" error.
Error Message
("<class 'semantic_kernel.connectors.ai.open_ai.services.azure_chat_completion.AzureChatCompletion'> service failed to complete the prompt", BadRequestError('Error code: 400 - {'error': {'message': "Missing required parameter: 'messages[5].content[0].type'.", 'type': 'invalid_request_error', 'param': 'messages[5].content[0].type', 'code': 'missing_required_parameter'}}'))
Relevant Code
# Selection config
SELECTION_PROMPT: str = f"""Determine which participant takes the next turn in a conversation based on the the most recent participant.
State only the name of the participant to take the next turn.
No participant should take more than one turn in a row.
Choose only from these participants:
- {CRITIC_NAME}
- {DS_NAME}
Always follow these rules when selecting the next participant:
- After user input, it is {DS_NAME}'s turn.
- After {DS_NAME} replies, it is {CRITIC_NAME}'s turn.
- After {CRITIC_NAME} provides feedback, it is {DS_NAME}'s turn.
History:
{{{{$history}}}}"""
# Termination config
TERMINATION_KEYWORD = "yes"
TERMINATION_PROMPT: str = f"""Examine the RESPONSE and determine whether the data scientist has met the targeted performance metric based on the critic's feedback.
If the critic provides specific suggestions for improvement, the results are not satisfactory.
If no correction is suggested, the results are satisfactory.
When the results are satisfactory, respond with a single word without explanation: {TERMINATION_KEYWORD}.
RESPONSE:
{{{{$history}}}}"""
# Init the group chat
chat = AgentGroupChat(
agents=[ds_scientist, critic],
selection_strategy=KernelFunctionSelectionStrategy(
function=selection_function,
kernel=_create_kernel_with_chat_completion("selection"),
result_parser=lambda result: (
str(result.value[0]) if result.value is not None else ds_scientist
),
agent_variable_name="agents",
history_variable_name="history",
),
termination_strategy=KernelFunctionTerminationStrategy(
agents=[critic],
function=termination_function,
kernel=_create_kernel_with_chat_completion("termination"),
result_parser=lambda result: TERMINATION_KEYWORD in str(result.value[0]).lower(),
history_variable_name="history",
maximum_iterations=10,
),
)Steps to Reproduce
- Set up a group chat with a ChatCompletionAgent and an AzureAssistantAgent
- Configure the chat with KernelFunctionSelectionStrategy and KernelFunctionTerminationStrategy
- Attempt to run the group chat
try:
# Loop variables
is_complete: bool = False # Whether to complete the conversation
file_ids: list[str] = [] # File ids created by the assistant to track
# User message
USER_MSG: str = "A brief introduction to the dataset with some visual aids."
print("TASK:", USER_MSG)
# Add the user message to the history
await chat.add_chat_message(
message=ChatMessageContent(role=AuthorRole.USER, content=USER_MSG),
)
while not is_complete:
# Start the groupchat
is_code: bool = False
async for response in chat.invoke():
# Whether the content is a code snippet
if is_code != response.metadata.get("code"):
print()
print(f"{'-'* 10} CODE {'-'* 10}\n")
is_code = not is_code
# Print the response
print(
f"# {response.role} - {response.name or '*'}: '{response.content}'"
)
# Collect the file ids
file_ids.extend(
[
item.file_id
for item in response.items
if isinstance(item, FileReferenceContent)
]
)
print()
# Download any image created by the Azure Assistant
await download_response_image(ds_scientist, file_ids)
# Then clear the list for the subsequent session
file_ids.clear()
# Whether the chat ended
if chat.is_complete:
is_complete = True
except Exception as e:
# Trace the error
print(e)
finally:
# Clean up resources
print("Cleaning up Azure resources...")
if ds_scientist is not None:
await _clean_up_resources(agent=ds_scientist, thread_id=ds_thread_id)Expected Behavior
- The group chat should run without errors, allowing the agents to communicate and complete the task.
Actual Behavior
- The
AzureChatCompletionservice fails with a "Missing required parameter" error, specifically mentioning 'messages[5].content[0].type'. I believe the error occurs during internal group chat conversations when the turn is held by thecritic.
Metadata
Metadata
Assignees
Labels
agentspythonPull requests for the Python Semantic KernelPull requests for the Python Semantic Kernel
Type
Projects
- StatusShow more project fieldsNo status
Activity
moonbox3 commentedon Jan 28, 2025
Are you able to turn on debug logging and get the payload you're sending before the 400 occurs?
anu43 commentedon Jan 29, 2025
Unfortunately, I wasn't able to debug the logging because all events occur within the
AgentGroupChat. Could you suggest a method that would allow me to observe and share the payload with you?moonbox3 commentedon Jan 29, 2025
You can add this to your script that instantiates the group chat:
Please be careful to replace any PII (resource names? endpoints?) so you don't communicate personal data/info.
anu43 commentedon Jan 29, 2025
Thanks. I thought I had to manage background debugging, but this process revealed everything happening under the hood. I believe the user message arrives and is managed without any issue; however, problems start after the chat bounces to the critic. Unfortunately, I still couldn't figure out what the main problem is.
P.S.: As soon as I substitute the
AzureAssistantAgentwith aChatCompletionAgent, the issue goes away. Of course, no code executions—just a chat happens.moonbox3 commentedon Jan 29, 2025
Thanks for your response. Looks like it has to do with:
We currently allow adding
FunctionResultContentto the chat between the agents. If I am understanding correctly, yourdata-scientistAzureAssistantAgent created content with file_id references and it's now calling your critic (ChatCompletionAgent). Does that flow sound right?Let me look into this further.
anu43 commentedon Jan 29, 2025
That's right Evan Mattson (@moonbox3) I insert the titanic.csv dataset with a request for basic intro to the dataset with some visual aids. Then, agent covers everything and returns the charts. In this scenario, the critic should provide some feedback on the response considering the task from the user. The context is simple by design for sure but my intention is to observe the communication between a
ChatCompletionAgentand aAzureAssistantAgent.moonbox3 commentedon Jan 30, 2025
Okay, thanks. Let me dig in today.
anu43 commentedon Jan 30, 2025
After you said that, I wanted to try giving a task without any file delivery. The conversation between the
dsand thecriticwent well without any errors. However, something happens when the assistant provides files.moonbox3 commentedon Jan 30, 2025
Yeah, the bug is that the
file_idcontent doesn't have atype. With that said, we don't even need to be sending thefile_idcontent to the Chat Completion Agent because it will have no notion of what to do with the file_id(s). I'll get a fix out soon to perform that filtering.anu43 commentedon Jan 30, 2025
I believe you solved the issue, right? How can I pull that change?
moonbox3 commentedon Jan 30, 2025
Once the PR merges to main (in-progress), you can do a temp pip install, until we get a new package released (next week):
If you use uv (or Poetry) you'd do something like:
If you're developing in code directly, just sync your fork with main (once the change is in).
Python: intro allowed content types in chat history channel receive. …
bbence84 commentedon Jul 10, 2025
Hm, getting the same error message, so I am not sure if this bug has been resolved already?
I was trying to adapt the Magentic one example to AzureOpenAI:
Python: intro allowed content types in chat history channel receive. …
yescastephanie commentedon Nov 5, 2025
File ids are still being passed to chat completion agent. This is the error I am getting: semantic_kernel.exceptions.service_exceptions.ServiceResponseException: ("<class 'semantic_kernel.connectors.ai.open_ai.services.azure_chat_completion.AzureChatCompletion'> service failed to complete the prompt", BadRequestError('Error code: 400 - {'error': {'message': "Missing required parameter: 'messages[6].content[1].type'.", 'type': 'invalid_request_error', 'param': 'messages[6].content[1].type', 'code': 'missing_required_parameter'}}')) (I am using MagenticOrchestration)