# 分数实现与验收判定公式 **对象**: `swarm-minimal` 最小蜂群原型 **日期**: 2026-05-17 **范围**: 任务分数、输出质量分、信息素分数、候选融合分数、多轮共识分数、L01 本机压力、L02 3000 TPM、S07/S09/S10 验收判定 ## 1. 分数层级 当前项目里的“分数”不是单一模型自评,而是多层规则共同作用: | 层级 | 分数名 | 用途 | | --- | --- | --- | | L1 | 输出质量原始分 `Q` | 判断单个模型 / Agnet 输出是否满足质量门 | | L2 | 任务分 `task.score` | 写入 task pool,作为基础收敛候选分 | | L3 | 信息素分 `P_t` | 影响后续任务 claim 顺序,并作为正负反馈记录 | | L4 | 候选融合分 `F` | 多个有效候选融合后形成的综合分 | | L5 | 共识候选分 `S_j` | 多个审查 Agnet 多轮投票后的候选分 | | L6 | 验收布尔判定 `PASS` | 判断整个场景是否满足标准矩阵 | 因此,最终不是“一个高分就通过”,而是“质量门、分数门、状态证据、artifact 证据、共识门同时通过”。 所有指标的设计场景和成功阈值统一见 `AGENT_SWARM_INDICATOR_TEST_MATRIX.zh-CN.md`。本文件只解释“分数如何算”和“公式如何判定”,不再用自然语言替代阈值。 ## 1.1 指标成功值速查 | 指标组 | 成功值 | | --- | --- | | 输出质量 | `Q >= 0.72` 且 critical checks 全通过 | | 风险输出 | 拒答、角色边界、偏题或质量失败时 `task.score = 0.12` | | 最终 STEP-07 | 质量通过后 `task.score = 1.0` | | S07 live 收敛 | 7 个任务完成、14 项 checks 全 PASS、`accepted_score >= 0.75`、共识 `round_count >= 2` | | S09 候选融合 | `min_score = 0.5`,低分噪声必须被过滤 | | S09/S07 共识 | S07 `threshold=0.7,min_margin=0.25`;S09 `threshold=0.7,min_margin=0.2` | | S10 六特征 | F01-F06 全部为 true | | L01 本机压力 | 128 Agent、131072 任务,失败 `0`,重复 claim `0` | | L02 3000 TPM | 单分钟 token `<=3000`,总预留 token `=3000`,预算利用率 `1.0` | | 蜂群性数值 | `swarmness_score >= 75` 才能说最小蜂群成立;当前为 `100` | ## 2. 输出质量原始分 每个质量检查项记为: ```text c_i ∈ {0, 1} ``` 其中: - `c_i = 1` 表示第 `i` 个质量检查通过。 - `c_i = 0` 表示第 `i` 个质量检查失败。 - `N` 表示当前步骤需要检查的质量项总数。 输出质量原始分: ```text Q = (Σ c_i) / N ``` 质量门通过条件: ```text quality_pass = Q >= 0.72 ∧ critical_checks_all_passed ``` S07 外部 GitHub 代码场景中的关键检查项包括: - 当前 STEP 标记存在。 - 前一步 STEP 标记存在。 - 外部仓库 `fastapi/fastapi` 存在。 - 固定 commit 存在。 - 输出没有漂移到当前仓库。 - 没有拒答、角色拒绝、偏题或质量失败标记。 - 包含 FastAPI 代码语义。 ## 3. 任务分公式 设: - `Q` 为输出质量原始分。 - `i` 为步骤序号,从 0 开始。 - `R(content)` 表示输出包含拒答、角色拒绝、偏题或质量失败风险。 - `final_step` 表示当前步骤是最终 STEP-07。 如果存在质量风险: ```text task.score = 0.12 ``` 如果没有质量风险,但没有通过质量门: ```text task.score = max(0.05, 0.3 + 0.35Q) ``` 如果通过质量门,且当前是最终 STEP-07: ```text task.score = 1.0 ``` 如果通过质量门,但不是最终步骤: ```text task.score = min(0.98, 0.62 + 0.28Q + 0.01i) ``` 解释: - `0.12` 是风险输出惩罚分,用于强制拒答、角色拒绝、偏题输出无法进入正常收敛。 - `0.3 + 0.35Q` 让未通过质量门的输出保留可审计分数,但不会轻易成为最终结果。 - `0.98` 是中间步骤上限,避免中间步骤压过最终验收步骤。 - 最终 STEP-07 通过质量门后给 `1.0`,表示它满足当前最小验收规则的最终收敛路径。 ## 4. 信息素分数公式 每个 task 有一个信息素分: ```text P_t ``` 任务创建时: ```text P_t = 0 ``` 任务成功完成时: ```text P_t ← P_t + task.score ``` 任务失败时: ```text P_t ← P_t - 1.0 ``` 任务 claim 时,在能力匹配且状态为 `pending` 的任务集合中选择: ```text claim_task = argmax(P_t) ``` 这表示信息素不是只用来展示分数,它会反过来影响后续 Agnet 领取任务的顺序。 ## 5. 基础收敛公式 基础收敛只在完成任务集合中选择最高任务分: ```text T_done = {t | status(t) = done} ``` ```text winner = argmax_{t ∈ T_done}(task.score_t) ``` 最终结果: ```text accepted_output = winner.output accepted_score = winner.score accepted_task_id = winner.id ``` 注意:S07 live 外部代码场景不是只靠这个最高分直接放行。它在基础收敛前后增加了质量门、fallback、多轮质量共识、PostgreSQL/Redis/Blob 证据检查。 ## 6. 候选融合分数公式 候选集合: ```text C = {c_1, c_2, ..., c_m} ``` 先过滤低分和空文本候选: ```text U = {c_i | score_i >= min_score ∧ text_i 非空} ``` 按分数降序排列后,对文本逐行去重合并。融合分数采用分数自加权平均: ```text F = (Σ score_i^2) / (Σ score_i), c_i ∈ U ``` 来源证据: ```text sources = ordered(candidate.id) ``` 解释: - `score_i^2` 让高分候选权重更大。 - 低分噪声会被 `min_score` 过滤。 - 多个高分候选的有效结论会被保留,而不是只选一个最高分文本。 ## 7. 多轮共识分数公式 每个候选 `j` 有共识分: ```text S_j ``` 每一轮开始先做分数蒸发: ```text S_j ← evaporation × S_j ``` 每个审查 Agnet 投票后,候选分累加: ```text S_candidate ← S_candidate + max(0, confidence_a) × weight_a ``` 其中: - `confidence_a` 是第 `a` 个 Agnet 对候选的置信度。 - `weight_a` 是该 Agnet 的角色权重。 领先候选: ```text leader = argmax_j(S_j) ``` 领先占比: ```text leader_share = S_leader / Σ max(0, S_j) ``` 领先差距: ```text margin = S_leader - S_second ``` 共识收敛条件: ```text consensus_converged = leader_share >= threshold ∧ margin >= min_margin ``` S07 质量共识参数: ```text threshold = 0.7 min_margin = 0.25 evaporation = 0.82 ``` S09 互相质询共识参数: ```text threshold = 0.7 min_margin = 0.2 evaporation = 0.85 ``` ## 8. S07 live 外部代码场景通过公式 S07 不是只看 `accepted_score`。可简化为: ```text S07_PASS = three_distinct_models_from_discovery ∧ seven_chain_steps_all_done_in_pg ∧ step_markers_and_previous_links ∧ all_outputs_pass_quality_gate ∧ shared_state_chain_cursor_and_summaries ∧ pheromone_scores_pg_and_redis ∧ shared_state_converged ∧ convergence_pg_and_blob ∧ redis_stream_event_volume ∧ contains_external_fastapi_code_review_material ∧ multi_round_quality_consensus_accepts_chain ∧ final_output_references_external_files ∧ keeps_model_discovery_not_fixed_model ∧ external_github_target_not_local_project ``` 其中分数相关的关键门为: ```text all_outputs_pass_quality_gate = ∀ step, quality_pass_step = true ``` ```text pheromone_scores_pg_and_redis = ∀ task, P_task_pg > 0 ∧ P_task_redis > 0 ``` ```text convergence_pg_and_blob = convergence_exists ∧ completed_tasks = 7 ∧ accepted_score >= 0.75 ∧ blob_artifact_exists ``` ```text multi_round_quality_consensus_accepts_chain = consensus_converged ∧ accepted_candidate = accept_external_chain ∧ round_count >= 2 ``` ## 9. S09 下一阶段边界通过公式 S09 由三项检查组成: ```text S09_PASS = scaled_autonomous_claim_pass ∧ candidate_fusion_pass ∧ questioning_consensus_pass ``` 3/5/7 并发 claim 通过条件: ```text scaled_autonomous_claim_pass = ∀ n ∈ {3, 5, 7}, converged_n ∧ completed_tasks_n = 2n ∧ failed_tasks_n = 0 ∧ duplicate_claims_n = ∅ ∧ participating_agents_n = n ∧ all_tasks_done_n ``` 候选融合通过条件: ```text candidate_fusion_pass = source_candidate_ids = ("quality", "coverage") ∧ expected_terms ⊆ fused.text ∧ low_score_noise ∉ fused.text ``` 互相质询共识通过条件: ```text questioning_consensus_pass = converged ∧ accepted_candidate = approve_fused_candidate ∧ round_count >= 2 ∧ first_round_converged = false ∧ last_round_converged = true ∧ every_round_has_challenges ∧ every_round_has_revisions ``` ## 10. S10 蜂群六特征通过公式 S10 把蜂群判定收敛为六个一级指标: ```text S10_PASS = decentralization_pass ∧ self_organization_pass ∧ emergence_pass ∧ robustness_pass ∧ scalability_pass ∧ implicit_collaboration_pass ``` 去中心化: ```text decentralization_pass = participating_agents >= 4 ∧ duplicate_claims = ∅ ∧ control_keys = ∅ ∧ decision_records = task_count ``` 自组织: ```text self_organization_pass = no_preseeded_global_plan ∧ local_interaction_count >= 5 ∧ dominant_cluster = argmax(cluster_score) ``` 涌现性: ```text emergence_pass = global_score(candidate_group) > max(local_signal_i) ∧ accepted_candidate = argmax(global_score) ``` 鲁棒性: ```text robustness_pass = failed_tasks >= 1 ∧ completed_tasks >= 2 ∧ negative_observation_exists ∧ run_status = converged ``` 可扩展性: ```text scalability_pass = ∀ n ∈ {3, 5, 7}, completed_tasks_n = 2n ∧ failed_tasks_n = 0 ∧ duplicate_claims_n = ∅ ∧ participating_agents_n = n ``` 隐式协作: ```text implicit_collaboration_pass = direct_message_keys = ∅ ∧ environment_trail_exists ∧ first_claim = argmax(initial_pheromone) ∧ final_pheromone_high > final_pheromone_medium ``` ## 11. L01 / L02 本机规模和模型预算公式 L01 本机最大性能压力通过条件: ```text L01_PASS = worker_processes = logical_cpus ∧ completed_tasks = total_tasks ∧ failed_tasks = 0 ∧ duplicate_claims = ∅ ∧ participating_agents = total_agents ∧ converged_shards = worker_processes ``` L02 3000 TPM 预算通过条件: ```text tokens_by_minute_m = 第 m 个模拟分钟窗口内预留 token 总量 ``` ```text L02_PASS = target_tpm = 3000 ∧ max_m(tokens_by_minute_m) <= 3000 ∧ total_reserved_tokens = task_count × tokens_per_task = 3000 ∧ budget_utilization = total_reserved_tokens / (simulated_minutes × target_tpm) = 1.0 ∧ completed_tasks = task_count ∧ failed_tasks = 0 ∧ duplicate_claims = ∅ ∧ participating_agents = agent_count ∧ converged = true ``` 解释: - L01 验证本机并发 claim / 执行 / 收敛在大任务量下不崩。 - L02 验证模型预算调度不会因为多 Agent 并发而冲破 3000 TPM;调度思想参考 token bucket / rate policing,项目中实现为离散分钟窗口 ledger。 - L02 使用本地虚拟 ledger,不调用真实模型供应商;真实 live 限流仍需要 NewAPI 网关的请求 token、返回 token、429 和费用归因证据。 L02 参数换算: ```text target_tpm = 3000 tokens_per_task = 50 task_count = target_tpm / tokens_per_task = 60 total_token_demand = task_count × tokens_per_task = 3000 simulated_minutes = ceil(total_token_demand / target_tpm) = 1 budget_utilization = total_reserved_tokens / (simulated_minutes × target_tpm) = 1.0 ``` ## 12. 蜂群性数值评分公式 核心蜂群性只看 F01-F06: ```text swarmness_score = 100 × (10F01 + 10F02 + 10F03 + 10F04 + 10F05 + 10F06) / 60 ``` 其中: ```text F_i ∈ {0, 1} ``` 最小合规评分: ```text minimal_compliance_score = 10F01 + 10F02 + 10F03 + 10F04 + 10F05 + 10F06 + 10S07 + 5S08 + 10S09 + 7L01 + 8L02 ``` 总权重: ```text 60 + 25 + 15 = 100 ``` 当前实测代入: ```text F01=F02=F03=F04=F05=F06=1 S07=S08=S09=L01=L02=1 swarmness_score = 100 minimal_compliance_score = 100 ``` 分数等级: ```text score < 60 -> 不满足蜂群 60 <= score < 75 -> 部分蜂群,不可验收 75 <= score < 85 -> 最小可验收蜂群 85 <= score < 95 -> 合规蜂群原型 score >= 95 -> 极强本地最小蜂群合规 ``` 硬上限: ```text if any(F01..F06) = 0: minimal_compliance_score <= 59 ``` ```text if any(S07,S08,S09) = 0: minimal_compliance_score <= 84 ``` ```text if any(L01,L02) = 0: minimal_compliance_score <= 94 ``` 这意味着核心蜂群特征失败时,不能通过补跑文档、单测或压力测试把总分刷到合格。 ## 13. 总体验收公式 当前仓库最小闭环验收可以概括为: ```text MINIMAL_CLOSED_LOOP_PASS = A01_static_compile ∧ A02_unit_and_deterministic_scenarios ∧ A03_swarm_behavior_acceptance ∧ A04_swarm_vs_traditional_benchmark ∧ A05_consensus_convergence_acceptance ∧ A06_next_boundary_minimal_acceptance ∧ A07_swarm_six_characteristics_acceptance ∧ S07_live_external_github_code_reasoning ∧ S08_model_io_report_audit ∧ S09_next_boundary_minimal_acceptance ∧ S10_swarm_six_characteristics_acceptance ``` 若声明“本机压力与 3000 TPM 量级也通过”,还需要: ```text LOCAL_SCALE_AND_BUDGET_PASS = MINIMAL_CLOSED_LOOP_PASS ∧ L01_PASS ∧ L02_PASS ``` 最终解释: ```text score 高 ≠ 自动 PASS ``` 真正判定是: ```text 质量门 + 分数门 + 信息素证据 + 状态证据 + artifact 证据 + 多轮共识门 全部通过 = PASS ``` ## 14. 公式对应实现位置 | 公式 / 机制 | 实现位置 | | --- | --- | | 输出质量原始分 `Q` | `examples/run_continuous_reasoning_acceptance.py::assess_output_quality` | | 任务分 `task.score` | `examples/run_continuous_reasoning_acceptance.py::score_output` | | 信息素更新 `P_t` | `swarm_minimal/core.py::complete_task` / `fail_task` | | 基础最高分收敛 | `swarm_minimal/core.py::converge` | | 候选融合分 `F` | `swarm_minimal/core.py::fuse_candidate_outputs` | | 多轮共识分 `S_j` | `swarm_minimal/core.py::ConsensusSwarm.run` | | 互相质询共识 | `swarm_minimal/core.py::QuestioningConsensusSwarm.run` | | S07 标准矩阵检查 | `examples/run_continuous_reasoning_acceptance.py::collect_report` | | S09 下一阶段边界检查 | `examples/run_next_boundary_acceptance.py` | | S10 蜂群六特征检查 | `examples/run_swarm_characteristics_acceptance.py` | | L01 本机最大性能压力 | `examples/run_large_scale_stress_acceptance.py` | | L02 3000 TPM 预算调度 | `examples/run_tpm_budget_acceptance.py` | | 蜂群性数值评分 | `swarm_minimal/acceptance_scoring.py` / `examples/run_swarm_compliance_score.py` |