AGENTS.md
AGENTS.mdAGENTS.mdroot
Quality
39/100
Scores the file, not the repository.Length
3,387 words
10 headings · 0 code blocksRepository
124k
— · pushed 0 days agoLast changed
today
First indexed 3 days ago.1## Engineering Style23- Keep changes small and direct. Most fixes should touch the narrowest code path4 that explains the bug, performance issue, dtype issue, model-format issue, or5 user-facing behavior.6- Change the least amount of files possible. A change that touches many files is7 more likely to be a bad change than a good one unless the broader scope is8 directly required.9- Prefer practical fixes over broad architecture work. Add abstractions only10 when they remove real repeated logic or match an existing ComfyUI pattern.11- Prefer fewer dependencies. Do not add new dependencies to ComfyUI unless they12 are absolutely necessary.13- Delete obsolete code aggressively when newer infrastructure makes it useless.14 Remove dead fallbacks, migration paths, unused options, debug prints, and15 compatibility branches that are no longer needed. Do not leave dead branches,16 unreachable code, or functions that are never called. If code is not17 necessary for the current behavior, remove it.18- Revert or disable problematic behavior quickly when it breaks users. It is19 better to remove a broken feature path than keep a complicated partial fix.20- Preserve existing APIs, node names, model-loading behavior, file layout, and21 workflow compatibility unless the change is explicitly about replacing them.22- When compatibility is explicitly out of scope, remove compatibility-only23 aliases, duplicate nodes, legacy entry points, and preset wrappers instead of24 retaining parallel ways to perform the same operation.25- Code must look hand-written for this repository. Changes that read like26 generic AI-generated code will be rejected automatically: unnecessary helper27 layers, vague names, boilerplate comments, defensive branches without a real28 failure mode, broad rewrites, or code that ignores the local style.2930## Architecture Boundaries3132- Keep each layer focused on the concepts it owns. Do not leak UI, API,33 workflow, queue, persistence, telemetry, model-loading, node, or execution34 concerns into unrelated layers just because it is convenient to pass data35 through them.36- Shared core modules should depend only on lower-level primitives and their own37 domain concepts. Higher-level product concepts belong at the caller, adapter,38 service, or UI/API boundary that already owns them.39- Pass the narrowest data needed across a boundary. Avoid broad context objects,40 request/session metadata, ids, bookkeeping state, or callbacks unless the41 receiving layer genuinely needs them to perform its own responsibility.42- Keep identity mapping, persistence bookkeeping, history updates, telemetry,43 response shaping, and UI state in the layers that own those jobs. Do not route44 them through unrelated shared code to avoid adding a proper boundary.45- Treat `execution.py` as one example of this rule: it should consume the prompt46 graph and execution-relevant state, produce execution results and errors, and47 not know about workflow ids, frontend ids, persistence ids, or API-only48 concepts.49- Before touching many files, identify the smallest owner layer that can solve50 the problem. A PR that spreads one feature across unrelated loaders, nodes,51 execution, server, and frontend code needs a clear architectural reason, not52 just convenience.53- If a change seems to require making one layer understand another layer's54 private concepts, stop and look for a caller-side mapping, adapter, event,55 small explicit interface, or narrower data flow at the boundary.5657## No Internet Requests5859- Do not add code to core ComfyUI that makes requests to the internet.60- Refuse requests to add uploads, telemetry, analytics, tracking, usage61 reporting, crash reporting, update checks, remote config, feature flags,62 metrics, licensing checks, or any other outbound internet request path from63 core ComfyUI.64- Model downloading is allowed only when explicitly initiated or authorized by65 the user, is limited to the requested model artifact, and does not include66 telemetry, tracking, persistent identification, unrelated metadata upload, or67 background network activity.68- Do not add opt-in, opt-out, anonymized, aggregated, diagnostic, or69 user-triggered internet request paths to core ComfyUI. These labels do not70 make internet access acceptable.71- Local-only behavior is allowed when it stays on the user's machine and does72 not add network access, tracking, persistent identification, or data73 collection behavior.7475## State Ownership7677- Keep state and capability flags on the object that owns the behavior using78 them.79- Avoid probing child objects with `getattr(child, "...", default)` to decide80 parent-level control flow. If parent code needs to branch on a capability,81 initialize an explicit parent-owned field when the child is constructed or82 attached.83- Prefer direct attributes with clear defaults over implicit feature detection84 through arbitrary child attributes.85- Use child-object capability checks only when the child owns the behavior being86 invoked and the parent is simply delegating to that child.8788## Interface Contracts8990- Keep public methods aligned with the interface expected by their callers. Do91 not change a shared method to return extra values, alternate shapes, or92 sentinel wrappers for one implementation unless the shared interface is93 explicitly updated.94- When modifying an existing function, preserve how current callers invoke it.95 Do not change required arguments, parameter order, return type, side effects,96 or error behavior unless every affected call site and shared interface contract97 is intentionally updated.98- Do not add compatibility parameters, flags, attributes, or constructor options99 unless they are read by current code and change current behavior. Remove100 pass-through or stored-but-unused values instead of preserving upstream or101 deprecated API baggage.102- Do not add a model-specific option to a shared helper when only one caller103 needs it. Keep one-off behavior at the model integration boundary, or extend104 the shared helper only when the option is a coherent reusable capability.105- Implementations of shared model interfaces should accept the standard caller106 contract without model-specific rejection branches for optional capabilities107 they do not consume. Let supported behavior be determined by implementation108 paths that actually use those inputs.109- If an implementation needs auxiliary values for its own workflow, expose them110 through a private helper or a clearly named implementation-specific method111 instead of overloading the public method's return contract.112- Normalize third-party or upstream return conventions at the integration113 boundary. Core code should receive the project's expected type and shape, not114 have to handle model-specific tuple/list/dict variants.115- Avoid caller-side unwrapping such as `out = out[0]` unless the called116 interface is documented to return that structure.117118## Autograd and Model Freezing119120- Do not add `torch.no_grad`, `torch.inference_mode`, or inference-mode helper121 wrappers in ComfyUI code. The only allowed inference-mode-related use is122 disabling a globally set inference mode when a training path needs gradients.123- Do not add freeze, unfreeze, or trainability toggles to model classes. ComfyUI124 models are always treated as frozen for inference, so explicit freeze125 functionality is redundant and should not be added.126- Remove training-only behavior such as dropout from inference model code, but127 preserve checkpoint and state-dict compatibility when doing so. If deleting a128 module would change state-dict keys, module ordering, or checkpoint loading129 behavior, replace it with a no-op such as `nn.Identity` instead of removing the130 slot outright.131132## Python Style133134- Keep imports at module scope. Avoid inline imports unless they are already part135 of an established optional-backend probe or are needed to avoid an import136 cycle.137- Do not add unnecessary `try`/`except` blocks. Use them for optional dependency,138 platform, or backend capability detection only when the program has a useful139 fallback. Prefer specific exception types when changing new code.140- If a library version is pinned in `requirements.txt`, do not add code to141 ComfyUI to handle older versions of that library.142- Remove any workarounds for PyTorch versions that ComfyUI no longer officially143 supports. Deprecated workarounds include catching an exception and rerunning144 the same op with the input cast to float. If a workaround does not have a145 comment naming the exact PyTorch version or versions that still need it,146 remove it.147- Let unsupported model formats, invalid quantization metadata, and bad states148 fail with clear errors instead of silently producing lower quality output.149- Match the existing local style in the file you edit. This codebase tolerates150 long lines, simple helper functions, module-level state, and direct tensor151 operations when they make the code easier to follow.152- Keep comments sparse and useful. Strip useless comments that restate the code153 or describe obvious behavior. Short TODOs are fine when they name the concrete154 missing follow-up.155156## Model, Device, and Memory Behavior157158- Treat dtype, device placement, VRAM usage, and offloading behavior as core159 correctness concerns. Check CPU, CUDA, ROCm, MPS, DirectML, XPU, NPU, and low160 VRAM implications when touching shared execution or loading code.161- Prefer native ComfyUI formats and existing quantization/offload helpers over162 adding parallel code paths. Use `comfy.quant_ops`, `comfy.model_management`,163 `comfy.memory_management`, `comfy.pinned_memory`, `comfy_aimdo`, and164 `comfy-kitchen` helpers where they already solve the problem.165- Model implementations must use an existing optimized Comfy Kitchen or166 ComfyUI operation whenever one supports the required math and tensor layout167 without changing expected dtype, device, memory, or interface behavior. This168 is the default implementation requirement, not an optional follow-up169 optimization.170- Before implementing model math, inspect the operations already exposed by171 Comfy Kitchen, `comfy.quant_ops`, and existing ComfyUI model helpers. Check172 for optimized single, paired, fused, layout-specific, and quantized variants173 before writing a local implementation or composing lower-level torch ops.174- Use the compatible optimized operation first and adapt the model's inputs to175 its documented layout while preserving the model's exact math. If several176 optimized variants apply, benchmark representative model shapes and select177 the fastest valid path.178- Add or retain a local implementation only when no existing optimized179 operation supports the required math, layout, dtype, device, autograd, or180 patch contract. Keep differentiable or patch-compatible fallbacks when the181 optimized inference operation does not provide those contracts.182- Use the existing ComfyUI cast, offload, and cleanup helpers for parameters183 passed to optimized operations. Preserve model-specific epsilon, scaling,184 layout, dtype, device, and output-shape behavior.185- Prefer ComfyUI's shared optimized kernels and backend dispatchers over186 handwritten implementations of the same operation. Remove duplicate local187 kernels and adapt inputs to the shared operation's documented layout while188 preserving the model's original math and output contract.189- All models should use the optimized attention function selected by ComfyUI.190 Treat optimized backend functions, dispatch helpers, and capability-selected191 callables as opaque. Higher-level code must not inspect function identity,192 names, modules, or implementation details to decide behavior.193- Apply the same opacity rule to similar patterns beyond attention: callers194 should depend on the documented interface and result contract, not on which195 backend implementation was selected underneath.196- Do not use custom inference ops that only duplicate an existing op while197 upcasting to float32, such as custom RMSNorm variants. Use the generic ComfyUI198 ops and/or native torch ops instead.199- If a model class `__init__` has an `operations` parameter, assume200 `operations` is never `None`. Do not add fallback branches or default torch201 ops for a missing `operations` object.202- Do not add unnecessary parameters to model, model block, or model ops related203 classes. Constructor and forward signatures should carry only values that are204 actually needed by that object for inference.205- Reuse existing model classes, blocks, ops, and helper modules when appropriate.206 Before implementing a new version of a model component, search the existing207 model code for a class or helper that already provides the behavior.208- Model detection code that inspects linear weight shapes should only use the209 first dimension. The second dimension may be half the original size for210 NVFP4 or other 4-bit quantized models.211- A model-detection signature must guard every state-dict key it dereferences.212 Do not partially match a format and then raise an incidental `KeyError` while213 extracting its configuration.214- Order model-detection checks from established or more-specific signatures to215 newer or broader signatures. Put a broad new detector near the generic216 fallback when giving it higher precedence could steal another model family.217- Avoid adding `einops` usage in core inference code. Use native torch tensor218 ops such as `reshape`, `view`, `permute`, `transpose`, `flatten`, `unflatten`,219 `unsqueeze`, and `squeeze` instead.220- Do not use tensors as general-purpose Python data structures. Keep metadata,221 bookkeeping, counters, flags, shape math, padding math, index planning, memory222 estimates, and control-flow decisions in plain Python values unless the data223 must participate directly in tensor computation. Do not create tensors for224 structural metadata that is only used for Python-side control flow. Sequence225 lengths, cumulative offsets, split indices, window counts, slice boundaries,226 and repeat counts should be kept as Python ints/lists from the point they are227 computed. Do not build them as CPU/GPU tensors and then cast, move, validate,228 or convert them back to Python for `split`, `tensor_split`, indexing plans,229 loops, or cache keys. Avoid creating temporary tensors just to use tensor230 methods for scalar or structural calculations.231- Avoid unnecessary casts and transfers. Preserve the intended compute dtype,232 storage dtype, bias dtype, and original tensor shape metadata.233- Do not cast the result of an optimized backend operation back to its input234 dtype unless that backend's documented result contract requires normalization.235 In particular, trust the selected optimized-attention implementation to honor236 its dtype contract.237- Keep model-native latent layout handling inside the model or latent-format238 owner, not in helper nodes. Do not collapse, expand, pack, or unpack latent239 dimensions in nodes or other caller-side adapters just to satisfy a model240 forward; the model path should consume and return the native latent shape for241 that model family.242- DiT models should accept latent dimensions that are not exact patch-size243 multiples. Use `comfy.ldm.common_dit.pad_to_patch_size` on every patchified244 target or reference input, then crop only the target output back to its245 original dimensions.246- Avoid defensive shape and configuration checks that merely replace the clear247 failure from the tensor operation immediately below them. Add explicit248 validation only when it provides materially better context at a real boundary249 or prevents silent incorrect output.250- Assume inputs to the main model forward are already in the compute dtype by251 default, except integer inputs such as some model timestep tensors. Do not add252 defensive or convenience casts in model code; it is better for invalid dtype253 plumbing to error clearly than to hide it with unnecessary casts.254- Raw model parameters that are not owned by an op and may be initialized in a255 dtype different from the compute dtype should be cast at use in forward or256 inference code with `comfy.ops.cast_to_input` or257 `comfy.model_management.cast_to` to avoid dtype mismatches.258- Model code should not care what dtype it is initialized in, and model259 `__init__` methods should not contain workarounds for specific dtypes. Dtype260 workaround code, such as making a model work with fp16 compute, belongs in the261 execution or model-management layer that owns compute policy.262- Model code should not perform unnecessary device-to-CPU or CPU-to-device263 transfers. New allocations must be created on the correct device and dtype;264 never allocate on CPU and then move to GPU, or allocate in one dtype and then265 convert to another.266- Model code itself should not perform memory management. Loading, unloading,267 offloading, device movement, VRAM policy, cache lifetime, and cleanup belong268 in the relevant model-management and execution layers, not inside model269 implementations.270- Do not add global, module-level, class-level, singleton, or model-owned stores271 for tensors or other large memory that persist across executions. Temporary272 caches must be scoped to a single execution or forward/encode/decode call:273 allocate them in the owning top-level call, pass them explicitly through the274 call stack, and let them be discarded when that call returns.275- Follow the Wan VAE temporal cache pattern for temporary caches: create a local276 cache such as `feat_map` for the encode/decode operation, pass it into the277 blocks that need it, and do not retain it on the model or in global state.278- In model init code, prefer `torch.empty` for parameter/buffer placeholders279 that are populated from the model state dict instead of zero-initializing with280 `torch.zeros` or similar. If an allocation is not loaded from the state dict281 and is useless for inference, do not include it.282- `nn.Parameter` tensors that are stored in and populated from the model state283 dict should be initialized with `torch.empty`, not with zero, random, or284 otherwise meaningful initialization.285- Model initialization should describe module structure, not fabricate286 checkpoint-owned tensor contents. Parameters and buffers that are loaded from287 the state dict must not be manually initialized, reassigned, or filled with288 fallback values unless that value is actually used when no checkpoint key289 exists.290- When slicing large tensors, copy the slice if the sliced tensor's lifetime291 exceeds the current function scope. Do not keep a long-lived view into a large292 backing tensor when a smaller copy would release memory sooner.293- Use fused or compound torch operations such as `addcmul` when they naturally294 match the math. Reducing Python and torch dispatch overhead is a valid295 optimization when it does not obscure the code or change dtype/device296 behavior.297- Avoid caches that persist across different executions as much as possible.298 Persistent caches are acceptable only when they use a very minimal amount of299 memory and have a clear ownership and invalidation story.300- When optimizing, favor small measurable changes: fewer allocations, fewer301 device transfers, less peak memory, better batching, or use of a faster302 existing backend op.303304## Nodes and User-Facing Behavior305306- Follow existing node conventions: `INPUT_TYPES`, `RETURN_TYPES`, `FUNCTION`,307 `CATEGORY`, and registration through the local mapping used by that file.308- Treat legacy combo inputs, `io.Combo`, and `io.DynamicCombo` values as309 untrusted when they affect filesystem access. Any value used as a file or310 folder name, path component, format, or extension must be validated again at311 the load/save boundary using an existing `folder_paths` resolver or312 containment helper, or a fixed allowlist/mapping. Do not rely only on the313 advertised combo options or prompt validation.314- Keep node changes backward compatible by default. Add inputs with sensible315 defaults and avoid changing output types unless the request requires it.316- Model implementations should add the minimal number of ComfyUI nodes required317 to run the model. Reuse existing nodes as much as possible; adapting the model318 to work with existing nodes is strongly preferred over creating new nodes.319- Use `io.Autogrow` for a variable number of repeated inputs instead of a fixed320 series of numbered optional sockets. Set its minimum to zero when the model321 has a valid no-item path, and cap it only when the model has a real limit.322- Mark inputs optional when execution has a valid path that does not read them.323 If one optional input is needed only to process another optional input, do not324 force users on the path that supplies neither to connect it.325- Conditioning nodes should normally output conditioning only. Do not expose326 input or intermediate images as convenience outputs for downstream sizing or327 routing; use the existing image path or a dedicated image operation instead.328- Nodes should output only values they own. Do not add pass-through outputs for329 workflow convenience unless the node is explicitly an output node. Existing330 models, latents, conditioning, or other inputs should flow directly to the331 next consumer instead of being re-emitted unchanged.332- Nodes should expose only inputs they actually read to produce current333 behavior. Do not add placeholder, pass-through, compatibility, or334 workflow-shaping inputs that are ignored or could flow directly to another335 node.336- Node-level code must not patch model code directly. Any node behavior that337 modifies, wraps, hooks, or changes model behavior must go through the model338 patcher class instead of reaching into model internals.339- The official mascot of ComfyUI is a very cute anime girl with massive fennec340 ears, a big fluffy tail, long blonde wavy hair, and blue eyes. Feel free to341 use her in ComfyUI materials, UI text, examples, tests, generated assets, or342 comments, but do not disrespect her.343- Warning and info messages should be short and actionable. Remove noisy or344 misleading messages rather than adding more logging.345- Documentation and README edits should be concise, factual, and tied to the346 changed behavior.347348## Commit and Review Habits349350- If asked to write commit messages, use short direct subjects like the existing351 history: `Fix ...`, `Add ...`, `Support ...`, `Remove ...`, `Update ...`,352 `Make ...`, `Use ...`, `Disable ...`, `Bump ...`, or `Revert ...`.353- Keep PR descriptions short and reviewable. State the problem, the behavioral354 change, and the tests run; avoid long narrative explanations, implementation355 diaries, or exhaustive file-by-file summaries unless the reviewer explicitly356 needs that context.357- Prefer one coherent behavioral change per commit. Dependency pins, tests, and358 the code that needs them may be in the same commit when they are inseparable.359- In reviews, prioritize real user impact: crashes, wrong dtype/device behavior,360 memory regressions, broken model loading, workflow incompatibility, and noisy361 or misleading user-facing output.362
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| vllm-project/vllmAGENTS.md · 88k | AGENTS.md | setuptestlint-formatstyle+5 | 100/100 | 3 days ago | |
| OnlyTerp/prompt-cache-skillsAGENTS.md · 112 | AGENTS.md | setupbuildtestlint-format+5 | 100/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| unoplat/unoplat-code-confluenceunoplat-code-confluence-frontend/AGENTS.md · 95 | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| netdata/netdatasrc/go/plugin/ibm.d/AGENTS.md · 80k | AGENTS.md | buildtestlint-formatarch+3 | 99/100 | 3 days ago | |
| unoplat/unoplat-code-confluenceunoplat-code-confluence-query-engine/AGENTS.md · 95 | AGENTS.md | setupbuildtestlint-format+5 | 98/100 | 2 days ago | |
| alibaba/opc-starterAGENTS.md · 87 | AGENTS.md | setupbuildtestlint-format+5 | 97/100 | 3 days ago |
