Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions main_harness/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.DS_Store
.env
.env.*
!.env.example
.venv/
__pycache__/
.pytest_cache/
*.py[cod]
*.pem
*.key
*.p12
*.pfx
tmp/
Data/
backup/
run_records/
harness_ablation_runs/
result/
results/
outputs/
dist/
build/
*.egg-info/
71 changes: 71 additions & 0 deletions main_harness/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# main_harness

PawBench 的 Harness attribution 与 Feature ablation 模块。此目录只包含源码和测试,不包含 task data、API key 或运行记录。

## 工作流

```text
PawBench result + trajectory
-> Reasoning backend 输出 H/M/Ex code 与 evidence
-> bridge 校验 H-code 并映射 F-code
-> 生成一个 accepted H-to-F Feature development request
-> Qwen3.8-Max through Claude Code 按 skill 实现并写 admission receipt
-> 独立校验 receipt 后才允许打开一个 Feature
-> paired ablation 与 holdout result 回传 PawBench
```

- `M-code`:模型可观察行为,不映射 Feature。
- `Ex-code`:task、scorer 或外部服务问题,不自动映射 Feature。
- `H-code`:Harness 机制问题,可根据 evidence 选择 0-2 个 F-code 做 ablation。

## 主要代码

| 路径 | 作用 |
| --- | --- |
| `scripts/feature_taxonomy.py` | H/M/Ex 定义、15 个 Feature 与 H-to-F mapping。 |
| `scripts/pawbench_output_adapter.py` | 将 PawBench output 转成 attribution input。 |
| `scripts/bridge_attribution_to_harness_core.py` | 校验 H-code,生成 Feature switch 建议。 |
| `candidates/agentscope/` | 默认 AgentScope Harness 及受治理的 Qwen3.8-Max Feature 开发桥接。 |
| `tests/` | taxonomy、adapter、bridge、report 与 security 测试。 |

## PawBench 接入

Reasoning backend 需为每个 task 提供:

```json
{
"task_id": "example-task",
"codes": ["H2"],
"evidence": "direct trajectory evidence"
}
```

Bridge 输出 `recommended_feature_ids` 与 `recommended_switch_keys`。在 Feature
未启用时,先用 `agentscope-develop-feature prepare` 固化一个 accepted H-to-F
request,再由 Qwen3.8-Max through Claude Code 在本地 skill 约束下实现。只有
`FEATURE_ADMISSION_RECEIPT.json` 独立通过全部 gate,调用方才可以打开一个
Feature 并复跑。所有归因必须基于 trajectory evidence,不能由 score 直接推断。

## 安全边界

- API key 只从环境变量读取,不写入源码。
- provider key 与 base URL 按同一 namespace 绑定,避免 key 发往错误 endpoint。
- `Data/`、`tmp/`、cache、run records 和 ablation outputs 不进入代码提交。
- API-backed run 可能把 prompt、model output 和 response ID 写入本地记录;共享前必须再次脱敏。

## 测试

在本目录执行:

```bash
python -m pytest -q
python scripts/run_feature_contracts.py --candidate agentscope --pretty
python -m pytest candidates/agentscope/tests/test_feature_development.py -q
python candidates/agentscope/scripts/v2_ablation_matrix.py
```

API-backed run 由 `DASHSCOPE_API_KEY`、`OPENAI_API_KEY`,或成对的 `LLM_API_KEY` + `LLM_BASE_URL` 配置。Qwen3.8-Max 的 Claude Code route 使用 `DASHSCOPE_API_KEY` 加 `DASHSCOPE_ANTHROPIC_BASE_URL`,或从 `DASHSCOPE_BASE_URL` 推导;不要把 key 写入参数、URL、receipt 或文件。

## TODO

当前 H-code 与 Feature mapping 是 hard-coded 的统一 taxonomy。下一步按 PawBench task category 分别设计 Feature,并用真实 trajectory 做 task-specific ablation 验证。
12 changes: 12 additions & 0 deletions main_harness/candidates/agentscope/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.venv/
.env
.env.*
!.env.example
__pycache__/
.pytest_cache/
*.pyc
tmp/
dist/
build/
*.egg-info/
.DS_Store
62 changes: 62 additions & 0 deletions main_harness/candidates/agentscope/FEATURE_CHANGE_STANDARD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# AgentScope Feature Change Standard

This is the normative procedure for adding, strengthening, disabling, or
removing an AgentScope Feature. A Feature is admitted only when its OFF path,
runtime seams, evidence, and release gates are all explicit.

## Boundary

A Feature is a harness-owned, independently switchable intervention around one
fixed AgentScope model and tool loop. It may change workspace policy, tool
contract, runtime policy, observability, or context and memory at its declared
seam. It must not change model identity or sampling, benchmark task or split,
Harbor authority, external verifier, accepted attribution evidence, or an
unrelated Feature.

## Required contract

Before editing, bind the request to:

- stable Feature ID, English and Chinese names, and one H1-H5 owner;
- causal mechanism, spatial dependencies, writes, conflicts, and OFF behavior;
- apply, trace, cleanup, cancellation, retry, and resume phases;
- a Feature-independent observable and Feature-owned trace event;
- safety floors that remain when the Feature is OFF;
- compatibility for config, state, trace, artifacts, CLI, and package;
- a frozen paired experiment and holdout gate;
- retirement/rollback behavior.

Active display names must not use `/` to join concepts. Historical aliases may
remain only as explicit compatibility provenance.

## Admission workflow

