Last active
May 8, 2026 20:26
-
-
Save wullemsb/9dfa050cc188b080e38b8a707bb68b6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using GitHub.Copilot.SDK; | |
| using Microsoft.Extensions.AI; | |
| // Define the tool | |
| [AIFunction("get_current_weather", "Gets the current weather for a given city")] | |
| static string GetCurrentWeather(string city) | |
| { | |
| // In a real app, call a weather API here | |
| return $"It's 18°C and partly cloudy in {city}."; | |
| } | |
| await using var client = new CopilotClient(); | |
| await client.StartAsync(); | |
| var session = await client.CreateSessionAsync(new SessionConfig | |
| { | |
| Model = "gpt-4.1", | |
| OnPermissionRequest = PermissionHandler.ApproveAll, | |
| Tools = [AIFunctionFactory.Create(GetCurrentWeather)] | |
| }); | |
| var response = await session.SendAndWaitAsync(new MessageOptions | |
| { | |
| Prompt = "What's the weather like in Amsterdam and Berlin?" | |
| }); | |
| Console.WriteLine(response?.Data.Content); | |
| await client.StopAsync(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment