Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Last active May 8, 2026 20:26
Show Gist options
  • Select an option

  • Save wullemsb/9dfa050cc188b080e38b8a707bb68b6f to your computer and use it in GitHub Desktop.

Select an option

Save wullemsb/9dfa050cc188b080e38b8a707bb68b6f to your computer and use it in GitHub Desktop.
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