AH-Mechanic

amirhusain.com/mechanic

AH-Mechanic-1-4B

AH-Mechanic-1-4B

AH-Mechanic-1-4B is a specially trained version of Qwen3.5-4B for Linux administration. It works as an agent on a live machine: it runs one bash command at a time, reads the output, and then decides the next step. It can also answer a request with one shell command.

The model is small. The Q8_0 file is 4.6 GB and the Q4_K_M file is 2.8 GB, so it runs on one consumer GPU or on a CPU. Use it to find what fills a disk, to repair a service that does not start, to fix a broken cron job, to restore files safely and to read logs.

Demo

A real run, recorded with asciinema in a disposable Docker container (Ubuntu 24.04). The ticket: nginx will not start, and the site must return HTTP 200. Three faults are linked: a syntax error in the site configuration, a retired status daemon that still holds port 80, and a web root that the nginx workers cannot read. opencode 1.19.5 drives AH-Mechanic-1-4B (Q8_0, llama-server, one RTX 3090). Pauses longer than 2 s were shortened to 2 s; no model action was cut. Full MP4.

We recorded this scenario 5 times. In 3 runs, the model fixed all three faults (this is run 2). In 1 run, it reached HTTP 200 by pointing nginx at a copy of the page in another directory instead of fixing the permissions. In 1 run, it repeated the same check in a loop and stopped at the 15-minute limit.

What can it do?

Give it a task in plain words. The model inspects the machine before it changes anything. Before it deletes, kills or overwrites, it first lists what the action will affect. When it is not sure that an option exists, it reads the tool's --help text or man page. When a command fails, it reads the error and fixes the cause. At the end, it checks the result and writes a short summary.

Typical requests:

  • "The /var partition is at 98%. Find what is using the space, and tell me before you remove anything."
  • "nginx fails to start after last night's edit. Find the error and fix it, so that nginx -t passes."
  • "The nightly backup in /etc/cron.d/nightly-backup does not run. Find out why and fix it."
  • "Restore /etc/app/config.yaml from /var/backups/app.tar.gz. Keep a copy of the current file first."
  • "Write a systemd unit for /opt/scripts/rotate_logs.sh that runs as the user logrotate, and verify the unit file."
  • "Find which IP addresses caused most of the 5xx errors in /var/log/nginx/access.log in the last 1,000 requests."

Real examples

These are held-out test items. The model did not see them in training. The requests and the model's outputs are copied without changes from our evaluation logs. For the sandbox tasks, the logs keep the commands and the final reply, but not the command outputs. The held-out tests have no Docker tasks and almost no package-management tasks, so this list has none.

systemd: write a service unit and verify it

Live sandbox task 33 (passed, 3 commands).

Request

The development team needs a new service configuration file created for their 'data-processor' application. Please create a systemd service unit file at /etc/systemd/system/data-processor.service that starts the script /opt/apps/processor/run.sh as the user devops and ensures the working directory is set to /opt/apps/processor.

Commands the model ran

$ ls -la /opt/apps/processor/ 2>&1; echo "---"; id devops 2>&1
$ cat > /etc/systemd/system/data-processor.service <<'EOF'
[Unit]
Description=Data Processor Service
After=network.target

[Service]
Type=simple
User=devops
WorkingDirectory=/opt/apps/processor
ExecStart=/opt/apps/processor/run.sh

[Install]
WantedBy=multi-user.target
EOF
$ cat /etc/systemd/system/data-processor.service; echo "---"; systemd-analyze verify /etc/systemd/system/data-processor.service 2>&1

Final reply (the eval log keeps the first 300 characters)

Created /etc/systemd/system/data-processor.service with User=devops, WorkingDirectory=/opt/apps/processor, and ExecStart=/opt/apps/processor/run.sh. The file passed systemd-analyze verify with no errors. Note: you'll need to run systemctl daemon-reload and then `systemctl enable --now da [...]

Networking: find the process on a port

Live sandbox task 19 (passed, 3 commands).

Request

I need to identify which Python HTTP server instance is currently listening on port 8080. Please find the specific PID of that process and save it to /root/pid_8080.txt so I can terminate it later.

Commands the model ran

$ ss -tlnp | grep ':8080'
$ echo 16 > /root/pid_8080.txt
$ cat /root/pid_8080.txt

Final reply

The Python HTTP server instance listening on port 8080 is python3 with PID 16. I've saved 16 to /root/pid_8080.txt, so you can use kill 16 to terminate it when ready.

