Skip to main content

Lightweight code agent that explores codebases and generates analysis reports via OpenAI-compatible APIs

Project description

LocoTrainer

PyPI MODEL GGUF GitHub

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

  • [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

  • An OpenAI-compatible API key (DashScope, OpenRouter, or local llama.cpp)

Install

pip install locotrainer

Configure

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

Or use a .env file (clone the repo for the template):

git clone https://github.com/LocoreMind/LocoTrainer.git
cd LocoTrainer && cp .env.example .env
# Edit .env with your API key

Run (auto-clones ms-swift on first use)

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

# Configure and run
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?"

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

  • ๐Ÿค– Qwen Team for the Qwen3-4B-Instruct-2507 base model
  • ๐Ÿ› ๏ธ MS-SWIFT for the training framework and the codebase this model specializes in
  • ๐Ÿฆ™ llama.cpp for efficient local inference
  • ๐Ÿค– Anthropic for the Claude Code agent loop design that inspired this work

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

locotrainer-0.1.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

locotrainer-0.1.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file locotrainer-0.1.1.tar.gz.

File metadata

  • Download URL: locotrainer-0.1.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for locotrainer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 108170836f9530deb847d0e4739a883867c8fa95eb747e2cc1a1af9768ebd4c8
MD5 1f5c8f8cc5e9435f019ddceb96ffa59d
BLAKE2b-256 433f6e388b6ca44fd694de1823ca8a9e377b15c98410c181315282f1b28250eb

See more details on using hashes here.

File details

Details for the file locotrainer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for locotrainer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 63ca988b94739736cb8866b5781c77dc3c6d30543fd5d31e82f420fffd33b22f
MD5 ddd898d35d6876f79fffafa4ccec9d73
BLAKE2b-256 6ab9924fabf23ecf98e12d69b4044e9435c791246fe41916c9a0178e46b696af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page