Post

Module 6 — Function calling: letting the model drive your tools

Prompt & Tool Design for .NET Teams · Part 2 — Semantic Kernel in .NET · Module 6 of 12

So far the model can talk and you have a plugin it can’t reach. This module connects the two: you hand the kernel your tools, the model decides when to call them, and Semantic Kernel (SK) runs the back-and-forth. When it works it feels like magic. When it doesn’t, it’s almost always a description you wrote in Module 3 coming back to collect.

Objective

Enable automatic tool invocation and watch the full request → tool call → tool result → answer loop happen.

Read (~8 min)

Lab (~22 min)

Switch on automatic function calling and let the model reach your ComicPlugin:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;

var settings = new PromptExecutionSettings
{
    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
};

var history = new ChatHistory();
history.AddUserMessage("Find me a comic about merge conflicts.");

// Passing `kernel` is the whole trick. It's what lets SK discover your
// registered plugins and run the tool-call loop for you. Omit it and
// the model has no tools to call — it just talks.
var answer = await chat.GetChatMessageContentAsync(history, settings, kernel);
Console.WriteLine(answer);

Log every step. Then deliberately break it: ask for a comic about something nonsensical, pass an empty topic, return an error string from the plugin. Watch how the model recovers — or doesn’t, which is the more instructive outcome — and tighten the descriptions and error messages until it copes on its own.

⚠️ Tool/function-call support in the Amazon connector has historically lagged the OpenAI connector. It was a known gap through 2025. If auto-invocation misbehaves on your pinned version, fall back to calling Converse tool-use directly via AWSSDK.BedrockRuntime for this lab; the loop is conceptually identical. Check the current connector status on NuGet before you assume it’s your bug.

Done when

You can narrate the message sequence — assistant toolUse block → your function → toolResult block → final answer — from your own logs, with no hand-waving.


Series navigation

This post is licensed under CC BY 4.0 by the author.