👉 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 Demo
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
IToolinterface. - Define JSON schemas for tool parameters.
- Register tools via
chat.Tools.Register(). - Use
MultiTurnConversationwith 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.
💻 Demo Application Overview
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 (3.3-18 GB)
- Internet connection (for weather/currency)
Run
cd demos/console_net/agents/tool_calling_assistant
dotnet build
dotnet run
📚 Additional Resources
- LM-Kit.NET Documentation
- ITool API Reference
- ToolRegistry API Reference
- MultiTurnConversation API Reference
- LM-Kit Samples Repository
📚 Related Content
- How-To: Build Function Calling Agent: Step-by-step guide to implementing ITool and registering custom tools.
- How-To: Create Agent with Tools: Learn how to define JSON schemas and wire tools into agents and conversations.
- Glossary: Function Calling: Core concepts behind how LLMs invoke typed tools with JSON arguments.
- Glossary: AI Agent Tools: Overview of tool registration, schemas, and the ITool interface.
- Multi-Turn Chat with Tools Demo: A companion demo showing tool calling in multi-turn conversations with built-in weather, currency, and unit tools.
- Code Analysis Assistant Demo: A coding-focused demo using built-in FileSystem and WebSearch tools for code analysis.
- Code Writing Assistant Demo: Extends the code analysis pattern with FileSystemWrite for creating and modifying source files.