mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: Fix error for ChatClientAgent DI ambiguity (#299)
* Fix error for ChatClientAgent DI ambiguity * Using AIAgent abstraction for DI samples * Update dotnet/samples/GettingStarted/Steps/Step04_ChatClientAgent_DependencyInjection.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix warnings --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -65,7 +65,7 @@ public class AgentSample(ITestOutputHelper output) : BaseSample(output)
|
||||
/// <remarks>
|
||||
/// Ideally for faster execution and potential cost savings, server-side agents should be reused.
|
||||
/// </remarks>
|
||||
protected Task AgentCleanUpAsync(ChatClientProviders provider, ChatClientAgent agent, AgentThread? thread = null, CancellationToken cancellationToken = default)
|
||||
protected Task AgentCleanUpAsync(ChatClientProviders provider, AIAgent agent, AgentThread? thread = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return provider switch
|
||||
{
|
||||
@@ -157,9 +157,9 @@ public class AgentSample(ITestOutputHelper output) : BaseSample(output)
|
||||
|
||||
#region Private AgentCleanUp
|
||||
|
||||
private async Task AzureAIAgentsPersistentAgentCleanUpAsync(ChatClientAgent agent, AgentThread? thread, CancellationToken cancellationToken)
|
||||
private async Task AzureAIAgentsPersistentAgentCleanUpAsync(AIAgent agent, AgentThread? thread, CancellationToken cancellationToken)
|
||||
{
|
||||
var persistentAgentsClient = agent.ChatClient.GetService<PersistentAgentsClient>() ??
|
||||
var persistentAgentsClient = (agent as ChatClientAgent)?.ChatClient.GetService<PersistentAgentsClient>() ??
|
||||
throw new InvalidOperationException("The provided chat client is not a Persistent Agents Chat Client");
|
||||
|
||||
await persistentAgentsClient.Administration.DeleteAgentAsync(agent.Id, cancellationToken);
|
||||
@@ -171,9 +171,9 @@ public class AgentSample(ITestOutputHelper output) : BaseSample(output)
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OpenAIAssistantCleanUpAgentAsync(ChatClientAgent agent, AgentThread? thread, CancellationToken cancellationToken)
|
||||
private async Task OpenAIAssistantCleanUpAgentAsync(AIAgent agent, AgentThread? thread, CancellationToken cancellationToken)
|
||||
{
|
||||
var assistantClient = agent.ChatClient
|
||||
var assistantClient = (agent as ChatClientAgent)?.ChatClient
|
||||
.GetService<AssistantClient>()
|
||||
?? throw new InvalidOperationException("The provided chat client is not an OpenAI Assistant Chat Client");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user