Description
Hi,
I found that no functions are being called although assistant has functions information. I am defining functions as classes with [KernelFunction] method attribute. But same setup is working for OpenAI and Azure OpenAI. Here are details:
Here are snippets of my code setup:
var bedrockClient = new AmazonBedrockRuntimeClient(awsCredentials, region);
var chatClient = bedrockClient.AsIChatClient(modelId);
var chatCompletionService = chatClient.AsChatCompletionService();
var builder = Kernel.CreateBuilder();
builder.Services.AddSingleton(chatCompletionService);
builder.Plugins.AddFromObject(_workItemSkill, "SKWorkItemSkill");
builder.Plugins.AddFromObject(_querySkill, "SKQuerySkill");
builder.Plugins.AddFromObject(_dataSkill, "SKDataSkill");
builder.Plugins.AddFromObject(_pythonSkill, "SKPythonSkill");
builder.Build();
IChatCompletionService chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();
promptExecutionSettings = new AnthropicPromptExecutionSettings()
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(),
Temperature = 0.5,
ModelId = modelId // modelId = us.anthropic.claude-3-5-sonnet-20241022-v2:0
};
await foreach (var c in chatCompletionService.GetStreamingChatMessageContentsAsync(history, promptExecutionSettings, cancellationToken:cancellationToken, kernel: kernel))
{}
When I asked assistant:
what functions or tool call are available
It answered me right:
SKWorkItemSkill_CreateWorkItem
SKWorkItemSkill_UpdateWorkItem
SKWorkItemSkill_PatchWorkItem
SKWorkItemSkill_DeleteWorkItem
SKWorkItemSkill_LinkWorkItems
SKWorkItemSkill_AddCommentToWorkItem
SKWorkItemSkill_DeleteWorkItemLink
SKWorkItemSkill_GetCurrentWorkItem
SKWorkItemSkill_GetCurrentWorkItems
SKQuerySkill_CreateQuery
SKQuerySkill_UpdateQuery
SKQuerySkill_DeleteQuery
SKQuerySkill_GetQueryType
SKQuerySkill_GetCurrentQuery
SKDataSkill_GetWorkItem
SKDataSkill_GetLinkedWorkItems
SKDataSkill_GetWorkItems
SKDataSkill_GetWorkItemsByIds
SKDataSkill_GetWorkItemsByType
SKDataSkill_GetWorkItemsByQueryId
SKDataSkill_GetWorkItemsByQueryString
SKDataSkill_GetWorkItemTypes
SKDataSkill_GetWorkItemTypeDefinition
SKDataSkill_GetRelationTypes
SKDataSkill_SearchWorkItems
SKDataSkill_GetUsers
SKDataSkill_GetProjects
SKDataSkill_GetQueries
SKDataSkill_GetBacklogWorkItems
SKDataSkill_GetCurrentSprint
SKDataSkill_GenerateMermaidDiagram
SKDataSkill_ConvertMermaidToImage
SKDataSkill_ConvertHtmlToImage
SKDataSkill_GetDownloadLinkForFileContent
SKPythonSkill_ListPythonLibraries
SKPythonSkill_InstallPythonLibrary
SKPythonSkill_RunPythonCode
Also when I asked that:
Create Epic work item for User Management, generate title and description by yourself
it answered following but did not do any function call and stops streaming in 2-3 secs after sending last message(after last message it does wait for 2-3 secs.):
**
Certainly, I'll create an Epic work item for User Management with a generated title and description right away.
Thinking: Generating title and description for User Management Epic
Creating: Preparing to create new Epic work item
Now, I'll use the SKWorkItemSkill_CreateWorkItem function to create this Epic:
**
Also I checked StreamingChatMessageContent does receive function call related data, but function doesn't call:
{"Content":null,"Items":[{"CallId":"tooluse_bTgNyH1HQauYzRHFj5D5Wg","Name":"SKWorkItemSkill_CreateWorkItem","Arguments":"{\r\n \"workItemType\": \"Epic\",\r\n \"title\": \"Implement Comprehensive User Management System\",\r\n \"description\": \"\\u003Cdiv\\u003E\\n\\u003Ch2\\u003EEpic: Implement Comprehensive User Management System\\u003C/h2\\u003E\\n\\n\\u003Cp\\u003EThis epic encompasses the development and implementation of a robust user management system to enhance our application\\u0027s security, user experience, and administrative capabilities.\\u003C/p\\u003E\\n\\n\\u003Ch3\\u003EObjectives:\\u003C/h3\\u003E\\n\\u003Cul\\u003E\\n \\u003Cli\\u003EStreamline user registration and onboarding processes\\u003C/li\\u003E\\n \\u003Cli\\u003EEnhance authentication and authorization mechanisms\\u003C/li\\u003E\\n \\u003Cli\\u003EImplement role-based access control (RBAC)\\u003C/li\\u003E\\n \\u003Cli\\u003EDevelop user profile management features\\u003C/li\\u003E\\n \\u003Cli\\u003ECreate administrative tools for user oversight and management\\u003C/li\\u003E\\n\\u003C/ul\\u003E\\n\\n\\u003Ch3\\u003EKey Features:\\u003C/h3\\u003E\\n\\u003Cul\\u003E\\n \\u003Cli\\u003EUser registration with email verification\\u003C/li\\u003E\\n \\u003Cli\\u003ESecure login system with multi-factor authentication\\u003C/li\\u003E\\n \\u003Cli\\u003EPassword reset and account recovery mechanisms\\u003C/li\\u003E\\n \\u003Cli\\u003EUser profile creation and editing\\u003C/li\\u003E\\n \\u003Cli\\u003ERole and permission management\\u003C/li\\u003E\\n \\u003Cli\\u003EUser activity tracking and reporting\\u003C/li\\u003E\\n \\u003Cli\\u003EAccount deactivation and deletion processes\\u003C/li\\u003E\\n \\u003Cli\\u003EIntegration with existing systems and databases\\u003C/li\\u003E\\n\\u003C/ul\\u003E\\n\\n\\u003Ch3\\u003EExpected Outcomes:\\u003C/h3\\u003E\\n\\u003Cul\\u003E\\n \\u003Cli\\u003EImproved security and data protection\\u003C/li\\u003E\\n \\u003Cli\\u003EEnhanced user satisfaction and engagement\\u003C/li\\u003E\\n \\u003Cli\\u003EReduced administrative overhead\\u003C/li\\u003E\\n \\u003Cli\\u003EScalable user management infrastructure\\u003C/li\\u003E\\n \\u003Cli\\u003ECompliance with data protection regulations\\u003C/li\\u003E\\n\\u003C/ul\\u003E\\n\\n\\u003Cp\\u003EThis epic will serve as the foundation for all user-related functionalities in our application, ensuring a secure, efficient, and user-friendly experience.\\u003C/p\\u003E\\n\\u003C/div\\u003E\"\r\n}","FunctionCallIndex":0,"RequestIndex":0,"ChoiceIndex":0,"InnerContent":null,"ModelId":null,"Metadata":null}],"AuthorName":null,"Role":{"Label":"assistant"},"Encoding":{"BodyName":"utf-8","EncodingName":"Unicode (UTF-8)","HeaderName":"utf-8","WebName":"utf-8","WindowsCodePage":1200,"IsBrowserDisplay":true,"IsBrowserSave":true,"IsMailNewsDisplay":true,"IsMailNewsSave":true,"IsSingleByte":false,"EncoderFallback":{"DefaultString":"?","MaxCharCount":1},"DecoderFallback":{"DefaultString":"?","MaxCharCount":1},"IsReadOnly":true,"CodePage":65001},"ChoiceIndex":0,"InnerContent":{"ContentBlockIndex":1},"ModelId":null,"Metadata":null}
My Nuget API versions:
Microsoft.SemanticKernel 1.57.0
Microsoft.SemanticKernel.Connectors.Amazon 1.57.0-alpha
AWSSdk.BedrockRuntime 4.0.0.10
AWSSdk.Extensions.Bedrock.MEAI 4.0.1.1
Microsoft.Extensions.AI 9.6.0
Please let me know if further details are needed. Waiting for response.
Thanks,
Mustafa
More updates:
I also checked my code with Google Gemini, function calling is also not happening with it, here are details which are different from the details I shared above:
promptExecutionSettings = new GeminiPromptExecutionSettings()
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(),
Temperature = (reasoningEffort == null || reasoningEffort == string.Empty)
? (float?)temperature
: null,
ModelId = modelId, // gemini-2.5-pro
ResponseMimeType = (convertToJSON == null || convertToJSON == false)
? null
: "application/json",
};
Nuget API Vesion for Google Connector:
Microsoft.SemanticKernel.Connectors.Google 1.57.0-alpha
I am also sharing one of my Skills class for sample:
using System;
using System.Diagnostics;
using System.IO;
using System.ComponentModel;
using Microsoft.SemanticKernel;
using Newtonsoft.Json;
public class SKPythonSkill
{
private readonly ILogger _logger;
public SKPythonSkill(ILogger logger)
{
_logger = logger;
}
[KernelFunction("ListPythonLibraries")]
[Description("Lists all installed Python libraries using pip.")]
public string ListPythonLibraries([Description("Dummy parameter, it's not required.")]
string dummy)
{
try
{
var psi = new ProcessStartInfo
{
FileName = "pip",
Arguments = "list",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using var process = Process.Start(psi);
var output = process.StandardOutput.ReadToEnd();
var error = process.StandardError.ReadToEnd();
process.WaitForExit();
return string.IsNullOrEmpty(error) ? output : $"{output}\nError: {error}";
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
return JsonConvert.SerializeObject(new { error = ex.Message });
}
}
[KernelFunction("InstallPythonLibrary")]
[Description("Installs a Python library via pip.")]
public string InstallPythonLibrary(
[Description("Name of the Python library to install.")]
string libraryName)
{
try
{
var psi = new ProcessStartInfo
{
FileName = "pip",
Arguments = $"install {libraryName}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using var process = Process.Start(psi);
var output = process.StandardOutput.ReadToEnd();
var error = process.StandardError.ReadToEnd();
process.WaitForExit();
return string.IsNullOrEmpty(error) ? output : $"{output}\nError: {error}";
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
return JsonConvert.SerializeObject(new { error = ex.Message });
}
}
[KernelFunction("RunPythonCode")]
[Description("Executes a Python code snippet and returns its output.")]
public string RunPythonCode(
[Description("Python code to execute.")]
string code)
{
var tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".py");
try
{
File.WriteAllText(tempFile, code);
var psi = new ProcessStartInfo
{
FileName = "python",
Arguments = tempFile,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using var process = Process.Start(psi);
var output = process.StandardOutput.ReadToEnd();
var error = process.StandardError.ReadToEnd();
process.WaitForExit();
return string.IsNullOrEmpty(error) ? output : $"{output}\nError: {error}";
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
return JsonConvert.SerializeObject(new { error = ex.Message });
}
finally
{
try { File.Delete(tempFile); } catch { }
}
}
}
Metadata
Metadata
Assignees
Type
Projects
Status