⚡ Mend

The Autonomous Bug Remediation & Self-Healing Agent

License: Apache 2.0 GGUF Available Sub-Cortex: Tokenectomy

You write the features. Mend heals the bugs.


📌 What is Mend?

Mend is a specialized autonomous software engineering agent, fine-tuned specifically for end-to-end bug remediation — not general-purpose coding assistance.

Generic AI coding assistants try to do everything: generating entire unverified applications from vague prompts, hallucinating missing functions, and bloating context with massive raw runtime logs.

Mend is scoped narrower, on purpose. It handles a single closed-loop workflow: diagnose a failure, track it as an incident, apply a verified patch, check blast radius, deliver via Git, and close the loop.

  • Diagnoses runtime failures and test crashes from raw error logs.
  • Emits structured JSON tool calls (get_error_context, apply_code_patch, etc.) for a calling agent/orchestrator to execute.
  • Trained on multi-turn trajectories covering the full incident lifecycle, not single-shot patch suggestions.
  • Not intended for open-ended code generation, architecture design, or tasks outside bug remediation.

🛠️ Tool Schema

Mend was fine-tuned to emit calls against this tool set. A calling application is expected to implement and execute these tools; Mend only produces the structured calls.

Tool Purpose
get_error_context Extract the offending code context from a raw stack trace / log
apply_code_patch Apply a search-and-replace style patch to a file
inspect_docker Diagnose container-level failures (e.g. OOM, crash loops)
probe_database Diagnose connection/lock-related database issues
sentinel_analyze_blast_radius Map callers of a symbol/file before a patch is applied
create_fix_branch Create a branch for the fix
commit_fix Commit the applied patch
open_pull_request Open a PR for the fix
create_incident_issue Open a tracking issue for the incident
link_issue_to_fix_pr Link a tracking issue to its fix PR
close_incident_issue Close the tracking issue once resolved

Full JSON Schema definitions for these tools are shown in the Quickstart section below.


🚀 Quickstart: Running Inference

import re, json, torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "NadevA23/Mend"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)

system_prompt = (
    "You are Mend, an autonomous bug-remediation agent natively equipped with "
    "the Tokenectomy M2M Sub-Cortex. You handle the full incident lifecycle: "
    "diagnose through get_error_context (and inspect_docker/probe_database when "
    "the failure is infra-level), open an incident issue for tracking, apply a "
    "verified atomic patch, run a blast-radius check before merging when the "
    "change is non-trivial, deliver the fix via a branch/commit/pull request, "
    "link the issue to its fix PR, and close the issue once resolved. You are "
    "not a general-purpose coding assistant — you exist solely to remediate "
    "reported bugs and incidents end-to-end, deterministically and with zero "
    "dirty diffs."
)

tools_schema = [
    {"type": "function", "function": {
        "name": "get_error_context",
        "description": "Excise framework noise, redact credentials, and extract exact offending code snippets from a raw stack trace.",
        "parameters": {
            "type": "object",
            "properties": {
                "log": {"type": "string"},
                "strategy": {"type": "string", "enum": ["aggressive", "conservative"]},
            },
            "required": ["log"],
        },
    }},
    {"type": "function", "function": {
        "name": "apply_code_patch",
        "description": "Apply an atomic search-and-replace AST patch, verified by the compiler before commit.",
        "parameters": {
            "type": "object",
            "properties": {
                "file_path": {"type": "string"},
                "original_code": {"type": "string"},
                "new_code": {"type": "string"},
            },
            "required": ["file_path", "original_code", "new_code"],
        },
    }},
    {"type": "function", "function": {
        "name": "inspect_docker",
        "description": "Diagnose container crashes (e.g. exit code 137 OOMKilled) via container logs and resource stats.",
        "parameters": {
            "type": "object",
            "properties": {"container_id": {"type": "string"}},
            "required": ["container_id"],
        },
    }},
    {"type": "function", "function": {
        "name": "probe_database",
        "description": "Triage connection pool starvation and lock deadlocks; suggests SKIP LOCKED remedies.",
        "parameters": {
            "type": "object",
            "properties": {"connection_string": {"type": "string"}},
            "required": ["connection_string"],
        },
    }},
    {"type": "function", "function": {
        "name": "sentinel_analyze_blast_radius",
        "description": "Map caller dependency graph for a symbol/file before applying a patch.",
        "parameters": {
            "type": "object",
            "properties": {
                "file_path": {"type": "string"},
                "symbol": {"type": "string"},
            },
            "required": ["file_path"],
        },
    }},
    {"type": "function", "function": {
        "name": "create_fix_branch",
        "description": "Create a new git branch for the fix.",
        "parameters": {
            "type": "object",
            "properties": {"branch_name": {"type": "string"}},
            "required": ["branch_name"],
        },
    }},
    {"type": "function", "function": {
        "name": "commit_fix",
        "description": "Commit the verified patch to the current branch.",
        "parameters": {
            "type": "object",
            "properties": {"commit_message": {"type": "string"}},
            "required": ["commit_message"],
        },
    }},
    {"type": "function", "function": {
        "name": "open_pull_request",
        "description": "Open a PR from the fix branch to the target branch.",
        "parameters": {
            "type": "object",
            "properties": {
                "target_branch": {"type": "string", "default": "main"},
                "title": {"type": "string"},
            },
            "required": ["title"],
        },
    }},
    {"type": "function", "function": {
        "name": "create_incident_issue",
        "description": "Open a tracking issue for a diagnosed incident.",
        "parameters": {
            "type": "object",
            "properties": {
                "title": {"type": "string"},
                "body": {"type": "string"},
                "severity": {"type": "string", "enum": ["low", "medium", "high", "critical"]},
            },
            "required": ["title"],
        },
    }},
    {"type": "function", "function": {
        "name": "link_issue_to_fix_pr",
        "description": "Link an existing incident issue to the pull request that resolves it.",
        "parameters": {
            "type": "object",
            "properties": {
                "issue_id": {"type": "string"},
                "pr_id": {"type": "string"},
            },
            "required": ["issue_id", "pr_id"],
        },
    }},
    {"type": "function", "function": {
        "name": "close_incident_issue",
        "description": "Close an incident issue once its linked fix has been verified and merged.",
        "parameters": {
            "type": "object",
            "properties": {
                "issue_id": {"type": "string"},
                "resolution_note": {"type": "string"},
            },
            "required": ["issue_id"],
        },
    }},
]

