Lightweight code agent that explores codebases and generates analysis reports via OpenAI-compatible APIs
Project description
LocoTrainer-4B is a 4B-parameter MS-SWIFT domain expert agent distilled from Qwen3-Coder-Next. Designed to analyze MS-SWIFT codebases and generate comprehensive markdown reports โ combining tool-calling capabilities with deep framework knowledge.
๐ Table of Contents
- ๐ฐ News & Updates
- ๐ Introduction
- โจ Key Features
- ๐๏ธ Architecture
- ๐ Performance
- ๐ Quick Start
- ๐ง Usage Examples
- ๐ Project Structure
- โ ๏ธ Known Limitations
- ๐ License
- ๐ Acknowledgments
๐ฐ News & Updates
- [2026-03-13] ๐ LocoTrainer-4B and LocoTrainer framework released.
๐ Introduction
LocoTrainer-4B is a specialized code analysis agent trained via knowledge distillation from Qwen3-Coder-Next. Unlike general-purpose code agents, it 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.
| LocoTrainer-4B | |
|---|---|
| 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 |
โจ 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
๐๏ธ Architecture
LocoTrainer consists of two components: the agent framework (this repo) and the LocoTrainer-4B model.
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)
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.
๐ Performance
Evaluated on MS-SWIFT codebase analysis tasks across 3 test iterations.
Agent Loop Reliability
| Metric | Test 1 (Relative Paths) | Test 2 (Absolute Paths) | Test 3 (Absolute + Tolerant Args) |
|---|---|---|---|
| Read success rate | 0% | 100% | 100% |
| Write success rate | โ | 0% | 100% |
| Turns used | 15 (limit) | 15 (limit) | 9 |
| Tool calls | 34 | 27 | 13 |
| output.md generated | โ | โ | โ (225 lines) |
Key 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.
๐ Quick Start
Prerequisites
- uv โ
curl -LsSf https://astral.sh/uv/install.sh | sh - An OpenAI-compatible API key (DashScope, OpenRouter, or local llama.cpp)
Install
git clone https://github.com/LocoreMind/LocoTrainer.git
cd LocoTrainer
cp .env.example .env
# Edit .env with your API key
uv sync
Run (auto-clones ms-swift on first use)
uv run locotrainer run -q "What are the default LoRA settings in ms-swift?"
# โ output/output.md
With LocoTrainer-4B via llama.cpp
# Start local server
./llama-server -m LocoTrainer-4B.gguf --ctx-size 51200 --port 8080
# Point LocoTrainer at it
LOCOTRAINER_BASE_URL=http://localhost:8080/v1
LOCOTRAINER_MODEL=LocoTrainer-4B
LOCOTRAINER_API_KEY=local
uv run locotrainer run -q "How does ms-swift implement GRPO training?"
With DashScope (Qwen3-Coder-Next)
LOCOTRAINER_API_KEY=sk-your-dashscope-key
LOCOTRAINER_BASE_URL=https://dashscope-intl.aliyuncs.com/compatible-mode/v1
LOCOTRAINER_MODEL=qwen3-coder-next
LOCOTRAINER_ENABLE_THINKING=true
๐ง Usage Examples
Analyze a specific topic
locotrainer run -q "What are all supported training methods in ms-swift and their differences?"
Analyze a different codebase
locotrainer run \
-q "How does the authentication system work?" \
-c /path/to/other/project \
-o ./reports
Full CLI options
locotrainer run \
-q "Your question here" \
-c /path/to/codebase \ # optional, default: auto-clone ms-swift
-o ./output \ # optional, default: ./output
-m model-name \ # optional, overrides .env
--max-turns 20 \ # optional, default: 20
--quiet # suppress verbose output
๐ Project Structure
LocoTrainer/
โโโ pyproject.toml # uv project config, pip installable
โโโ .env.example # Configuration template
โโโ .env # User config (gitignored)
โโโ src/locotrainer/
โโโ __init__.py # Package version
โโโ prompts.py # SYSTEM_PROMPT + get_system_reminder()
โโโ tools.py # ToolExecutor (Read/Grep/Glob/Write/Bash)
โโโ agent.py # Agent loop
โโโ config.py # Config dataclass, .env loading
โโโ repo.py # Auto-clone ms-swift logic
โโโ cli.py # Click CLI: `locotrainer run`
โ๏ธ Configuration
| Env Variable | Default | Description |
|---|---|---|
LOCOTRAINER_API_KEY |
(required) | API key (falls back to OPENAI_API_KEY) |
LOCOTRAINER_BASE_URL |
https://api.openai.com/v1 |
OpenAI-compatible endpoint |
LOCOTRAINER_MODEL |
gpt-4o |
Model name |
LOCOTRAINER_MAX_TURNS |
20 |
Max agent loop turns |
LOCOTRAINER_MAX_TOKENS |
8192 |
Max tokens per response |
LOCOTRAINER_ENABLE_THINKING |
false |
Enable thinking mode (Qwen3) |
LOCOTRAINER_CODEBASE |
. |
Codebase path (triggers auto-clone if default) |
LOCOTRAINER_OUTPUT_DIR |
./output |
Output directory |
Training Details
๐ Click to expand full training configuration
| Parameter | Value |
|---|---|
| Base model | Qwen3-4B-Instruct-2507 |
| Teacher model | Qwen3-Coder-Next |
| Method | Full-parameter SFT |
| Training data | 361,830 samples |
| Data composition | Agent trajectory + MS-SWIFT knowledge + project structure paths |
| Hardware | 8x NVIDIA H100 80GB |
| DeepSpeed | ZeRO-2 |
| Precision | BF16 |
| Epochs | 1 |
| Max sequence length | 32,768 tokens |
| Attention | Flash Attention 2 |
| Kernel optimization | Liger Kernel |
| Learning rate | 1e-5, warmup ratio 0.05 |
| Batch size | 1/GPU, gradient accumulation 4 (effective batch 32) |
| Template | qwen3_nothinking |
| Framework | MS-SWIFT |
| Training time | ~25 hours |
โ ๏ธ 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
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file locotrainer-0.1.0.tar.gz.
File metadata
- Download URL: locotrainer-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bde4880feb49b555d7e4661b538562a07d85515443a5f9f6d684ee3be9a286d
|
|
| MD5 |
2c9c7403b7bb8aec28a9a232b65fb413
|
|
| BLAKE2b-256 |
33e2b831835212abed4477b3546c37f7d15b2a231a354a27ffff0098b3c07f9f
|
File details
Details for the file locotrainer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: locotrainer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b468181ce3ede5cd1c2570eac21b6c94b9b9b86056af557cadca6fe3eac15b4
|
|
| MD5 |
3c029754ca31e75f2f30213f79026bed
|
|
| BLAKE2b-256 |
1716fc56350c08eb3bb74dfc5c644bfd45a9490b66cdc764487ba31f52597da6
|