Skip to main content

Operator Agent

一个 LLM 驱动的 GPU 算子开发 agent:输入自然语言或结构化请求(matmul / softmax / attention 等),由 LLM agent 设计、生成、修复 Triton / CUDA 核,经三级验证 (L1 编译 → L2 功能 → L3 性能 + Roofline)后产出可审计的结论。

  • 版本:0.7.2,采用 DSH 外层组装上下文与迭代。本地交付状态及工件身份见 v0.7.2 封版记录,能力与限制见 支持清单。已封版的 0.7.1 与安装回退记录保留。公开包仓库未发布。
  • 当前开发与封版剩余事项见 v0.7.2 封版待办。
  • v0.7.2 技术方案与图示包含总体架构图、开发流程图、恢复时序图和模块职责映射。
  • 完整执行示例与日志:真实 DSH 外层在 H20 上生成 Softmax、完成验证和独立终评,并附修复与同会话恢复实例。
  • v0.7.2 自助试跑指南:本机配置、可复制的 ReLU 提示词、日志查看与取消/恢复。
  • 固定 DSH 模型路由已完成真实模型与 H20 验收,转发仍需显式启用,性能提升未确立。历史 0.7.0 的冻结支持清单保持原样。
  • 运行模式:DSH 外层驱动上下文、生成与迭代;独立 CLI 保留无人值守流程
  • DSH 默认配置为绑定后的主模型请求执行任务级调用与输出预留硬门;同会话恢复保留原任务和预算,operator_resume 返回候选与证据引用。任务结束后可讨论,用户在新一轮直接提出新任务,由 DSH 自动准备独立任务;/op new 保留为手动入口。绑定前准备和辅助调用不在该限额内,费用未知。
  • DSL:Triton / CUDA 为主;后端接口预留模板型后端

30 秒开始

默认开发版本为 Python 3.12,由仓库根目录的 .python-version 固定;包的最低兼容版本仍为 3.9。 使用 uv 时可运行 uv venv --python 3.12,然后激活 .venv。

# 依赖极少,本仓库没有 requirements.txt
pip install numpy            # 必需:参考实现 / MockGPU
pip install torch triton     # 仅真机执行需要

# 全部单元测试(离线,不碰 GPU / LLM)
python -m pytest tests/ -q

# 零依赖演示:亲眼看一下「脊柱」的判定
# ⚠️ 它默认用 output/kernel_db.jsonl 那个 KernelDatabase(会往语料追加 retrieved 事件),
#    所以先把三个落点指到仓库外 —— 与跑测试同一个理由:
OPERATOR_AGENT_OUTPUT_DIR=/tmp/oa-demo/out \
OPERATOR_AGENT_LOG_DIR=/tmp/oa-demo/log \
OPERATOR_AGENT_KERNEL_DB=off \
python3 benchmarks/demos/demo_spine_local.py

# 真机端到端(需要 GPU + ~/.ssh/config 里的别名)
python test_nvidia_matmul.py

⚠️ 请始终用 python -m pytest tests/:pyproject.toml 已设 testpaths,裸跑也只收集 tests/,不会扫到根目录那几个需要真机的 driver 或 vendored 的 triton/ 检出。

日常循环不必跑全量(全量约 12 分钟,含真实 DSH/沙箱子进程):tests/acceptance 整组和 LeetCUDA 评分器子进程自测标了 slow,-m "not slow" 可跳过;进程/截止/取消敏感的用例标了 serial,并行运行时须单独串行。常用组合:

python -m pytest -q -m "not slow and not serial" -n 4 --dist loadfile    # 日常,约 80 s
python -m pytest -q -m "slow"                                             # 验收组,约 4 min(普通终端)
python -m pytest -q -m "serial"                                           # 时序组,约 20 s
python -m pytest -q                                                        # 全量(封版前),约 12 min

需要 pytest-xdist(uv pip install pytest-xdist)。并发度别开到 -n auto: 本机 11 核实测会让几个依赖时序/共享状态的用例偶发失败(-n 4 连跑两遍全绿)。

先读哪份文档

本仓把同一个「事实」按边界拆成三份,读之前先记住这个分工(设计规范 §0.1):

文档 只回答 不回答
设计规范 应该是什么:接口 / 不变量 / 状态机 / schema / 验收标准 现在做到了哪一步
实现状态 现在是什么、被哪条守卫守着、边界在哪 应该是什么
研究日志 与研究索引 为什么这么改、哪次实验推翻了什么 当前口径(历史结论可被推翻)