user_prompt = (
    "Automated test run failed with an unhandled exception:\n\n"
    "TypeError: Cannot read properties of undefined (reading 'sub')\n"
    "    at AuthService.verifyToken (/app/src/services/auth.service.ts:58:28)"
)

messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": user_prompt},
]

encoded = tokenizer.apply_chat_template(
    messages, tools=tools_schema, tokenize=True,
    add_generation_prompt=True, return_tensors="pt",
)
input_ids = encoded.input_ids.to(model.device) if hasattr(encoded, "input_ids") else encoded.to(model.device)
attention_mask = encoded.attention_mask.to(model.device) if hasattr(encoded, "attention_mask") else torch.ones_like(input_ids)

im_end_id = tokenizer.convert_tokens_to_ids("<|im_end|>")
stop_tokens = list({tokenizer.eos_token_id, im_end_id})

outputs = model.generate(
    input_ids=input_ids,
    attention_mask=attention_mask,
    max_new_tokens=512,
    do_sample=False,
    eos_token_id=stop_tokens,
)

response_text = tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=True)
print(response_text)

# Parse tool calls — Mend emits raw JSON objects, no <tool_call> wrapper
for m in re.finditer(r'\{\s*"name"\s*:\s*"[^"]+"\s*,\s*"arguments"\s*:\s*\{.*?\}\s*\}', response_text, re.DOTALL):
    try:
        print("Mend Tool Action:", json.dumps(json.loads(m.group(0)), indent=2))
    except json.JSONDecodeError:
        pass

📦 Quantized & Edge Deployments

GGUF weights for llama.cpp / Ollama are available at NadevA23/Mend-GGUF:

ollama run hf.co/NadevA23/Mend-GGUF:Q4_K_M

Training Details

Training Data

Fine-tuned on a custom multi-turn tool-calling trajectory dataset (tokenectomy_apex), covering the full incident lifecycle: diagnosis, patch application, blast-radius analysis, git delivery, and incident tracking. Not derived from or trained on SWE-bench or other public benchmark test sets.

Training Procedure

  • Method: LoRA (rank 16, alpha 16, dropout 0) via Unsloth
  • Target modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
  • Base model: unsloth/Qwen2.5-Coder-7B-Instruct-bnb-4bit (4-bit, QLoRA-style — base frozen, adapter trained in bf16)
  • Sequence length: 4096
  • Epochs: 2
  • Optimizer: adamw_8bit, cosine LR schedule, LR 2e-4

Training regime

bf16 mixed precision (adapter); 4-bit frozen base weights.


Evaluation

Evaluation methodology: generation over sampled instances from princeton-nlp/SWE-bench_Lite, scored on tool-call emission and structural patch validity — not the official SWE-bench harness (which requires Docker-based execution of the target repository's real test suite and was not available in the training/eval environment used).

Metrics reported in the model-index above reflect this structural evaluation, not confirmed bug-fix resolution against real test suites. Treat these as an internal proxy signal for agent reliability (does it emit tool calls, does it reach the patch stage, does the patch apply cleanly), not as a bug-fix success rate.

(Values above are placeholders pending a completed evaluation run — update before relying on this card for external claims.)


Limitations

  • Scoped to bug remediation; not evaluated or intended for general code generation, refactoring, or architecture tasks.
  • Emits tool calls only — does not execute them. Requires an orchestrating application to implement and run the tool set above.
  • Evaluation metrics reported here are structural/emission-based, not verified-fix rates against real test suites.
  • Fine-tuned on a small (1,200-trajectory) custom dataset; behavior outside the distribution of that data (unfamiliar languages, frameworks, or error types) is untested.

License

This model is a LoRA fine-tune merged into unsloth/Qwen2.5-Coder-7B-Instruct-bnb-4bit, itself derived from Qwen/Qwen2.5-Coder-7B-Instruct (Alibaba), licensed under Apache License 2.0. This derivative work is likewise distributed under Apache 2.0. See the Apache 2.0 license text for full terms, including the requirement to preserve copyright and license notices in redistributions.


🏢 Organization & Author

Downloads last month
163
Safetensors
Model size
8B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for NadevA23/Kronumos

Base model

Qwen/Qwen2.5-7B
Finetuned
(116)
this model
Quantizations
2 models

Evaluation results