Table of Contents

👉 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 MultiTurnConversation with 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, FileSystemWrite for reading and modifying source files
  • Navigation: FileSystemList, FileSystemSearch for exploring codebases
  • Web search: WebSearch for 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: /reset clears history, /regenerate redoes 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

  1. Clone the repository:
git clone https://github.com/LM-Kit/lm-kit-net-samples
  1. Navigate to the project directory:
cd lm-kit-net-samples/console_net/coding/multi_turn_chat_with_code_writing_assistant
  1. Build and run the application:
dotnet build
dotnet run
  1. 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.FileSystemTree for a quick overview of project structure before writing.
  • Add BuiltInTools.RegexMatch for searching code patterns within files before refactoring.
  • Add BuiltInTools.TextDiff to show before/after comparisons of modified files.
  • Combine with BuiltInTools.ProcessShell to let the assistant run build or test commands after writing code.
  • Switch to the Agent + AgentExecutor pattern with PlanningStrategy.ReAct for multi-step autonomous workflows.

Share