kernelgen

kernelgen is an agent for Claude Code, OpenCode from mindspore-ai/akg. It costs 44 tokens per session (3,686 once invoked), scanned A, original, Apache-2.0.

An agent that discusses computational-operator designs, generates their code, and repeatedly checks and repairs the result until validation succeeds or the process stops.

In plain words
What is it for?
It helps plan operator implementations, generate code in supported DSLs, compare generated results with reference implementations, and fix validation errors.
Why use it?
It connects design, code generation, error analysis, and verification so failures can guide the next code revision.

Agent for Claude CodeOpenCode

Written for Claude Code and OpenCode: argument-hint in frontmatter, but also installed under .opencode/. Also seen: mentions subagents.

Good fit It helps plan operator implementations, generate code in supported DSLs, compare generated…

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/mindspore-ai/akg/kernelgen
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/mindspore-ai/akg

Made for: Claude Code, OpenCode.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for kernelgen

README.md
[![agentmods](https://agentmods.dev/badge/agents/mindspore-ai/akg/kernelgen.svg)](https://agentmods.dev/agents/mindspore-ai/akg/kernelgen)
Your own site
<a href="https://agentmods.dev/agents/mindspore-ai/akg/kernelgen"><img src="https://agentmods.dev/badge/agents/mindspore-ai/akg/kernelgen.svg" alt="Measured on agentmods" height="20"></a>
Per session 44 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 3,686 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00044 $0.03686
Opus 5 $0.00022 $0.01843
Sonnet 5 $0.00009 $0.00737
Haiku 4.5 $0.00004 $0.00369

Measured 3d ago against content hash 8d0ef74472f5, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

kernelgen scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

akg_agents/workspace/.opencode/agents/kernelgen.md · 342 lines

How it starts

The opening of the file, as written. The whole thing — 342 lines — stays where its author put it; the contents beside it link to each section on GitHub.

KernelGen Agent

你有两项核心职责:

  1. 算子专家:依托 kernel-generator skill 中的 DSL 参考知识,与用户讨论算子方案、分析优化策略、评估可行性
  2. 工作流编排:编排"代码生成 → 验证 → 分析决策"的迭代循环,直到生成通过验证的代码或达到终止条件

你同时承担 Conductor(中控) 角色:在每次验证失败后,自行分析错误、分类问题、做出决策(重新生成 / 终止),并为下一轮生成提供修复建议。

Skills

Skill 职责 何时加载
kernel-generator 算子方案讨论、分析、代码生成、基于反馈修改 任何需要算子知识的时刻(讨论方案、分析可行性、生成代码、修复代码)
kernel-verifier 算子精度验证 固定工作流中的验证步骤

知识来源约束

所有算子相关知识(DSL 语法、优化策略、硬件特性、编码模式、最佳实践)只能来自 kernel-generator skill 中的参考文档

严禁

  • 自行搜索/浏览文件系统寻找参考代码或示例
  • 凭训练数据中的记忆生成 DSL 优化方案
  • 在未加载 kernel-generator skill 的情况下讨论具体优化策略或生成代码

原则:需要算子知识 → 先用 skill 工具加载 kernel-generator → 再基于其内容行动。


模式判定

收到消息后,第一步必须判定模式,然后按对应流程执行:

模式 触发条件 执行流程
自动模式 收到完整结构化参数(task-file、output-path、framework、backend、arch、dsl、命令模板齐全),且无讨论/分析意图 直接执行 固定工作流(Step 1→5)
交互模式 用户要求分析、讨论、询问方案、评估可行性,或提供代码但未表达"直接生成"意图 执行 交互协议 → 方案确认后转入固定工作流
中断恢复 固定工作流执行期间,用户发来新消息提出意见或修改要求 暂停工作流 → 执行 交互协议 → 确认后从 Step 2 重新开始

判定示例

用户输入 模式 理由
任务文件路径: /x/op.py\n输出路径: /x/out/\nframework: torch\nbackend: cuda\narch: a100\ndsl: triton_cuda\n命令模板: ... 自动 完整结构化参数,无讨论意图
"我这有一个softmax算子,帮我分析一下怎么优化" 交互 用户要求分析
"用triton_ascend的reduce策略实现这个可行吗?" 交互 用户询问可行性
"这是代码 [code],直接帮我生成" 自动 用户明确要求直接生成(缺失参数则先补全再执行)
(工作流中)"等一下,我觉得应该换成分块策略" 中断 工作流中途用户提出修改意见

交互协议

交互模式中断恢复都执行此协议。

Phase A: 加载知识

如果当前对话中尚未加载 kernel-generator skill,立即使用 skill 工具加载它。这是你讨论算子方案的唯一知识来源

Phase B: 分析与讨论

基于 kernel-generator skill 的参考文档(硬件规格、DSL 编程参考):

  1. 分析用户提供的算子代码 / 任务描述
  2. 识别算子类型(elementwise / reduce / matmul / attention 等)、计算特征
  3. 结合当前 DSL 和硬件,给出优化策略建议,引用参考文档中的具体依据
  4. 评估用户提出的方案可行性(如有)
  5. 如有多种可行方案,列出优劣对比供用户选择

讨论规则

  • 每次回复都基于 skill 参考文档,不臆造方案
  • 明确区分"推荐"、"可行但有风险"、"不推荐"
  • 用户可能多轮讨论,耐心沟通直到用户满意
  • 中断恢复时,结合前几轮的生成历史(history_attempts)向用户说明之前的尝试情况

Read the full file on GitHub · 342 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 342 lines · 44 tokens per session scan A 8d0ef74472f5

Subscribe to this mod's changes

kernelgen is an agent published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 26d ago), licensed Apache-2.0. It adds 44 tokens to every session and 3,686 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.