AI接入规范

A set of project rules for calling AI models, selecting fallback models, managing configuration, storing prompts, and parsing AI responses. It requires modules to use a shared AI service rather than calling provider APIs directly.

In plain words
What is it for?
Use it when adding or reviewing AI features, registering prompts, choosing fallback models, recording call logs, retrieving shared configuration, or parsing JSON responses.
Why use it?
It prevents separate modules from using inconsistent model settings, hard-coded keys, duplicated response parsing, or untracked AI calls.

Cursor rule

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.

agentmods
npx agentmods add rules/nongjun/awesome-harness-engineering/ai
Clone the repo
git clone --depth 1 https://github.com/nongjun/awesome-harness-engineering
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 606 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00000 $0.00606
Opus 5 $0.00000 $0.00303
Sonnet 5 $0.00000 $0.00121
Haiku 4.5 $0.00000 $0.00061

Measured 2d ago against content hash be13251ce5a8, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

AI接入规范 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 2d 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.

项目模板/瑞小美AiOS/rules/AI接入规范.mdc · 67 lines

What it actually says

瑞小美 AI 接入规范

核心原则

原则 要求
优先最强 默认使用 Claude Opus 4.5,失败后自动降级
智能降级 Claude → Gemini Pro → Gemini Flash(每级重试 2 次)
统一配置 从门户系统统一获取 Key,各模块禁止独立配置
统一服务 通过 shared_backend.AIService 调用,禁止直接请求 API

服务商降级策略

4sapi.com (首选): Claude → Gemini Pro → Gemini Flash
    ↓ 全部失败
OpenRouter (备选): Gemini Pro → Gemini Flash

降级触发:首字超时 10 秒、请求失败、每模型最多 2 次重试。

模型配置

等级 模型 说明
首选 claude-opus-4-5-20251101-thinking 所有任务首先尝试
标准 gemini-3-pro-preview Claude 失败后降级
快速 gemini-3-flash-preview 最终保底
生图 gemini-2.5-flash-image-preview 图像生成专用
视频 veo3.1-pro 视频生成专用

强制要求

  • 使用 shared_backend.services.ai_service.AIService,禁止直接调 API
  • 禁止硬编码 API Key
  • 初始化时必须传入 db_session(记录调用日志)
  • 调用时必须传入 prompt_name(用于统计)

提示词规范

  • 文件位置:{模块}/后端服务/prompts/{功能名}_prompts.py
  • 必须包含 PROMPT_META(name、display_name、module、variables)
  • 模块启动时通过 scan_and_register_prompts 自动注册到数据库

AI 响应解析

必须使用公共函数:parse_ai_json_responsesafe_parse_ai_json,禁止自行编写解析逻辑。

配置入口

  • 门户系统 AI 配置页面管理 Key 和模型
  • 各模块通过 GET /api/ai/internal/config 获取配置(5 分钟缓存)
  • 调用统计:门户系统 → AI 配置 → 调用统计
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. 2d ago First seen · 67 lines · 0 tokens per session scan A be13251ce5a8

Subscribe to this mod's changes

AI接入规范 is a cursor rule published in the GitHub repository nongjun/awesome-harness-engineering (2 stars, last pushed 5mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 606 tokens. 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-08-31.