semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net: Bug: C#, error in using Microsoft.SemanticKernel.Agents.AzureAI 1.48.0-preview and above

Open BenoityipMSFT opened this issue 7 months ago • 7 comments

Describe the bug When using VS2022 C# .Net 9, and add Nuget package Microsoft.SemanticKernel.Agents.AzureAI 1.48.0-preview and above. Calling GetAgentsClient() method will throw a compile error

using 1.47.0-preview does not have this error

Reference to type 'ConnectionProvider' claims it is defined in 'System.ClientModel', but it could not be found

The code we follow is in https://learn.microsoft.com/en-us/semantic-kernel/frameworks/agent/azure-ai-agent?pivots=programming-language-csharp#configuring-the-ai-project-client

Expected behavior Compile the code successfully

Screenshots Image

BenoityipMSFT avatar May 15 '25 02:05 BenoityipMSFT

Hi @BenoityipMSFT,

ConnectionProvider is certainly defined in System.ClientModel; however, I cannot repro in my own project locally [1.47.0 - 1.50.0].

Here is the source:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <NoWarn>$(NoWarn);SKEXP0110</NoWarn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.SemanticKernel.Agents.AzureAI" Version="1.50.0-preview" />
  </ItemGroup>

</Project>
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.SemanticKernel.Agents.AzureAI;

namespace SKFoundryAgentDependencyAnalysis;

internal class Program
{
    static async Task Main(string[] args)
    {
        AIProjectClient client = AzureAIAgent.CreateAzureAIClient("<conneciton string>", new AzureCliCredential());
        AgentsClient agentsClient = client.GetAgentsClient();
        Agent agent = await agentsClient.GetAgentAsync("asst_ynGawRZhcWoDT6w78YMZUmUO");
        Console.WriteLine(agent.Name);
    }
}

I do wonder if this is a build error or intellisense. Can you please switch your error filter to "Build" only: Image

I'd also be interested to see the console message from the build failure.

I've pinged you directly and am happy to take a look at what may be in play on your local environment.

Note: We are just about to update the underlying SDK dependency (breaking change) as Foundry goes GA. (So the dependency graph will be dramatically altered - FYI)

crickman avatar May 15 '25 15:05 crickman

Working together on a call, we discover that this issue occurs when the Azure.Identity package is included as an explicit project dependncy. As a work-around, Ben is unblocked by removing this reference and relying on the transitive dependency from SK package.

Will continue to monitor and investigate as we updated our dependencies over the next couple days.

crickman avatar May 15 '25 23:05 crickman

Thanks for your effort for unblocking me. Happy to continue investigate with you together

BenoityipMSFT avatar May 15 '25 23:05 BenoityipMSFT

Removing an explicit Azure.Identity package reference did not work for me

JeffreyAllenMiller avatar May 16 '25 14:05 JeffreyAllenMiller

This issue also happens with Azure.Monitor.OpenTelemetry.Exporter 1.4.0 When i down graded to 1.2.0 of that package I was able to build again.

hanslinder avatar May 17 '25 11:05 hanslinder

You will need the new Azure.AI.Projects package (beta 9). It appears the Azure.AI.Projects has changed the AIAgent object to PersistentAgent and it breaks the SK integration with Azure AI Foundry.

bartczernicki avatar May 18 '25 15:05 bartczernicki

@bartczernicki We have this PR https://github.com/microsoft/semantic-kernel/pull/12027 ready to handle the change you mentioned. We are planning to merge this to align with the service changes.

In the interim using the current version of SK with existing AI Projects.

markwallace-microsoft avatar May 18 '25 17:05 markwallace-microsoft