eval: add command and browser parity evidence

This commit is contained in:
jxxghp
2026-09-11 11:16:20 +08:00
parent 5e50caabcb
commit 3cfbf9dbcf
12 changed files with 581 additions and 46 deletions

View File

@@ -109,6 +109,7 @@ class EvaluationWorld:
self._initial: dict[str, Any] = {}
self._ledger: list[dict[str, Any]] = []
self._unknown_returned = False
self._browser_url = ""
self.reset()
@property
@@ -127,6 +128,62 @@ class EvaluationWorld:
with self._lock:
return deepcopy(self._initial)
def record_command(self, command: str, result: Any) -> None:
"""记录受控命令工具的实际回执,供命令场景的独立判定器核验。"""
with self._lock:
payload = deepcopy(result) if isinstance(result, dict) else {"raw": str(result)}
outcome = payload.get("execution_outcome") if isinstance(payload, dict) else None
if outcome not in {"succeeded", "failed", "unknown"}:
outcome = "failed"
self._ledger.append({
"sequence": len(self._ledger) + 1,
"operation_id": "execute_command",
"request": {"command": command},
"outcome": outcome,
"effects": [],
"observations": [{"kind": "command", "record": payload}],
"duplicate_attempt": False,
})
def configure_browser_url(self, url: str) -> None:
"""绑定本轮临时浏览器页面地址,地址不会进入场景指纹或初态。"""
if self.scenario.kind != "browser" or not isinstance(url, str) or not url.startswith("http://127.0.0.1:"):
raise ValueError("浏览器评测地址无效")
with self._lock:
self._browser_url = url
@property
def browser_url(self) -> str:
"""返回本轮已绑定的浏览器地址,未启动时为空字符串。"""
with self._lock:
return self._browser_url
def model_input(self) -> str:
"""返回已注入临时资源地址的模型输入,其他场景保持公开定义不变。"""
rendered = self.scenario.model_input()
if self.scenario.kind == "browser":
if not self._browser_url:
raise RuntimeError("浏览器评测页面尚未启动")
return rendered.replace(self.scenario.browser_url, self._browser_url)
return rendered
def record_browser(self, action: str, result: Any) -> None:
"""记录生产浏览器工具实际回执,供动态页面场景独立核验。"""
with self._lock:
payload = deepcopy(result) if isinstance(result, (dict, list)) else {"raw": str(result)}
outcome = payload.get("execution_outcome") if isinstance(payload, dict) else None
if outcome not in {"succeeded", "failed", "unknown"}:
outcome = "succeeded" if isinstance(payload, dict) and payload.get("success") is True else "failed"
self._ledger.append({
"sequence": len(self._ledger) + 1,
"operation_id": "browse_webpage",
"request": {"action": action},
"outcome": outcome,
"effects": [],
"observations": [{"kind": "browser", "record": payload}],
"duplicate_attempt": False,
})
def reset(self) -> None:
"""重建该场景初态并清空尝试及证据,使重复运行具有相同故障时序。"""
with self._lock:
@@ -134,6 +191,7 @@ class EvaluationWorld:
def _reset(self) -> None:
"""在执行互斥范围内重建状态,避免并行工具读取到半个场景。"""
self._browser_url = ""
self._state = {
"scenario_id": self.scenario.scenario_id,
"subscriptions": [_subscription(71, "991000", "无关订阅")],