Permissions: fix ownership and modes

Live sandbox task 23 (passed, 4 commands).

Request

The security audit flagged the /var/audit/logs directory as having insecure permissions and incorrect ownership. Please fix the directory so that it is owned by the user auditor and group auditors, with permissions set to 750. Additionally, ensure that the file access.log inside that directory is owned by auditor:auditors and has permissions 640.

Commands the model ran

$ ls -la /var/audit/logs/
$ id auditor && getent group auditors
$ chown auditor:auditors /var/audit/logs && chmod 750 /var/audit/logs && chown auditor:auditors /var/audit/logs/access.log && chmod 640 /var/audit/logs/access.log
$ ls -la /var/audit/logs/

Final reply

The /var/audit/logs directory is now owned by auditor:auditors with permissions 750 (drwxr-x---), and the access.log file inside it is owned by auditor:auditors with permissions 640 (-rw-r-----). Both the directory and file have been corrected as required by the security audit.

Disk: find the file that fills a directory

Live sandbox task 59 (passed, 3 commands).

Request

The storage team reports that /var/logs has exceeded its quota, but the top-level directory only shows a few kilobytes. Investigate /var/logs to identify the single largest file consuming space and report its full path.

Commands the model ran

$ du -sh /var/logs
$ find /var/logs -type f -printf '%s %p\n' | sort -rn | head -20
$ ls -lh /var/logs/.hidden_large_dump

Final reply (the eval log keeps the first 300 characters)

The largest file consuming space in /var/logs is /var/logs/.hidden_large_dump at 10 MB (10,485,760 bytes). It is a regular file (not a directory), which is why the top-level directory listing only showed a few kilobytes โ€” the space is consumed by this single hidden file nested within the directory [...]

nginx: find and fix a configuration error

Live sandbox task 166 (passed, 3 commands).

Request

Our production nginx configuration at /etc/nginx/nginx.conf is currently failing validation. Please identify the specific syntax error in the file and fix it so that nginx -t passes successfully.

Commands the model ran

$ nginx -t 2>&1; echo "---"; cat -n /etc/nginx/nginx.conf
$ sed -i '4s/worker_connections 1024$/worker_connections 1024;/' /etc/nginx/nginx.conf
$ nginx -t 2>&1

Final reply

The syntax error was a missing semicolon on line 4 of /etc/nginx/nginx.conf โ€” worker_connections 1024 should have been worker_connections 1024;. I added the semicolon, and nginx -t now passes successfully.

Firewall: restore and persist iptables rules

One command, held-out request #71 (exact match).

Request

I have a backup of my iptables rules in /var/backups/netfilter/ruleset. I need to be restored using the iptables-restore command with the file as a direct argument, and I want to ensure persistence by manually saving the current rules to /etc/iptables/rules.v4 using iptables-save.

Model output

iptables-restore /var/backups/netfilter/ruleset && iptables-save > /etc/iptables/rules.v4

git: read the reflog

One command, loosely worded request #159 (judged equivalent; reference: git reflog --max-count 5).

Request

Show only the 5 latest entries in the reflog

Model output

git reflog --max-count=5

Text processing: prefix every line

One command, held-out request #335 (exact match).

Request

How can I use sed to prepend the string "| " to the beginning of every line in the output of a command named some_command?

Model output

some_command | sed 's/^/| /'

Two failures from the same tests

Wrong option for a rare flag

One command, held-out request #18 (not equivalent).

Request

Use smartctl to check the overall health status of the /dev/sda drive and, if that check passes, display its error log using the specific errlog option rather than the generic error option.

Model output

smartctl -H /dev/sda && smartctl -e errlog /dev/sda

Reference

smartctl -H /dev/sda && smartctl -l errlog /dev/sda

A deleted file and a loop

Live sandbox task 177 (failed: 12 commands, the step limit, no final reply).

Request

The deployment pipeline is failing because the application server is ignoring the system timezone. Please inspect the current locale and timezone configuration files in /etc, identify which specific file is missing or incorrect for the America/New_York zone, and create the correct symbolic link to the appropriate zoneinfo file so that cat /etc/timezone (if it existed) or the link target reflects America/New_York.

First four commands the model ran (eight more followed, all inspection and retries)

