Update sample to also include function calling telemetry (#577)

This commit is contained in:
Roger Barreto
2025-09-01 17:19:00 +00:00
committed by GitHub
parent cf0e779638
commit 19210fc5c9
2 changed files with 58 additions and 44 deletions
@@ -18,7 +18,7 @@ internal static class ChatClientExtensions
chatBuilder.UseAgentInvocation();
}
if (chatClient.GetService<NewFunctionInvokingChatClient>() is null)
if (chatClient.GetService<FunctionInvokingChatClient>() is null && chatClient.GetService<NewFunctionInvokingChatClient>() is null)
{
_ = chatBuilder.Use((IChatClient innerClient, IServiceProvider services) =>
{
@@ -33,7 +33,17 @@ internal static class ChatClientExtensions
if (options?.ChatOptions?.Tools is { Count: > 0 })
{
// When tools are provided in the constructor, set the tools for the whole lifecycle of the chat client
agentChatClient.GetService<NewFunctionInvokingChatClient>()!.AdditionalTools = options.ChatOptions.Tools;
var newFunctionService = agentChatClient.GetService<NewFunctionInvokingChatClient>();
var oldFunctionService = agentChatClient.GetService<FunctionInvokingChatClient>();
if (newFunctionService is not null)
{
newFunctionService.AdditionalTools = options.ChatOptions.Tools;
}
else
{
oldFunctionService!.AdditionalTools = options.ChatOptions.Tools;
}
}
return agentChatClient;