From 254b3cbf71da393daa16d87aa661e2dd455dc77a Mon Sep 17 00:00:00 2001 From: "Vic Perdana (MSFT)" <7114832+vicperdana@users.noreply.github.com> Date: Fri, 23 Jan 2026 16:09:41 +1100 Subject: [PATCH] docs: add .NET example for weather assistant using Copilot SDK --- docs/getting-started.md | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/docs/getting-started.md b/docs/getting-started.md index 7833d07494..aad966e5cc 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -779,6 +779,74 @@ python weather_assistant.py +
+.NET + +Create a new console project and update `Program.cs`: + +```csharp +using GitHub.Copilot.SDK; +using Microsoft.Extensions.AI; +using System.ComponentModel; + +// Define the weather tool using AIFunctionFactory +var getWeather = AIFunctionFactory.Create( + ([Description("The city name")] string city) => + { + var conditions = new[] { "sunny", "cloudy", "rainy", "partly cloudy" }; + var random = new Random(); + var temp = random.Next(50, 80); + var condition = conditions[random.Next(conditions.Length)]; + return new { city, temperature = $"{temp}°F", condition }; + }, + "get_weather", + "Get the current weather for a city"); + +await using var client = new CopilotClient(); +await using var session = await client.CreateSessionAsync(new SessionConfig +{ + Model = "gpt-4.1", + Streaming = true, + Tools = [getWeather] +}); + +// Listen for response chunks +session.On(ev => +{ + if (ev is AssistantMessageDeltaEvent deltaEvent) + { + Console.Write(deltaEvent.Data.DeltaContent); + } +}); + +Console.WriteLine("🌤️ Weather Assistant (type 'exit' to quit)"); +Console.WriteLine(" Try: 'What's the weather in Paris?' or 'Compare weather in NYC and LA'\n"); + +while (true) +{ + Console.Write("You: "); + var input = Console.ReadLine(); + + if (string.IsNullOrEmpty(input) || input.Equals("exit", StringComparison.OrdinalIgnoreCase)) + { + break; + } + + Console.Write("Assistant: "); + await session.SendAndWaitAsync(new MessageOptions { Prompt = input }); + Console.WriteLine("\n"); +} +``` + +Run with: + +```bash +dotnet run +``` + +
+ + **Example session:** ```