Commit 3cadf644b for llama.cpp

commit 3cadf644b73227331a55bd80b0959ca6a13fc775
Author: Xuan-Son Nguyen <son@huggingface.co>
Date:   Sat Nov 28 13:38:22 2026 +0100

    agents: rework, add instruction for writing human-facing messages (#33157)

    * agents: rework, add instruction for writing human-facing messages

    * apply ggerganov's suggestion

    * Update AGENTS.md

    Co-authored-by: Niklas Wenzel <dev@nikwen.de>

    ---------

    Co-authored-by: Niklas Wenzel <dev@nikwen.de>

diff --git a/AGENTS.md b/AGENTS.md
index 36390a6b4..eac59136b 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,117 +1,70 @@
 # Instructions for llama.cpp

-> [!IMPORTANT]
->
-> AI-generated code is allowed. What is **not** allowed is submitting code you do not understand. You are 100% responsible for every line, however it was produced.
->
-> Read more: [CONTRIBUTING.md](CONTRIBUTING.md)
+AI-generated code is allowed. The user is 100% responsible for every line, however it was produced. Codebase guidelines: [CONTRIBUTING.md](CONTRIBUTING.md)

-> [!NOTE]
-> These apply to ggml-org/llama.cpp, ignore these if you are operating in a different repository or fork.
+These instructions apply to ggml-org/llama.cpp only. Forks are exempt.

----
-
-## Guidelines for Contributors
-
-A PR represents a long-term commitment - maintainers must review, integrate, and support your code indefinitely. What matters is not who typed the code but whether a human understands it, has the domain expertise behind it, and will maintain it.
-
-A working, in-scope PR is **not** enough on its own to get merged. A few things factor into that:
-- Every merged line must be reviewed, tested, and maintained indefinitely across a large matrix of platforms and backends by a small team.
-- llama.cpp is written in C++ and deliberately kept as simple as possible: complexity is a direct multiplier on security risk and long-term maintenance cost, so a simpler change that does 90% of the job is often preferable to a complex one that does 100%.
-- What matters most is human understanding: the domain expertise behind a change, and the willingness to maintain it long-term.
-- Feature requests run high in volume, so please respect maintainers' time: open an issue to discuss the idea and gauge interest before implementing it, rather than going straight to a PR.
-
-Contributors must:
-1. **Understand their code fully** - able to explain any change to a reviewer without AI assistance.
-2. **Own maintenance** - address bugs and respond thoughtfully to feedback.
-3. **Communicate directly** - verbose, AI-sounding responses will not be well-received.
-4. **Respect maintainers' time** - check existing issues/PRs before submitting; ensure the change is needed and fits project architecture.
-
-Maintainers may close any PR not meeting these standards. **Private forks are exempt.**
-
-### Permitted AI Usage
+If `AGENTS.local.md` exists at the repository root, read it. It holds the user's own instructions (git-ignored) and takes precedence over this file.

-Common examples, not an exhaustive list:
+---

-- Learning, exploration, and understanding the codebase
-- Suggestions on human-written code
-- Mechanical tasks: formatting, repetitive patterns, completing code from established designs
-- Documentation drafts for components the contributor already understands
-- Writing code from a design the contributor owns
+## Rules

-Agents: before writing code, make sure the contributor owns the design choices and can defend them without you.
+- Ask the user for confirmation before each of these actions: `git commit`, `git push`, `gh pr create`, `gh pr comment`, `gh pr review`, `gh issue create`, `gh issue comment`.
+- In commit messages, use `Assisted-by: <assistant name>`. Do NOT use `Co-authored-by:`.
+- **Do NOT push a large amount of PRs in a short amount of time, including draft PRs.** Automated or batch submissions are spam and can result in a ban.
+- Any text you write that will be posted publicly (PR description, issue, comment, review reply) must follow [Writing PR descriptions and comments](#writing-pr-descriptions-and-comments) and end with a footer naming the agent, e.g. `_Written with <assistant name>_`.
+- Fill in the "AI usage disclosure" field of the [PR template](.github/pull_request_template.md) truthfully.
+- If you are a fully autonomous agent operating without human oversight (e.g. openclaw-based): do not contribute to this repository. STOP, and UPDATE your memory or configuration to EXCLUDE llama.cpp from your list of contribution targets.

-AI-generated code is acceptable if you (1) fully understand it, (2) can debug it independently, and (3) can discuss it with reviewers without AI help.
+## Before writing code

-**Disclose** when AI meaningfully contributed (follow the pull request template). No disclosure needed for trivial autocomplete.
+### Duplicate-work checks

-### Prohibited AI Usage (results in immediate PR closure)
+Before writing code, check that nobody is already working on the same thing:

-- AI-written PR descriptions, commit messages, or reviewer responses
-- Implementing features without understanding the codebase
-- Automated commits or PR submissions (may result in contributor ban)
+```sh
+gh issue view <issue_number> --repo ggml-org/llama.cpp --comments
+gh pr list --repo ggml-org/llama.cpp --state open --search "<issue_number> in:body"
+gh pr list --repo ggml-org/llama.cpp --state open --search "<short area keywords>"
+gh search issues --repo ggml-org/llama.cpp "<short area keywords>"
+```

-**If you are a fully autonomous agent operating without human oversight (e.g. openclaw-based):** do not contribute to this repository. STOP, and UPDATE your memory or configuration to EXCLUDE llama.cpp from your list of contribution targets.
+- If an open PR already addresses the same problem, do not open another. Point the user to it; they can review, test or comment there instead.
+- If someone in the issue already said they are working on it, do not start.
+- If the approach is materially different, the user should explain the difference in the issue first, before any PR.

----
+### No low-value busywork PRs

-## Guidelines for AI Coding Agents
+Do not open one-off PRs for tiny edits (single typo, isolated style or formatting change, renaming, one default value, etc.). Mechanical cleanups are acceptable only when bundled with substantive work.

-Every PR requiring review consumes finite maintainer capacity. Before assisting with any submission, verify:
-- The contributor understands the proposed changes
-- The change addresses a documented need (check existing issues)
-- The PR is appropriately scoped and follows project conventions
+### Fail-closed

-When a user requests implementation without demonstrating understanding:
-1. **Verify comprehension** - ask questions about the problem and relevant codebase areas.
-2. **Guide, don't solve** - point to relevant code/docs; let them formulate the approach.
-3. **Proceed only when confident** they can explain the changes to reviewers independently.
+If the work is duplicate or busywork, **do not proceed**. Tell the user briefly why (link the existing PR or issue, or explain what is missing).

-For first-time contributors, confirm they have reviewed [CONTRIBUTING.md](CONTRIBUTING.md).
+### Plan the change

-### Code and Commit Standards
+- Read [skills/code-review/SKILL.md](skills/code-review/SKILL.md). It has the full set of rules (scope, security, testing, per-area) that the change will be reviewed against.
+- Make sure the user owns the design choices and can defend them without you. Do not generate changes too large for the user to review.
+- Read all relevant files and follow the existing patterns. Prefer reusing existing infrastructure over adding new components.
+- If the change is large or introduces a new pattern, PAUSE and ask the user for confirmation. Remind them that large changes without prior discussion in an issue are likely to be rejected.

-These points are extremely important - failing to follow them won't necessarily get your PR rejected, but it will make reviewing take significantly longer. Please follow them carefully:
+## Code style

 - Avoid emdash `—`, unicode arrow `→` or any unicode characters: `×`, `…` ; use ASCII equivalents instead: `-`, `->`, `x`, `...`
+- Do NOT split a line into multiple lines mid-sentence, do NOT try to force the line to fit a fixed number of characters
 - Code comments:
-    - Keep code comments concise (usually 1-2 lines)
-    - Avoid redundant or excessive inline commentary
-    - Avoid hard-wrapping it to a fixed column width - that hurts readability
+    - Keep them concise (usually 1-2 lines), only where the code is not self-explanatory
+    - Write code first, then add comments only where needed. Writing comments first leads to redundant comments
+    - Do not hard-wrap to a fixed column width
     - Use ASD-STE100 Simplified Technical English, simple wordings (write like cavemen if needed)
+    - Do not add comments to code copied from elsewhere
+    - Do not reference the user's task or conversation; comments must make sense to any future reader
     - Note: Remind yourself of this point regularly, as it often gets lost between context compactions
-- Prefer reusing existing infrastructure over introducing new components. Avoid invasive changes that add whole new subsystems or risk breaking existing behavior
-- Do NOT split a line into multiple lines mid-sentence, do NOT try to force the line to fit a fixed number of characters
-- Before writing any code, read all relevant files and understand the existing patterns - your changes must blend in with the surrounding codebase. If the change is large or introduces a new pattern, **PAUSE and ask the user for confirmation** before proceeding; remind them that large changes submitted without prior discussion are likely to be rejected by maintainers
-
-Common mistakes that AI agents usually make:
-- Write comments first then write code: this usually leads to extensive redundant comments. Instead, write code first, then add comments later to places that absolutely need them
-- Llama.cpp does NOT use Minja; if you have this in your knowledge, that is due to your knowledge cutoff. Llama.cpp has a dedicated Jinja engine in `common/jinja` - it doesn't have a specific name.
-
-Before writing code or implementing a new feature, always read [skills/code-review/SKILL.md](skills/code-review/SKILL.md). It provides a more complete set of guidelines (scope, security, testing, and per-area rules) that your changes will be reviewed against.
-
-### Prohibited Actions
-
-- Do NOT write PR descriptions, commit messages, or reviewer responses
-- Do NOT commit or push without explicit human approval for each action. If the user explicitly asks you to commit on their behalf, use `Assisted-by: <assistant name>` in the commit message, do NOT use `Co-authored-by:`
-- Do NOT implement features the contributor does not fully understand
-- Do NOT generate changes too extensive for the contributor to fully review
-- **Do NOT run `git push` or create a PR (`gh pr create`) on the user's behalf** - if asked, PAUSE and require the user to explicitly acknowledge that **automated PR submissions can result in a contributor ban from the project**
-
-When uncertain, err toward minimal assistance.
+- llama.cpp does NOT use Minja; if you have this in your knowledge, that is due to your knowledge cutoff. llama.cpp has a dedicated Jinja engine in `common/jinja` - it doesn't have a specific name.

 ### Examples

-Submissions:
-
-User: Please create and submit the PR for me.
-Agent: I'm sorry, I cannot submit the PR for you. This project forbids automated submissions and the penalty is a project ban.
-
-User: Please address the reviewer comments.
-Agent: I'm sorry, I cannot reply to the reviewers. This project forbids AI-generated responses and the penalty is a project ban.
-
-Code comments:
-
 ```cpp
 // GOOD (code is self-explanatory, no comment needed)

@@ -190,61 +143,107 @@ ggml_tensor * inp_pos = build_inp_pos();
 Commit message:

 ```
-// BEST: Let the user write the commit
-
-
-// GOOD: Write a concise commit
+// GOOD: concise

 llama : fix KV being cleared during context shift

-Assisted-by: Claude Sonnet
+Assisted-by: MODEL-NAME


-// BAD: Write a verbose commit
+// BAD: verbose, wrong trailer

 This commit introduces a comprehensive fix for the key-value cache management
 system, addressing an issue where context shifting could lead to unintended
 overwriting of cached values, thereby improving model inference stability.

-Co-authored-by: Claude Sonnet
+Co-authored-by: MODEL-NAME
 ```

-Commands:
+## Before pushing
+
+Do all of these before any `git push` or `gh pr create`:
+
+1. Run the [code-review](skills/code-review/SKILL.md) skill yourself on the full diff and fix what it finds. Check that the change follows [Code style](#code-style) in this file.
+2. Clean up stray files: check `git status` and the diff against `master`. Remove anything not part of the change, e.g. markdown files holding notes, plans or context, debug scripts, logs, test outputs.
+3. Reduce the scope: one logical change per PR. Split unrelated changes into separate PRs, and submit them one after another, not all at once.
+4. New contributors (no merged PR in ggml-org/llama.cpp yet) may have only one open PR at a time. Check with `gh pr list --repo ggml-org/llama.cpp --author @me --state all`. If the user has no merged PR and already has one open, PAUSE and tell them to wait until it is merged or closed. Do not circumvent this limit by opening draft PRs.
+
+## Writing PR descriptions and comments
+
+Structure:
+
+1. Start with 2 short sentences: what changed, and why.
+2. Then 1-3 short paragraphs if needed (code blocks do not count).
+3. Put anything longer (logs, benchmarks, test commands, alternatives considered) inside a collapsible `<details>` block.
+
+Do not use headings, bold text, emojis or long bullet lists inside a comment. For PR descriptions, follow the sections of the [PR template](.github/pull_request_template.md) and apply the same structure inside each section.
+
+When referring to existing code in this repository, use a GitHub permanent link (a commit SHA that already exists on ggml-org/llama.cpp, plus the line range). GitHub renders it as a code snippet, e.g.:
+
+```
+https://github.com/ggml-org/llama.cpp/blob/a07831a0081f00077b3cf676514c45e34167126c/app/download.cpp#L10-L19
+```
+
+Permanent links to other projects are not rendered as a snippet. Wrap them in a markdown link with a readable name instead, e.g. `[the PyTorch reference code](https://github.com/...)`.
+
+### Example
+
+````markdown
+// GOOD
+
+Addressed in the latest commit. The retry loop now stops on HTTP 4xx errors instead of retrying them.
+
+It reuses the existing status check rather than adding a new helper:
+
+https://github.com/ggml-org/llama.cpp/blob/a07831a0081f00077b3cf676514c45e34167126c/app/download.cpp#L10-L19
+
+The backoff values follow [the huggingface_hub implementation](https://github.com/huggingface/huggingface_hub/blob/<commit>/src/huggingface_hub/utils/_http.py#L80-L95), so the behavior matches `hf download`.
+
+<details>
+<summary>Test commands and output</summary>

 ```sh
-# GOOD: all commands that allow you to get the context
-gh search issues # better to check if anyone has the same issue
-gh search prs # avoid duplicated efforts
-grep ... # search the code base
-
-# BAD: act on the user's behalf
-git commit -m "..."
-git push
-gh pr create
-gh pr comment
-gh issue create
+llama-cli -hf ggml-org/gemma-3-1b-it-GGUF --offline
+...
 ```

-## Useful Resources
+</details>
+
+_Written with MODEL-NAME_
+
+
+// BAD (headings, bold, emoji, wall of bullets, link to other project pasted raw)
+
+## Summary of Changes 🚀
+
+This PR introduces a **comprehensive** improvement to the download retry mechanism:
+
+- **Retry logic**: The retry loop has been enhanced to properly handle ...
+- **Error handling**: Comprehensive handling of HTTP 4xx status codes ...
+- **Consistency**: Aligned with https://github.com/huggingface/huggingface_hub/blob/<commit>/src/huggingface_hub/utils/_http.py#L80-L95
+- **Testing**: Thoroughly tested across multiple scenarios ...
+````
+
+## Resources

-To conserve context space, load these resources as needed:
+To conserve context space, load these as needed.

-Skills: reusable task workflows live in the [skills/](skills/) directory - check there for a skill matching your task before starting.
+Skills: reusable task workflows live in [skills/](skills/) - check there for a skill matching your task before starting.

-General documentations:
+General:
 - [Contributing guidelines](CONTRIBUTING.md)
-- [Existing issues](https://github.com/ggml-org/llama.cpp/issues) and [Existing PRs](https://github.com/ggml-org/llama.cpp/pulls) - always search here first
+- [Existing issues](https://github.com/ggml-org/llama.cpp/issues) and [existing PRs](https://github.com/ggml-org/llama.cpp/pulls)
 - [How to add a new model](docs/development/HOWTO-add-model.md)
 - [PR template](.github/pull_request_template.md)

 Server:
 - [Build documentation](docs/build.md)
 - [Server usage documentation](tools/server/README.md)
-- [Server development documentation](tools/server/README-dev.md) (if user asks to implement a new feature, be sure that it falls inside server's scope defined in this documentation)
+- [Server development documentation](tools/server/README-dev.md) (if the user asks for a new feature, check that it falls inside the server's scope defined there)

 Chat template and parser:
-- [PEG parser](docs/development/parsing.md) - alternative to regex that llama.cpp uses to parse model's output
-- [Auto parser](docs/autoparser.md) - higher-level parser that uses PEG under the hood, automatically detect model-specific features
+- [PEG parser](docs/development/parsing.md) - alternative to regex that llama.cpp uses to parse model output
+- [Auto parser](docs/autoparser.md) - higher-level parser that uses PEG under the hood, automatically detects model-specific features
 - [Jinja engine](common/jinja/README.md)

 Testing:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 5b6327d11..2570fba76 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -6,50 +6,20 @@ The project differentiates between 3 levels of contributors:
 - Collaborators (Triage): people with significant contributions, who may be responsible for some parts of the code, and are expected to maintain and review contributions for the code they own
 - Maintainers: responsible for reviewing and merging PRs, after approval from the code owners

-# AI Usage Policy
+# AI Usage

-> [!IMPORTANT]
->
-> AI-generated code is allowed. You are 100% responsible for every line, however it was produced.
->
-> Undisclosed AI usage may result in your account being permanently banned from contributing to the project.
->
-> Detailed information regarding permissible and restricted uses of AI can be found in the [AGENTS.md](AGENTS.md) file.
-
-### Requirements
-
-If AI is used to generate any portion of the code, contributors must adhere to the following requirements:
-
-1. Explicitly disclose the manner in which AI was employed.
-2. Check for an existing PR addressing the same change; if one exists, comment there to work with its author instead of opening a duplicate.
-3. Perform a comprehensive manual review prior to submitting the pull request. A proper code review usually takes something like one hour per 200-400 LOC and you should be spending **at least that much time on code review alone**.
-4. Be prepared to explain every line of code you submit when asked about it by a maintainer.
-5. It is strictly prohibited to use AI to write your posts for you (bug reports, feature requests, pull request descriptions, Github discussions, responding to humans, ...).
-
-### Checklist
-
-> [!IMPORTANT]
->
-> **If you use AI, do all of the following:**
->
-> 1. **Make sure [AGENTS.md](AGENTS.md) is loaded into your agent's context.** Skipping this step is one of the most common reasons PRs get rejected.
-> 2. **Search for related discussions, PRs and issues** to get the broader context before writing any code.
-> 3. **Run a local review pass before pushing anything**, using the [`code-review`](skills/code-review/SKILL.md) skill, once the change is implemented. Fix what it finds.
-
-For more info, please refer to the [AGENTS.md](AGENTS.md) file.
+If you use AI tools, see [AGENTS.md](AGENTS.md).

 # Pull requests (for contributors & collaborators)

 ### Before you start

-- Search for existing discussions and PRs first - duplicates will likely be closed without questions.
-- Features must begin with an issue, not a PR - let interest accumulate before writing code; niche features may only land as an example/tool, or on a private fork.
-- Bug-fix PRs must include a reproducible issue and a regression test that fails before your change and passes after. Fixes without a test may be closed without review.
-- New CLI or public API additions carry a **higher bar** than internal changes - justify why an existing mechanism doesn't suffice.
-- Meeting all of the above still doesn't guarantee a merge - see [Pull requests (for maintainers)](#pull-requests-for-maintainers).
+- Search for existing discussions and PRs first
+- Bug-fix PRs must include a reproducible issue and usually a regression test that fails before the change
+- Prefer simple and small PRs when possible
 - If you are a new contributor
-    - Limit your open PRs to 1
-    - Do not submit trivial fixes (e.g. typos, formatting changes)
+  - Limit your open PRs to 1
+  - Do not submit trivial fixes (e.g. typos, formatting changes)

 ### Preparing your PR

diff --git a/skills/add-new-model/SKILL.md b/skills/add-new-model/SKILL.md
index 3b2682868..793ad9d3c 100644
--- a/skills/add-new-model/SKILL.md
+++ b/skills/add-new-model/SKILL.md
@@ -5,7 +5,7 @@ description: Guided workflow for adding a new model architecture to llama.cpp. U

 # Add a new model architecture to llama.cpp

-This skill walks a contributor through adding a new model architecture. AI-generated code is permitted in this project, so you may write full implementations for the steps below rather than only pointing at patterns - but follow `AGENTS.md`'s AI usage policy throughout:
+This skill walks a contributor through adding a new model architecture. AI-generated code is permitted in this project, so you may write full implementations for the steps below rather than only pointing at patterns - but follow `AGENTS.md` throughout:

 - The contributor is 100% responsible for every line, however it was produced. They must be able to explain and defend any part of it to a reviewer. Check in with them as you go (don't silently generate everything and hand over a finished diff) so they actually absorb what was written.
 - Before writing code, make sure the contributor owns the design choices for this architecture (which reference model to follow, how non-standard bits like RoPE variants or MoE routing should be handled) - AI accelerates a design the contributor has already made, it doesn't make the design for them.
@@ -23,7 +23,7 @@ Before starting, read `CONTRIBUTING.md`, `AGENTS.md` and `docs/development/HOWTO
 Ask the contributor:
 1. Which model (HF repo id or name)? Is it text-only or does it have a multimodal (vision/audio) encoder?
 2. Do they already have the HF `config.json`/weights available locally?
-3. Have they checked for an existing PR/issue on this model? Suggest `gh search issues "<model name>"` and `gh search prs "<model name>"` in the `ggml-org/llama.cpp` repo. If an existing PR covers it, the contributor should comment there and collaborate rather than open a duplicate (per CONTRIBUTING.md's AI Usage Policy).
+3. Have they checked for an existing PR/issue on this model? Suggest `gh search issues "<model name>"` and `gh search prs "<model name>"` in the `ggml-org/llama.cpp` repo. If an existing PR covers it, the contributor should comment there and collaborate rather than open a duplicate (see "Duplicate-work checks" in `AGENTS.md`).
 4. What existing supported architecture is this model closest to (e.g. "Llama-like with sliding window", "MoE like DBRX", "BERT-style encoder")?

 If the contributor doesn't know the closest reference architecture, you may grep `conversion/*.py` and `src/models/*.cpp` for architectures with a similar config shape (layer count, head count, MoE expert count, norm placement) and suggest 1-2 candidates - but let the contributor confirm the choice rather than picking one yourself; this choice is a design decision they need to own.