Skip to content

feat: Add AntWar2 - #2

Open
NemotionalDamage wants to merge 3 commits into
mainfrom
feature/AntWar2
Open

feat: Add AntWar2#2
NemotionalDamage wants to merge 3 commits into
mainfrom
feature/AntWar2

Conversation

@NemotionalDamage

Copy link
Copy Markdown
Collaborator

概述

为 AntWAR2 游戏搭建完整的基础设施:引入 rank05 选手的游戏引擎,按 BaseEnv 接口封装;构建统一策略层、策略库管理、对战矩阵、预算记录,以及评测、Coding Agent 迭代、RL 训练三大入口。完整闭环可端到端跑通,所有产出符合 CI 数据契约。

核心功能

游戏引擎与环境

  • 将 rank05 SDK 引入 env/_antwar2/,所有 SDK. 引用已重写
  • AntWar2Env(BaseEnv) 封装引擎,缓冲玩家0操作,在玩家1行动时统一结算
  • 支持可选 opponent 回调,切换为单智能体 RL 自对弈模式

统一策略接口

  • BaseStrategy(BaseAgent) - 抽象基类,定义 act()/reset()/save()/load()
  • RuleStrategy - 内置策略(hold/random/greedy/pragmatic)+ 自定义模块
  • RLStrategy - torch 策略(卷积+MLP+actor/critic),缺失时降级为贪心
  • ExternalStrategy - 4字节长度前缀 JSON stdio 驱动外部进程

策略库与数据划分

  • Population - 版本化磁盘注册表,支持注册、加载、历史记录、ZIP 导入
  • DataSplit - train/validation/hidden-test 划分,hidden 集训练时不可见

对战矩阵与预算

  • PayoffMatrix - 全配对胜率矩阵,支持增量评估(O(n))
  • BudgetRecorder - 累计环境交互、wall-clock、API/token、GPU 成本

三大入口

  • eval_entry - 单策略评测 / 多策略对比(PayoffMatrix 循环赛)
  • iter_entry - Coding Agent 迭代(加载→edit_fn→注册→评测→接受/拒绝)
  • rl_entry - PPO 训练(torch 可用)或贪心 smoke test(torch 缺失)

接入

  • register_env("antwar2", AntWar2Env)
  • 新增 agentbench antwar2 {eval, iterate, train} CLI
  • 顶层导出 AntWar2Env

修复内容

  • load_strategy() 循环依赖:改为懒加载导入子类
  • DataSplit.load() 未解包 assignment 键:修复后正确读取划分配置
  • cli.py Python 3.10 兼容性:tomllib 改为懒加载并增加 tomli 回退

验证

在 WSL Ubuntu-22.04(Python 3.10、numpy、无 torch)环境下:

  • 导入与环境注册 ✅
  • 策略库注册 4 个规则策略 ✅
  • 数据划分 ✅
  • PayoffMatrix 循环赛 ✅
  • 评测 compare/single 模式 ✅
  • Coding Agent 迭代(2次)✅
  • RL smoke test(2 episode)✅
  • CI 数据校验:4 valid, 0 invalid ✅

设计说明

  • 零硬依赖:torch/numpy 均可选,支持优雅降级
  • CI 兼容:所有入口产出 run.toml + summary.json + cost_summary
  • 可插拔设计iter_entryedit_fn 可替换为真实 LLM

@wkj2333666 wkj2333666 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自动 AI 审阅已通过最新 SSE 链路完整执行,结论为 fail,共 17 条 findings。主要阻塞项包括:策略 manifest 在制品元数据更新前写入,导致规则/RL/外部策略重载后变成不同 agent;同时回合和多操作验证存在顺序依赖与重复计费;get_legal_actions 返回值无法 round-trip 给 step;非 smoke PPO 路径会因包装器类型直接崩溃,且训练目标、ppo_epochs 和随机种子不正确;评测选择与持久化 summary 会记录错误或不完整结果;外部 agent 缺少 timeout/隔离,zip 导入未真正导入,population 路径存在越界风险。请逐项修复并补 round-trip、对称性、非 smoke PPO、持久化及安全边界测试。完整 annotations:https://github.com/SAST-agent/AgentBenchFramework/actions/runs/30274923306/job/90181293895

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants