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
- MS-SWIFT Domain Expert: Trained on MS-SWIFT documentation, CLI parameters, and project structure — answers framework questions accurately without hallucination
- Tool-Calling Agent: Generates structured
<tool_call>JSON for Read, Grep, Glob, Bash, and Write tools - End-to-End Reports: From a single question to a complete, well-structured markdown analysis report
- Local Deployment: GGUF quantized, runs on Mac Studio via llama.cpp at zero API cost
- Long Context: 32K training covers 90% of long-context analysis scenarios
- Auto Clone: Automatically clones ms-swift on first run — no manual setup needed
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:
- Understanding MS-SWIFT framework internals and best practices
- Analyzing training configurations and parameter choices
- Generating comprehensive documentation from codebases
- Answering "how does X work?" questions with full context
- Creating structured markdown reports for technical analysis
Known Limitations
- Specialized for MS-SWIFT; performance on unrelated codebases is untested
- 4B parameters — complex multi-hop reasoning may require a larger model
- MS-SWIFT project structure knowledge reflects the training data snapshot; may drift as the framework evolves
What's Next
LocoTrainer-4B represents our first step toward domain-specialized local agents. We're exploring:
- Expanding to other frameworks and codebases
- Larger model sizes (7B, 14B) for more complex reasoning
- Multi-modal capabilities for analyzing documentation and diagrams
- Community-driven training data contributions
Get Involved
LocoTrainer is open-source and built for the community. Contributions, feedback, and use cases are welcome!