Table of Contents

👉 Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/agents/tool_calling_assistant

Tool Calling Assistant for C# .NET Applications


Purpose of the Sample

Tool Calling Assistant demonstrates how to use LM-Kit.NET to build AI assistants that can invoke custom tools during conversations using the native tool-calling system.

The sample shows how to:

  • Implement the ITool interface.
  • Define JSON schemas for tool parameters.
  • Register tools with ToolRegistry.
  • Use MultiTurnConversation with tools.
  • Handle tool invocation events for logging and debugging.

Why Tool Calling with LM-Kit.NET?

  • Real capabilities: tools perform actions LLMs cannot (API calls, calculations, data access).
  • Native format: uses the model's built-in tool-calling format for reliability.
  • Type safety: JSON schemas validate tool parameters.
  • Extensibility: easily add new tools for new capabilities.
  • Local-first: all tool invocations run on your hardware.

Sample Application Description

Console app that:

  • Creates three practical tools: Weather, Currency Conversion, Unit Conversion.
  • Registers tools with the conversation system.
  • Allows natural language queries that trigger tool use.
  • Displays tool invocation details in real-time.
  • Demonstrates multi-tool conversations.

Key Features

  • WeatherTool: real-time weather via Open-Meteo API (free, no key).
  • CurrencyTool: currency conversion via ECB rates (free, no key).
  • UnitConversionTool: offline unit conversions (length, mass, temp, etc.).
  • Native Tool Calling: uses model's built-in JSON tool format.

Tool Implementation Pattern

using LMKit.Agents.Tools;

public class WeatherTool : ITool
{
    public string Name => "get_weather";

    public string Description => "Get current weather for a location";

    public string InputSchema => @"{
        ""type"": ""object"",
        ""properties"": {
            ""location"": {
                ""type"": ""string"",
                ""description"": ""City name or coordinates""
            }
        },
        ""required"": [""location""]
    }";

    public async Task<string> InvokeAsync(string arguments, CancellationToken ct)
    {
        // Parse arguments, call API, return JSON result
    }
}

Available Tools

Tool API Description
get_weather Open-Meteo (free) Current weather + forecast
convert_currency ECB Frankfurter (free) Real-time exchange rates
convert_units Offline Length, mass, temperature, etc.

Example Queries

  • "What's the weather in Paris?"
  • "Convert 100 USD to EUR"
  • "How many kilometers is 5 miles?"
  • "What's 72 Fahrenheit in Celsius?"

Getting Started

Prerequisites

  • .NET 8.0 or later
  • VRAM for selected model (4-11 GB)
  • Internet connection (for weather/currency)

Run

cd demos/console_net/agents/tool_calling_assistant
dotnet build
dotnet run

Additional Resources