Last active
June 12, 2025 14:46
-
-
Save luisquintanilla/931bca3f8f1f342983c6e0b06a41f96e to your computer and use it in GitHub Desktop.
SK-MEAI-Agent
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
[Description("Calculate tax given a receipt and tax rate")] | |
float CalculateTax(float total, float taxRate) | |
{ | |
return total * (1 + taxRate); | |
} | |
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => | |
{ | |
builder.SetMinimumLevel(LogLevel.Trace).AddConsole(); | |
}); | |
var builder = Kernel.CreateBuilder(); | |
// Add your IChatClient | |
builder.Services.AddChatClient((sp) => | |
{ | |
return new ChatClientBuilder( | |
new AzureOpenAIClient( | |
new Uri(Environment.GetEnvironmentVariable("AOAI_ENDPOINT")), | |
new DefaultAzureCredential()) | |
.GetChatClient("gpt-4o-mini") | |
.AsIChatClient()) | |
.UseLogging(loggerFactory) | |
.UseFunctionInvocation() | |
.Build(); | |
}); | |
builder.Plugins.AddFromFunctions(nameof(CalculateTax), [AIFunctionFactory.Create(CalculateTax).AsKernelFunction()]); | |
var kernel = builder.Build(); | |
var agent = new ChatCompletionAgent | |
{ | |
Name = "TravelAgent", | |
Description = "A travel agent that helps users with travel plans", | |
Instructions = "Help users come up with a travel itinerary", | |
Kernel = kernel, | |
Arguments = new KernelArguments( | |
new PromptExecutionSettings { | |
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()}) | |
}; | |
await foreach(var item in agent.InvokeAsync("I want to go travel to paris. It will cost $1000. assuming a tax rate of 10%. What is the total cost?")) | |
{ | |
Console.WriteLine(item.Message.Content); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment