New Release

LocoTrainer-4B: MS-SWIFT Domain Expert Agent

March 13, 2026 · 8 min read

A specialized 4B-parameter code analysis agent that combines multi-turn tool-calling with deep framework knowledge

Knowledge Distillation Tool Calling MS-SWIFT 32K Context

Introduction

Today we're releasing LocoTrainer-4B, a specialized code analysis agent trained via knowledge distillation from Qwen3-Coder-Next. Unlike general-purpose code agents, LocoTrainer-4B combines multi-turn tool-calling capabilities with deep MS-SWIFT framework knowledge, enabling it to generate comprehensive codebase analysis reports without requiring a separate reasoning model.

Key Features

Model Specifications

Base Model Qwen3-4B-Instruct-2507
Teacher Model Qwen3-Coder-Next
Training Method Full-parameter SFT (distillation)
Training Data 361,830 samples (agent trajectory + MS-SWIFT knowledge + project paths)
Max Sequence Length 32,768 tokens
Training Hardware 8x NVIDIA H100 80GB
Training Time ~25 hours
Framework MS-SWIFT

Architecture

LocoTrainer consists of two components: the agent framework and the LocoTrainer-4B model. The framework simulates a Claude Code-style agent environment, which is exactly what LocoTrainer-4B was trained on — ensuring maximum compatibility between the model and the runtime.

User Query
    │
    ▼
LocoTrainer Framework
    ├── build_user_query()     # injects absolute paths
    ├── get_system_reminder()  # simulates Claude Code environment
    └── Agent Loop
            │
            ▼
    LocoTrainer-4B (or any OpenAI-compatible model)
            │
            ├── <tool_call> Read / Grep / Glob / Bash
            │       │
            │       ▼
            │   Real Filesystem (ms-swift codebase)
            │       │
            │       ▼
            └── <tool_response> → next turn
                    │
                    ▼
            output/output.md   (final markdown report)
            output/trajectory.json  (full conversation log)

Performance Insights

Through iterative testing on MS-SWIFT codebase analysis tasks, we discovered a critical design insight:

Absolute paths in user content + tolerant tool argument parsing = reliable agent behavior.

This mirrors Claude Code's own design: the system always provides full absolute paths so the model never has to guess.

With this approach, LocoTrainer-4B achieved 100% tool call success rates and generated complete 225-line analysis reports in just 9 agent loop turns.

Quick Start

Getting started with LocoTrainer is simple. Install via PyPI:

pip install locotrainer

Configure your environment:

export LOCOTRAINER_API_KEY=your-api-key
export LOCOTRAINER_BASE_URL=https://api.openai.com/v1
export LOCOTRAINER_MODEL=gpt-4o

Run your first analysis:

locotrainer run -q "What are the default LoRA settings in ms-swift?"
# → output/output.md

Local Deployment with llama.cpp

For complete privacy and zero API costs, run LocoTrainer-4B locally:

# Start local server
./llama-server -m LocoTrainer-4B.gguf --ctx-size 51200 --port 8080

# Configure for local use
export LOCOTRAINER_BASE_URL=http://localhost:8080/v1
export LOCOTRAINER_MODEL=LocoTrainer-4B
export LOCOTRAINER_API_KEY=local

locotrainer run -q "How does ms-swift implement GRPO training?"

Use Cases

LocoTrainer-4B excels at:

Known Limitations

What's Next

LocoTrainer-4B represents our first step toward domain-specialized local agents. We're exploring:

Get Involved

LocoTrainer is open-source and built for the community. Contributions, feedback, and use cases are welcome!