semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Python: Fencing Function calling stepwise planner response

Open karth123 opened this issue 1 year ago • 1 comments

I am experimenting with function calling stepwise planner in python version of semantic kernel. I want to provide a generic response when the Copilot is asked a question which it cannot use its catalog of tools to answer. This is the native function registered:

async def fall_back_function(self,ask:str) -> str:
        """ This is a fallback function in case the planner cannot identify any other functions which can be used to generate a response to the ask
        The planner should use this function as a final recourse fallback if it identifies it cannot satisfy the ask with any other function. Make sure to use the function if you suspect you cannot
        answer the query with other available functions.
        Here are situations where the fall back function is to be used:
        If the ask cannot be satisfied by even ONE other imported function and forces the LLM to generate a response from its training data. 
        Instead of doing that, return the fallback function response. If you invoked this function, that means there is no more work to do."""

        response = f"The query {ask} could not be satisfied by the Copilot. Please try again."
        return response

Directly registering this native function and loading it into the kernel doesn't do anything, as the function calling stepwise planner invokes UserInteraction-SendFinalAnswer and doesn't directly pass the response of the native function. The planner identifies that it must use the fallback function, but the response of the fallback function isn't directly passed. Somewhere in the chain, the LLM is using its intelligence to respond to the ask.

In "function_calling_stepwise_planner.py", line 42 I modify STEPWISE_USER_MESSAGE with an additional line: "If you have used the fall back kernel function, directly return its response as the final answer." This aligns the copilot.

Is there a better approach as I don't want to be modifying imported libraries.

karth123 avatar Apr 17 '24 18:04 karth123

Hi @karth123, have you tried configuring the callbacks to your own plan/step prompt files? The options are available here. You could use the default plan/prompt files as a reference and update them as needed so it uses your fallback function.

moonbox3 avatar May 02 '24 14:05 moonbox3

Closing as there has not been a response. Please re-open or create a new issue as needed.

moonbox3 avatar Jul 03 '24 15:07 moonbox3