你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Azure AI.AgentServer.AgentFramework client library for .NET - version 1.0.0-beta.5

With hosted agents developers can deploy existing agents — whether built with supported agent frameworks or custom code — into Microsoft AI Foundry with minimal effort.

Getting started

Install the package

dotnet add package Azure.AI.AgentServer.AgentFramework --prerelease

Key concepts

Azure AI Agent Server wraps your Agent-framework agent, and host it on the cloud.

You can talk to your agent using Azure.AI.Projects sdk.

Examples

using System.ComponentModel;
using Azure.AI.AgentServer.AgentFramework.Extensions;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;

var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ??
               throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";

[Description("Get the weather for a given location.")]
static string GetWeather([Description("The location to get the weather for.")] string location)
    => $"The weather in {location} is cloudy with a high of 15°C.";

var chatClient = new AzureOpenAIClient(
        new Uri(endpoint),
        new DefaultAzureCredential())
    .GetChatClient(deploymentName)
    .AsIChatClient()
    .AsBuilder()
    .UseOpenTelemetry(sourceName: "Agents")
    .Build();

var agent = new ChatClientAgent(chatClient,
        instructions: "You are a helpful assistant, you can help the user with weather information.",
        tools: [AIFunctionFactory.Create(GetWeather)])
    .AsBuilder()
    .UseOpenTelemetry(sourceName: "Agents")
    .Build();

// Run Agent Server
await agent.RunAIAgentAsync(telemetrySourceName: "Agents");

Troubleshooting

First run your agent with Azure.AI.AgentServer locally.

If it works on local by failed on cloud. Check your logs in the application insight connected to your Azure AI Foundry Project.

Reporting issues

To report an issue with the client library, or request additional features, please open a GitHub issue here. Mention the package name "Azure.AI.AgentServer" in the title or content.

Contributing

See the Azure SDK CONTRIBUTING.md for details on building, testing, and contributing to this library.

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.