除此之外:

磁盘上什么在仓里、什么不在

工作树约 1.0 GB,其中 905 MB 是 triton/ 本地检出;1.0 GB 的审计证据(各批次冻结计划、 候选、判定回执、GPU 快照)不在仓内,仓里只有 output → ~/op-agent-evidence/output 的符号链接。为什么这样:那些证据既不可 diff,也不该被 git status/rg/find 每次扫过, 而 .gitignore 让任何提交都不会提醒它正在膨胀。位置、重建方式与注意事项见 docs/research/evidence-location.json; 布局由 tests/hygiene/test_repo_layout.py 守住(根目录白名单、 平铺目录条目预算、缓存与产物禁止入库、证据目录只能是链接)。

代码怎么读

规范 §1–§19 的编号是稳定契约:代码注释按号引用它(想复算: grep -rho '设计 §[0-9]' operator_agent/*.py | wc -l,本轮 111 处)。所以读任何模块的第一步, 是读它 docstring 顶部的 §号,翻到规范那一节,再回来看代码。

逻辑依赖顺序是 先可信 → 再可搜 → 最后可生成。推荐这条路线:

包里按层分五个子包(2026-10-31 起;operator_agent/ 根目录只剩 __init__.py, 公开再导出不变 —— from operator_agent import Conductor 照旧):

  1. core/ —— 词汇与产物:schemas.py(TaskSchema / SourceSpec / TargetSpec / ConstraintSpec)、contract.py、run_contract.py、 artifact_store.py、kernel_db.py
  2. decide/ —— 判定:verifier.py → measurement.py → eligibility.py, 以及 correctness*、anticheat、reference*、resource_check
  3. execute/ —— 执行:remote_executor.py、 exec_guard.py、task_budget/cancellation/clock、 remote_scripts/run_kernel.py
  4. generate/ —— 生成与修复:agents.py → coder_pipeline.py → fixer.py / repair_* → prompts/ + skills/triton_skill.md
  5. app/ —— 入口与编排:conductor.py(Router 与主循环 _execute_inner()。别顺序读,3000+ 行,用实现状态 §五 的表跳读)、cli.py、 mcp_server.py、hitl_tools.py、autonomous.py

依赖方向是单向的:app → generate → decide → execute → core(由 tests/hygiene/test_repo_layout.py 与各层 docstring 守着)。

目录结构

operatorAgent/
├── operator_agent/          # 核心包(按层分组,根目录只有 __init__.py)
│   ├── core/                # 词汇/契约/产物:schemas contract run_contract artifact_store kernel_db …
│   ├── decide/              # 判定:verifier measurement eligibility correctness* anticheat reference* …
│   ├── execute/             # 执行:remote_executor exec_guard task_budget task_clock mock_gpu …
│   ├── generate/            # 生成与修复:agents coder_pipeline fixer repair_* prompt_manager …
│   ├── app/                 # 入口与编排:conductor cli mcp_server hitl_tools autonomous
│   ├── ops/  prompts/  skills/   # 资源与内嵌子包
│   └── __main__.py          # `python -m operator_agent` 的委托入口
├── remote_scripts/          # 远端执行载荷(run_kernel.py)
├── tests/                   # 按用途分三层(见下)
│   ├── conftest.py  fixtures/  golden_regression.py  # 共享夹具与 golden harness
│   ├── unit/                # 208 个单模块/单机制用例
│   ├── acceptance/          # 50 个批次验收(S4/S5/S6 协议、网关、隔离)
│   └── hygiene/             # 仓库守卫:打包、凭据扫描、布局预算、契约冻结
├── benchmarks/              # 按用途分目录(见下)
│   ├── probes/  verify/  calibration/  measurement/  demos/
│   ├── drivers/             # 真机驱动(*_h20、test_nvidia 同族)
│   └── experiments/s4 s5 misc/   # 批次实验与服务
│   └── _scratch.py _remote_bench.py …   # 多个驱动共用的私有辅助
├── test_nvidia_*.py         # 真机端到端 driver:唯一的 LLM 全流程入口
├── docs/                    # design / status / research / user_guide
├── output -> ~/op-agent-evidence/output   # 审计证据的**符号链接**,!不! 在仓内
├── logs/                    # 运行期日志(gitignored)
└── triton/                  # 本地 vendored 检出(gitignored)

配置

config.yaml 不是生效配置 —— 全仓没有 import yaml,它零消费者。真正生效的是三处: SSHExecutor.__init__ 的默认值、driver 里的 build_llm() / ssh_config()、以及环境变量。 config.example.yaml 保留为这些默认值的可读索引(改环境时请三处同步)。

常用环境变量(全表见 user_guide §4.2):

变量 作用
LLM_API_KEY / LLM_BASE_URL / LLM_MODEL LLM 端点与凭据
REMOTE_SSH_HOST / _PORT / _USER / _KEY 真机连接(推荐用 ~/.ssh/config 别名)
OPERATOR_AGENT_OUTPUT_DIR / OPERATOR_AGENT_LOG_DIR 产物与日志落点(跑测试时指到仓库外)
OPERATOR_AGENT_KERNEL_DB / OPERATOR_AGENT_FAILURE_DB 经验库路径;取 off 则关闭持久化

仓库纪律(改代码前请读)

  • 凭据不进仓:真实主机名 / IP / 用户名 / 密钥路径一律走 ~/.ssh/config 与环境变量。 tests/hygiene/test_repo_hygiene.py 会机械扫描所有已跟踪文件里的凭据形态 (含家目录绝对路径与真实端口),命中即红。
  • config.yaml 不进仓:它含真实值,已被 .gitignore 忽略;模板是 config.example.yaml。
  • 根目录的 _*.py 是临时脚本:由 .gitignore 的 /_*.py 忽略,不要 git add -f (历史上含过旧凭据)。
  • 跑测试不要污染仓库:Conductor 无条件落盘,见 tests/conftest.py 如何把 output/ 与 logs/ 重定向到 tmp。
  • 改实现要留守卫:本仓的验收标准是「一条能变红的守卫」,而不是一句描述 —— 规范章节 → 守卫的对应关系见实现状态 §五。

回归与真机

python tests/golden_regression.py compare   # exit 0 无回归 / 1 有回归 / 2 期望过期需人签认
python3 benchmarks/demos/demo_spine_local.py      # 零依赖:看脊柱判定(会写 output/,见上文 ⚠️)
python3 benchmarks/demos/smoke_spine_h20.py       # 真机版(要 GPU + ~/.ssh/config 别名)

Golden 的 CPU 对照保留真实计时:matmul 比较 GFLOPS,零 GFLOPS 的内存算子比较平均延迟。 compare 默认将 mock 产物/日志写到临时目录并关闭经验库持久化,不污染真实运行现场; 旧失败基线或缺失的延迟仍返回 REVIEW(exit 2),不会自动刷新 registry 或放宽门槛。

版本与依赖

  • Python >= 3.9
  • 没有 requirements.txt:numpy 必需;torch / triton 真机执行才需要; LLM 客户端只用标准库 urllib(零依赖)

License

Apache-2.0,见 LICENSE。版权:Copyright 2026 the operator-agent authors(见 NOTICE)。 第三方组件(ECharts / Mermaid)保留各自许可,见 THIRD_PARTY_NOTICES.md。

Metadata

Release files for dsh-operator-agent 0.7.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dsh-operator-agent 0.7.2
File Size Uploaded Provenance Actions
dsh_operator_agent-0.7.2.tar.gz 930.6 kB Without provenance Details for dsh_operator_agent-0.7.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dsh-operator-agent 0.7.2
File Interpreter ABI Platform Actions
dsh_operator_agent-0.7.2-py3-none-any.whl Python 3 none any Details for dsh_operator_agent-0.7.2-py3-none-any.whl

Total release size: 1.9 MB

Release files / dsh_operator_agent-0.7.2.tar.gz

Download URL dsh_operator_agent-0.7.2.tar.gz
Size 930.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d16968e7a4bfecd47ffb66c34ad0c60d41d34fb38dde484be51f4db39ded9168
BLAKE2b-256 checksum
How to use checksums
9063191c4e3409b25ee1f5609a7853031953935d1ce149289361ffe56a84da04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / dsh_operator_agent-0.7.2-py3-none-any.whl

Download URL dsh_operator_agent-0.7.2-py3-none-any.whl
Size 1.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
2d24617ac6890dc89137f6bbe75ecf14ab8276b2dc1edb07c2f1545d78412688
BLAKE2b-256 checksum
How to use checksums
a72706401178de6ef5804dd352a88f864ed13651b37e578089e2fb51c2453e7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for dsh-operator-agent 0.7.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.7.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page