1. The attribution bridge accepts an optimization-arm H-to-F decision.
2. `agentscope-develop-feature prepare` persists a request and a compiled
repository-skill receipt.
3. `agentscope-develop-feature run --execute` invokes only Qwen3.8-Max through
Claude Code with strict empty MCP configuration and the local skill.
4. The coding agent implements and tests OFF before ON, then writes the exact
`FEATURE_ADMISSION_RECEIPT.json`.
5. `agentscope-develop-feature verify` independently validates the request and
receipt. Only then may the caller activate the nominated Feature.

## Mandatory gates

The receipt must contain exactly these passing gates:

`boundary`, `off_equivalence`, `spatial_contract`, `temporal_contract`,
`safety`, `causal_pair`, `holdout`, `compatibility`, and `benchmark_matrix`.

For every claimed benchmark, retain a one-Feature paired row for all 15
Features. A blocked or mechanism-not-observed row is not a causal pass, and an
absent row blocks a support claim. Published runs and frozen inputs are never
rewritten to make an admission pass.

## Removal symmetry

Removal uses the same Feature identity, seams, OFF/absence behavior, frozen
comparison, trace, safety, holdout, compatibility, package, and matrix gates.
Deleting a call site alone is not removal: registrations, consumers, state,
configuration, tests, documentation, package exports, and old artifact readers
must remain valid.
87 changes: 87 additions & 0 deletions main_harness/candidates/agentscope/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# PawBench AgentScope Harness

默认的 Harness backend。AgentScope 提供 agent、model adapter、tool 与 ReAct
loop;PawBench Core 提供 Feature switch、workspace isolation、trace
normalization 与 verification。`agentscope-develop-feature` 是受治理的开发
桥接:它不会自行打开 Feature,也不会改写 attribution 结论。

## Feature mapping

| H-code | Feature |
| --- | --- |
| H1 Environment and Workspace | F1.1 Workspace Binding, F1.2 Readiness and Reset, F1.3 Isolation and Permissions |
| H2 Tool Contract | F2.1 Action Contract, F2.2 Tool Availability, F2.3 Result and Error Feedback |
| H3 Runtime and Loop | F3.1 Completion and Termination, F3.2 Budget and Guards, F3.3 Recovery and Resume |
| H4 Observability and Acceptance | F4.1 Diagnostic Trace, F4.2 State and Artifact Deltas, F4.3 Verification |
| H5 Context and Memory | F5.1 Context Assembly, F5.2 Persistent Memory, F5.3 Compaction |

`Ex-3` 是外部 provider 或 hosted service 故障,不自动映射 F-code。只有
Harness 对故障的处理也有直接 evidence 时,才额外归因 H/F。

## 受治理的 Feature 开发

默认 coding agent 是 **Qwen3.8-Max through Claude Code**。它只接收一个已
接受的 optimization-arm H-to-F request,并使用仓库内的
`implement-attributed-feature` skill。执行顺序固定为:

```text
attribution bridge
-> accepted H-to-F request
-> prepare skill receipt
-> Qwen3.8-Max through Claude Code
-> independent admission receipt validation
-> caller activates exactly one admitted Feature
-> paired benchmark and holdout evaluation
```

`run --execute` 才允许 Claude Code 改写本地 workspace。子进程只获得
DashScope gateway 所需的凭据;GitHub、Alibaba 与其他主机 token 不会继承,
且不会写入 receipt。需要配置:

```bash
export DASHSCOPE_API_KEY='...'
export DASHSCOPE_ANTHROPIC_BASE_URL='https://.../apps/anthropic'
# 或使用 DASHSCOPE_BASE_URL=https://.../compatible-mode/v1 自动推导
```

从 `main_harness/` 运行。`prepare`、`run` 与 `verify` 总是通过
`--workspace-root` 读取 PawBench checkout 内的 canonical manifest 和 local
skill;evidence 必须来自 optimization arm,任何含 `holdout` 的路径都会被拒绝。
已安装的 command 可以在 checkout 外显示 `--help`,但不能脱离 checkout 执行开发。

```bash
python -m pip install -e candidates/agentscope

agentscope-develop-feature prepare \
--workspace-root .. \
--output-dir main_harness/candidates/agentscope/tmp/feature_development/round_01 \
--h-code H2 --feature-id F2.2 \
--selection-reason 'accepted three-peer attribution evidence' \
--evidence main_harness/candidates/agentscope/tmp/round_01/ATTRIBUTION_SUMMARY.json

agentscope-develop-feature run --workspace-root .. --execute \
--request main_harness/candidates/agentscope/tmp/feature_development/round_01/FEATURE_DEVELOPMENT_REQUEST.json

agentscope-develop-feature verify --workspace-root .. \
--request main_harness/candidates/agentscope/tmp/feature_development/round_01/FEATURE_DEVELOPMENT_REQUEST.json
```

`FEATURE_CHANGE_STANDARD.md`、`feature_manifest.json` 与
`feature_value_contract.json` 是实现和验收的共同约束。receipt 必须使
boundary、OFF equivalence、spatial、temporal、safety、causal pair、holdout、
compatibility 和 benchmark matrix 九个 gate 全部通过。

## 本地测试

在 `main_harness/` 执行:

```bash
python -m pytest candidates/agentscope/tests -q
python candidates/agentscope/scripts/local_demo.py
python candidates/agentscope/scripts/feature_impact_smoke.py --iterations 10
python candidates/agentscope/scripts/v2_ablation_matrix.py
```

API-backed ablation 脚本保持原有 DashScope-compatible endpoint 配置。每次
run 创建新的 workspace 与 trace;`--resume` 仅用于明确支持续跑的脚本。
运行产物、request、receipt 和 token 都不得提交。
Loading