Basic agent invocation sample (#175)

* Basic agent invocation sample

* Simplify sample further.

* Add additional comment.

* Address code review comments.

* Suppress CA2000 and remove using from most basic sample, since the IChatClient instances involved do not do any disposal.
This commit is contained in:
westey
2025-07-14 15:15:46 +00:00
committed by GitHub
parent 407ed6de70
commit 55045b5c1e
3 changed files with 34 additions and 4 deletions
+4 -3
View File
@@ -6,6 +6,7 @@ using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.Agents;
using Microsoft.Shared.Diagnostics;
using Microsoft.Shared.Samples;
using OpenAI.Assistants;
using OpenAI.Chat;
@@ -31,13 +32,13 @@ public class AgentSample(ITestOutputHelper output) : BaseSample(output)
AzureAIAgentsPersistent
}
protected IChatClient GetChatClient(ChatClientProviders provider, ChatClientAgentOptions options)
protected IChatClient GetChatClient(ChatClientProviders provider, ChatClientAgentOptions? options = null)
=> provider switch
{
ChatClientProviders.OpenAIChatCompletion => GetOpenAIChatClient(),
ChatClientProviders.OpenAIAssistant => GetOpenAIAssistantChatClient(options),
ChatClientProviders.OpenAIAssistant => GetOpenAIAssistantChatClient(Throw.IfNull(options)),
ChatClientProviders.AzureOpenAI => GetAzureOpenAIChatClient(),
ChatClientProviders.AzureAIAgentsPersistent => GetAzureAIAgentPersistentClient(options),
ChatClientProviders.AzureAIAgentsPersistent => GetAzureAIAgentPersistentClient(Throw.IfNull(options)),
ChatClientProviders.OpenAIResponses or
ChatClientProviders.OpenAIResponses_InMemoryMessageThread or
ChatClientProviders.OpenAIResponses_ConversationIdThread