Python: Bug: Python: Potential Bug in FunctionChoiceBehavior.Required() and FunctionChoiceBehavior.Auto()
Describe the bug So i was playing around with FunctionChoiceBehavior.Required() in a Project and noticed some strange behavior.
- When i use
kernel.invoke()withFunctionChoiceBehavior.Required(autoinvoke=true)the first time the function is executed, i recieve an FunctionCallContent Object back instead of FunctionResultContent/TextContent Object. - When i use
kernel.invoke()withFunctionChoiceBehavior.Required(autoinvoke=true)the second time the function is not executed, i recieve an FunctionCallContent Object back instead of FunctionResultContent/TextContent Object.
I think it has to do with the following line , this will set the auto_invoke_kernel_functions to False after the first execution.
When you do another request then, it will hit the following if statement , this results in the Function is not Executed.
This could potentially also impact FunctionChoiceBehavior.Auto() when 5 Functions are called in the Loop. Then the property is set to false and no more Functions would be executed by the Kernel.
Probably me as a user can get around this when i reset the settings after kernel.invoke(), but i am not sure if this is intended.
To Reproduce Steps to reproduce the behavior:
- Go to
samples/concepts/function_calling_with_required_type.py - Change Line 55 to
stream = False - Use a Debugger or add the Following Lines at 173
print(type(result.value[0].items[0]))
print([type(message.items[0]) for message in result.metadata['messages'].messages])
- Run the
samples/concepts/function_calling_with_required_type.py2 Times
Expected behavior
- The first time running with
FunctionChoiceBehavior.Required(autoinvoke=true)i would expect a FunctionResultContent Object or a TextContent Object answer based on the Function Result - The second time running with
FunctionChoiceBehavior.Required(autoinvoke=true)i would expect a FunctionResultContent Object or a TextContent Object with the answer based on the Function Result
Screenshots
Additional context Add any other context about the problem here.
Hi @nmoeller, the behavior you're introducing in #7448 isn't what we'd like to support. The Required FunctionChoiceBehavior forces the model to only perform a function call (it's essentially requiring the caller to handle a manual tool call). We shouldn't be performing a final chat completion while modifying the underlying FunctionChoiceBehavior settings once the max auto invoke attempts are hit.
This issue is stale because it has been open for 90 days with no activity.
Closing as we're tracking an AzureChatCompletion FunctionChoiceBehavior.Required() bug in a separate issue.