👉 Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/coding/multi_turn_chat_with_code_writing_assistant
Code Writing Assistant with File Write Tools for C# .NET Applications
🎯 Purpose of the Demo
This demo shows how to build a multi-turn assistant that can read, create, and modify source files using built-in tools. The model navigates your codebase, generates new code, and writes changes back to disk, all through natural conversation.
👥 Who Should Use This Demo
- Developers who want a local AI pair programmer that can actually write and modify files.
- Teams looking for a private code generation assistant with no cloud dependency.
- Educators building interactive coding tutors that scaffold projects for students.
🚀 What Problem It Solves
Traditional AI coding assistants show you code in the chat window, leaving you to copy and paste it into the right files. This demo closes that gap: the model reads your existing code, generates the changes, and writes them directly to disk. Everything runs locally with no data leaving your machine.
💻 Demo Application Overview
The demo is a console app that:
- Lets you select a coding-focused model (or enter a custom model URI)
- Downloads and loads the model with progress feedback
- Creates a
MultiTurnConversationwith five built-in tools registered - Runs an interactive chat loop with streaming output
- Shows performance metrics after each response
✨ Key Features
- File read and write:
FileSystemRead,FileSystemWritefor reading and modifying source files - Navigation:
FileSystemList,FileSystemSearchfor exploring codebases - Web search:
WebSearchfor looking up documentation and APIs - Multi-turn conversation: full history preserved across turns
- Color-coded output: blue for reasoning, magenta for tool calls, white for normal text
- Session control:
/resetclears history,/regenerateredoes the last response
Minimal Integration Snippet
using LMKit.Agents.Tools.BuiltIn;
using LMKit.Model;
using LMKit.TextGeneration;
using LM model = LM.LoadFromModelID("qwen3-coder:30b-a3b");
var chat = new MultiTurnConversation(model)
{
SystemPrompt = "You are a code writing assistant. Read files before modifying them."
};
chat.Tools.Register(BuiltInTools.FileSystemRead);
chat.Tools.Register(BuiltInTools.FileSystemList);
chat.Tools.Register(BuiltInTools.FileSystemSearch);
chat.Tools.Register(BuiltInTools.FileSystemWrite);
chat.Tools.Register(BuiltInTools.WebSearch);
var result = chat.Submit("Create a new file hello.cs with a Hello World program");
Console.WriteLine(result.Completion);
⚙️ Getting Started
Prerequisites
- .NET 8.0 or later
- A tool-calling capable model (~7 GB VRAM for Qwen 3.5 9B, ~18 GB for Qwen 3 Coder 30B-A3B)
Download the Project
Running the Application
- Clone the repository:
git clone https://github.com/LM-Kit/lm-kit-net-samples
- Navigate to the project directory:
cd lm-kit-net-samples/console_net/coding/multi_turn_chat_with_code_writing_assistant
- Build and run the application:
dotnet build
dotnet run
- Follow the on-screen prompts to select a model and start writing code.
Example Usage
Create a new file
You: Create a new C# class called UserService in ./Services/UserService.cs with CRUD methods
Modify existing code
You: Read Program.cs and add proper error handling to the Main method
Scaffold a project
You: Scaffold a basic ASP.NET minimal API project in ./my-api/ with a health check endpoint
Refactor across files
You: Search for all *.cs files and add XML doc comments to any public methods that are missing them
Look up docs and apply
You: Search the web for System.Text.Json best practices and update my JsonHelper.cs accordingly
🚀 Extend the Demo
- Add
BuiltInTools.FileSystemTreefor a quick overview of project structure before writing. - Add
BuiltInTools.RegexMatchfor searching code patterns within files before refactoring. - Add
BuiltInTools.TextDiffto show before/after comparisons of modified files. - Combine with
BuiltInTools.ProcessShellto let the assistant run build or test commands after writing code. - Switch to the
Agent+AgentExecutorpattern withPlanningStrategy.ReActfor multi-step autonomous workflows.
📚 Related Content
- Code Analysis Assistant Demo: A read-only companion demo for code analysis without file write capabilities.
- Tool Calling Assistant Demo: A companion demo showing custom tool implementation with
MultiTurnConversation. - Document Processing Agent Demo: Agent-driven PDF and image processing using built-in Document tools.
- How-To: Equip Agent with Built-In Tools: Guide to registering and configuring built-in tools.
- Glossary: AI Agent Tools: Core concepts behind tool registration, invocation, and result handling.