Closed
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
AzureChatCompletion
service 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
Type
Projects
Status
No status