$ ls -la /etc/timezone /etc/localtime 2>&1; echo "---"; cat /etc/timezone 2>&1; echo "---"; ls /usr/share/zoneinfo/America/New_York 2>&1
$ ls -la /etc/zoneinfo/ 2>&1; echo "---"; ls -la /usr/share/zoneinfo/America/New_York 2>&1
$ cat /etc/zoneinfo/New_York 2>&1; echo "---"; head -5 /usr/share/zoneinfo/America/New_York 2>&1
$ rm /etc/zoneinfo/New_York && ln -sf /usr/share/zoneinfo/America/New_York /etc/zoneinfo/America/New_York && ln -sf /etc/zoneinfo/America/New_York /etc/localtime && echo "America/New_York" > /etc/timezone

How did we make it?

We built the single-turn and the multi-turn training datasets ourselves, from scratch. The single-turn data pairs a request with one correct command. The multi-turn data holds complete agent sessions: a task, the bash tool calls, the real outputs of those commands, and a final reply. In total there are 19,158 training examples.

We trained a LoRA adapter (rank 32, alpha 64) on all linear layers of the Qwen3.5-4B language model, for two epochs, and merged it into the base weights in bfloat16. We made no changes to the architecture: the model has the same layers, tokenizer and chat template as Qwen3.5-4B.

How does it score?

Results

Test Size AH-Mechanic-1-4B Qwen3.5-4B (base model)
Live sandbox: multi-step tasks, pass 200 tasks 82.0% (164) 73.0% (146)
One command: held-out requests, equivalent 370 65.4% 45.7%
One command: programs never seen in training, equivalent 264 63.6% 47.0%
One command: loosely worded requests, equivalent 210 21.4% 21.0%
One command, held-out requests: right program 370 95.9% 85.7%

What the tests measure:

  • Live sandbox. Each task starts in a fresh Ubuntu 24.04 container without network access. The model gets an agent system prompt and the bash tool, with at most 12 steps. A check script then decides pass or fail.
  • One command. The model answers a request with one command. It scores when the command is the same as the reference command, or when a larger model judges it equivalent. "Right program" means that the command uses the same program as the reference.
  • Held-out requests are not in the training data. Programs never seen in training are requests for programs that do not appear anywhere in the training data. Loosely worded requests are an older set; many of its requests do not say enough to pin down one command, which limits every model.
  • Qwen3.5-4B gets a strong one-command prompt. AH-Mechanic-1-4B gets the prompts it was trained with (below). All runs use greedy decoding and bf16 weights.

Read these numbers with care:

  • The sandbox tasks are separate from the training tasks, but they are similar in kind to the training sessions.
  • On 200 tasks, the 95% confidence interval is about ยฑ5.5 points.
  • The equivalence judge is a model, and it can make mistakes.

Files

File Size Use
model.safetensors-0000{1,2}-of-00002.safetensors 9.3 GB bf16 weights for Transformers, vLLM and SGLang
AH-Mechanic-1-4B-Q8_0.gguf 4.6 GB llama.cpp; output matched bf16 on 5 of 5 check prompts
AH-Mechanic-1-4B-Q4_K_M.gguf 2.8 GB llama.cpp; output matched bf16 on 4 of 5 check prompts

The GGUF files were made with llama.cpp's converter and llama-quantize. To check them, we ran 5 held-out requests on each file with greedy decoding and compared the output with the bf16 model. Q8_0 gave the same command 5 times. Q4_K_M gave the same command 4 times; once it chose /dev/sda1 where the request asked for the second partition (/dev/sda2). Use Q8_0 when you can.

Quick start

Turn thinking off (enable_thinking=False). The model was trained and tested in that mode. Replies end with <|im_end|> (token 248046) or <|endoftext|> (248044); generation_config.json sets both.

Transformers

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

repo = "ahtx/AH-Mechanic-1-4B"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, dtype=torch.bfloat16, device_map="auto")

