diff --git a/dotnet/samples/Concepts/Agents/ChatCompletion_Streaming.cs b/dotnet/samples/Concepts/Agents/ChatCompletion_Streaming.cs index 7a23efe6e112..6d11dd80ff91 100644 --- a/dotnet/samples/Concepts/Agents/ChatCompletion_Streaming.cs +++ b/dotnet/samples/Concepts/Agents/ChatCompletion_Streaming.cs @@ -81,6 +81,12 @@ private async Task InvokeAgentAsync(ChatCompletionAgent agent, ChatHistory chat, { if (string.IsNullOrEmpty(response.Content)) { + StreamingFunctionCallUpdateContent? functionCall = response.Items.OfType().SingleOrDefault(); + if (!string.IsNullOrEmpty(functionCall?.Name)) + { + Console.WriteLine($"\n# {response.Role} - {response.AuthorName ?? "*"}: FUNCTION CALL - {functionCall.Name}"); + } + continue; } diff --git a/dotnet/samples/Concepts/Agents/OpenAIAssistant_Streaming.cs b/dotnet/samples/Concepts/Agents/OpenAIAssistant_Streaming.cs index e394b8c49dad..39ff0f0fb97c 100644 --- a/dotnet/samples/Concepts/Agents/OpenAIAssistant_Streaming.cs +++ b/dotnet/samples/Concepts/Agents/OpenAIAssistant_Streaming.cs @@ -68,8 +68,8 @@ await OpenAIAssistantAgent.CreateAsync( string threadId = await agent.CreateThreadAsync(new OpenAIThreadCreationOptions { Metadata = AssistantSampleMetadata }); // Respond to user input - await InvokeAgentAsync(agent, threadId, "What is the special soup?"); - await InvokeAgentAsync(agent, threadId, "What is the special drink?"); + await InvokeAgentAsync(agent, threadId, "What is the special soup and its price?"); + await InvokeAgentAsync(agent, threadId, "What is the special drink and its price?"); // Output the entire chat history await DisplayChatHistoryAsync(agent, threadId); @@ -120,6 +120,12 @@ private async Task InvokeAgentAsync(OpenAIAssistantAgent agent, string threadId, { if (string.IsNullOrEmpty(response.Content)) { + StreamingFunctionCallUpdateContent? functionCall = response.Items.OfType().SingleOrDefault(); + if (functionCall != null) + { + Console.WriteLine($"\n# {response.Role} - {response.AuthorName ?? "*"}: FUNCTION CALL - {functionCall.Name}"); + } + continue; } diff --git a/dotnet/samples/GettingStartedWithAgents/Step08_Assistant.cs b/dotnet/samples/GettingStartedWithAgents/Step08_Assistant.cs index 32c03a40a638..1e952810e51e 100644 --- a/dotnet/samples/GettingStartedWithAgents/Step08_Assistant.cs +++ b/dotnet/samples/GettingStartedWithAgents/Step08_Assistant.cs @@ -43,8 +43,8 @@ await OpenAIAssistantAgent.CreateAsync( try { await InvokeAgentAsync("Hello"); - await InvokeAgentAsync("What is the special soup?"); - await InvokeAgentAsync("What is the special drink?"); + await InvokeAgentAsync("What is the special soup and its price?"); + await InvokeAgentAsync("What is the special drink and its price?"); await InvokeAgentAsync("Thank you"); } finally diff --git a/dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs b/dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs index 2a2a7989f116..65f483cc9a8a 100644 --- a/dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs +++ b/dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs @@ -404,6 +404,15 @@ public static async IAsyncEnumerable InvokeStreamin { yield return toolContent; } + else + { + yield return + new StreamingChatMessageContent(AuthorRole.Assistant, null) + { + AuthorName = agent.Name, + Items = [new StreamingFunctionCallUpdateContent(detailsUpdate.ToolCallId, detailsUpdate.FunctionName, detailsUpdate.FunctionArguments)] + }; + } } else if (update is RunStepUpdate stepUpdate) { @@ -493,15 +502,16 @@ await RetrieveMessageAsync( { foreach (RunStepToolCall toolCall in step.Details.ToolCalls) { - switch (toolCall.ToolKind) + if (toolCall.ToolKind == RunStepToolCallKind.Function) + { + messages?.Add(GenerateFunctionResultContent(agent.GetName(), stepFunctionResults[step.Id], step)); + stepFunctionResults.Remove(step.Id); + break; + } + + if (toolCall.ToolKind == RunStepToolCallKind.CodeInterpreter) { - case RunStepToolCallKind.CodeInterpreter: - messages?.Add(GenerateCodeInterpreterContent(agent.GetName(), toolCall.CodeInterpreterInput, step)); - break; - case RunStepToolCallKind.Function: - messages?.Add(GenerateFunctionResultContent(agent.GetName(), stepFunctionResults[step.Id], step)); - stepFunctionResults.Remove(step.Id); - break; + messages?.Add(GenerateCodeInterpreterContent(agent.GetName(), toolCall.CodeInterpreterInput, step)); } } }