Files
agent-framework/dotnet/demos/MinimalConsole/Program.cs
T
westey 71a0bf22eb .NET: Enhance console samples while preserving copyability (#475)
* Enhance console samples while preserving copyability

* Add readme for minimal console demo

* Suppress pre-release version warning

* Address PR comments

* Change showing settings to opt-in

* Update comment
2025-08-22 14:58:10 +00:00

27 lines
1.1 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.ComponentModel;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.Agents;
using OpenAI;
var azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var azureOpenAIDeploymentName = 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.";
AIAgent agent = new AzureOpenAIClient(
new Uri(azureOpenAIEndpoint),
new AzureCliCredential())
.GetChatClient(azureOpenAIDeploymentName)
.CreateAIAgent(
instructions: "You are a helpful assistant, you can help the user with weather information.",
tools: [AIFunctionFactory.Create(GetWeather)]);
Console.WriteLine(await agent.RunAsync("What's the weather in Amsterdam?"));