Skip to content

Commit a8fadbc

Browse files
authored
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.
1 parent 6c12b2c commit a8fadbc

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

dotnet/agent-framework-dotnet.slnx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<BuildType Solution="Publish|*" Project="Release" />
2525
</Project>
2626
</Folder>
27+
<Folder Name="/Demos/">
28+
<Project Path="demos/MinimalConsole/MinimalConsole.csproj">
29+
<BuildType Solution="Publish|*" Project="Release" />
30+
</Project>
31+
</Folder>
2732
<Folder Name="/Samples/">
2833
<Project Path="samples/GettingStarted/GettingStarted.csproj">
2934
<BuildType Solution="Publish|*" Project="Debug" />

dotnet/demos/.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Suppressing errors for Sample projects under dotnet/samples folder
2+
[*.cs]
3+
dotnet_diagnostic.CA2007.severity = none # Do not directly await a Task
4+
dotnet_diagnostic.CS1591.severity = none # Missing XML comment for publicly visible type or member
5+
dotnet_diagnostic.IDE1006.severity = warning # Naming rule violations
6+
dotnet_diagnostic.VSTHRD111.severity = none # Use .ConfigureAwait(bool) is hidden by default, set to none to prevent IDE from changing on autosave
7+
dotnet_diagnostic.CA1716.severity = none # Add summary to documentation comment.
8+
dotnet_diagnostic.CA2000.severity = none # Call System.IDisposable.Dispose on object before all references to it are out of scope
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>$(ProjectsTargetFrameworks)</TargetFrameworks>
6+
<TargetFrameworks Condition="'$(Configuration)' == 'Debug'">$(ProjectsDebugTargetFrameworks)</TargetFrameworks>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Azure.AI.OpenAI" />
11+
<PackageReference Include="Azure.Identity" />
12+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\src\Microsoft.Extensions.AI.Agents\Microsoft.Extensions.AI.Agents.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
3+
using System;
4+
using System.ComponentModel;
5+
using Azure.AI.OpenAI;
6+
using Azure.Identity;
7+
using Microsoft.Extensions.AI;
8+
using Microsoft.Extensions.AI.Agents;
9+
10+
[Description("Get the weather for a given location.")]
11+
static string GetWeather([Description("The location to get the weather for.")] string location)
12+
{
13+
return $"The weather in {location} is cloudy with a high of 15°C.";
14+
}
15+
16+
IChatClient chatClient = new AzureOpenAIClient(
17+
new Uri(Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!),
18+
new AzureCliCredential())
19+
.GetChatClient("gpt-4o-mini")
20+
.AsIChatClient();
21+
22+
AIAgent agent = new ChatClientAgent(
23+
chatClient,
24+
instructions: "You are a helpful assistant, you can help the user with weather information.",
25+
tools: [AIFunctionFactory.Create(GetWeather)]);
26+
27+
Console.WriteLine(await agent.RunAsync("What's the weather in Amsterdam?"));

0 commit comments

Comments
 (0)