messages = [
    {"role": "system", "content": "You are a Linux command-line expert. Reply with only the command, no explanation."},
    {"role": "user", "content": "Show disk usage of each directory directly under /var, largest first."},
]
prompt = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
ids = tok(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
out = model.generate(**ids, max_new_tokens=128, do_sample=False)
print(tok.decode(out[0, ids["input_ids"].shape[1]:], skip_special_tokens=True))

llama.cpp

llama-server -m AH-Mechanic-1-4B-Q8_0.gguf --jinja -ngl 99 -c 32768 --port 8090 \
  --chat-template-kwargs '{"enable_thinking": false}'

This gives an OpenAI-compatible API at http://localhost:8090/v1, with tool calls. We used this setup for the demo above. A recent llama.cpp build is necessary for the Qwen3.5 architecture.

Ollama

Ollama does not load these files yet. We tried Ollama 0.40.17: it reads the GGUF and its chat template, but its Qwen3.5 loader expects other tensor names than current llama.cpp writes (tensor 'blk.0.ssm_beta.weight' not found). Until that changes, use llama.cpp's llama-server as shown above. Any client that speaks the OpenAI API, including mechanic, can then use it.

vLLM and SGLang

The architecture is the unchanged Qwen3.5-4B architecture, so engines that serve Qwen3.5-4B should load the bf16 weights in the same way. We have not yet tested them with this release.

Agent use

The mechanic command-line agent

mechanic is our open-source agent for this model. It works with any OpenAI-compatible endpoint (llama.cpp, vLLM, Kindi and others). It shows each command before it runs, and you approve, edit or reject it. It also marks commands that delete, overwrite, kill or stop things that you did not name, and it checks every option against the local man page and --help text before the command runs.

pip install git+https://github.com/ahtx/mechanic
mechanic --endpoint http://localhost:8090/v1 "Find what fills /var and tell me before you delete anything."

System prompt for agent work

You are a Linux administration agent working on a live machine as root. Solve the user's task with the bash tool, one command at a time, reading each output before the next step. Inspect before you change anything; before deleting, killing or overwriting, first list exactly what will be affected. If you are not sure an option exists, check the tool's --help or man page first. If a command fails, read the error and fix the cause. Prefer precise, minimal changes and avoid interactive programs. When done, verify the result and reply with a brief summary or the requested answer.

System prompt for one command

You are a Linux command-line expert. Reply with only the command, no explanation.

Tool schema

[{"type": "function",
  "function": {"name": "bash",
               "description": "Run a shell command on the machine and return its output.",
               "parameters": {"type": "object",
                              "properties": {"command": {"type": "string", "description": "The bash command to run"}},
                              "required": ["command"]}}}]

Send each command's output back as a tool message. In our tests, a failed command came back as exit code N, followed by its output. Send one tool call per turn.

Safety

  • Confirm before you run. The model can make mistakes, and a wrong command can damage a system. Use a harness that shows each command and asks you before it runs, such as mechanic. Do not give the model root on a machine that matters without that step.
  • Run unattended only in a sandbox. Use a container or a throwaway virtual machine for unattended runs. mechanic --auto refuses to run outside a container or a virtual machine unless you pass --allow-auto-on-host.
  • Destructive commands. In one of the failures above, the model deleted a file that the task did not ask it to delete. In a static check of 20 sandbox tasks, it issued 11 delete, overwrite or kill commands on targets that the task did not name. Review such commands before they run.
  • Secrets. Commands and their outputs go to the model. Do not run it where outputs can contain secrets that must not reach the model's host.

Limitations

  • Rare options. The model knows common tools well. For rare options and for programs it did not see in training, it is less reliable (63.6% equivalent on unseen programs). Check such commands, or use a harness with a flag check.
  • Tested environment. We tested in Ubuntu 24.04 containers. Other distributions, real hardware, remote hosts and long-running services can behave differently. Docker, package installs from the network and a running systemd were not part of the sandbox.
  • Short sessions. The tests allow up to 12 commands per task. Long investigations are not tested.
  • Text only. The vision encoder of Qwen3.5-4B is still in the bf16 files, unchanged, but we did not train or test image input. The multi-token prediction (MTP) layer is also the unchanged base layer.
  • English only. The training data and the tests are in English.

Contributing sessions

mechanic can log your sessions locally if you turn logging on (it is off by default). With mechanic contribute, you can share sessions to help train the next version. mechanic removes secrets and identifying details, shows you the exact payload, and sends nothing until you agree. Contributed sessions are released under CC0 1.0. We acknowledge every valid contributor on this page.

License and credits

  • Base model: Qwen/Qwen3.5-4B by the Qwen team, Apache License 2.0. Their work makes this release possible. Thank you.
  • This model has the same license, the Apache License 2.0 (see LICENSE). The change from the base model is our training: a LoRA adapter, merged into the weights. The GGUF files are quantized from the merged weights.
  • GGUF conversion and quantization: llama.cpp.
  • Released by Amir Husain. Project page: amirhusain.com/mechanic.
Downloads last month
204
Safetensors
Model size
5B params
Tensor type
BF16
ยท
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for ahtx/AH-Mechanic-1-4B

Finetuned
Qwen/Qwen3.5-4B
Finetuned
(1,700)
this model
Quantizations
2 models