Files
agent-framework/dotnet/demos/MinimalConsole/Program.cs
T
westey a8fadbc49c Add a minimum console demo app (#198)
* Add a minimum console demo app

* Remove hardcoded values from sample.

* Make console project .net 9.0 only.

* Move minimum console demo to demo folder.

* Fix framework issue with demo project.

* Undo unintended commit.

* Address PR comments

* Fix build issue.

* Address PR Comments

* Rename Agent to AIAgent in new console app.
2025-07-21 09:49:47 +00:00

28 lines
933 B
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;
[Description("Get the weather for a given location.")]
static string GetWeather([Description("The location to get the weather for.")] string location)
{
return $"The weather in {location} is cloudy with a high of 15°C.";
}
IChatClient chatClient = new AzureOpenAIClient(
new Uri(Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!),
new AzureCliCredential())
.GetChatClient("gpt-4o-mini")
.AsIChatClient();
AIAgent agent = new ChatClientAgent(
chatClient,
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?"));