Skip to content

.Net: Function invocation improvements #13165

@dmytrostruk

Description

@dmytrostruk

In Semantic Kernel Auto invocation works as follows (link):

  1. Serialize functions: All of the available functions (and its input parameters) in the kernel are serialized using JSON schema.
  2. Send the messages and functions to the model: The serialized functions (and the current chat history) are sent to the model as part of the input.
  3. Model processes the input: The model processes the input and generates a response. The response can either be a chat message or one or more function calls.
  4. Handle the response: If the response is a chat message, it is returned to the caller. If the response is a function call, however, Semantic Kernel extracts the function name and its parameters.
  5. Invoke the function: The extracted function name and parameters are used to invoke the function in the kernel.
  6. Return the function result: The result of the function is then sent back to the model as part of the chat history. Steps 2-6 are then repeated until the model returns a chat message or the max iteration number has been reached.

If a ChatMessageContent is the last message in the chat history and a parameter is passed, e.g. AllowFunctionInvocationFirst = true, then skip to step 5 and invoke the functions in that final message before continuing with the auto loop.

Use Case

For our invocation we may want to get feedback from the user before continuing with the chat. Think, for example, distructiveHint in MCP but our own version.

Current Work Around

Our current workaround is to decorate the IChatCompletionService with a service that returns the ChatMessageContent first as a "fake" invocation of the model, but it would be great to add this to the framework directly somehow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETIssue or Pull requests regarding .NET codetriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions