diff --git a/CHANGELOG.md b/CHANGELOG.md index ad973dc2..91e80f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -143,6 +143,15 @@ Changes are grouped by software version. Entries under Unreleased describe work ### Added +- The AHE-Beta Adapter (AHE-Beta, arXiv:2611.24924, `examples/ahe_beta_adapter/`, `docs/methods/ahe_beta_adapter.md`): + AHE-Beta's requirement-centered harness evolution confined to a Codex adapter. `utils/user.py`'s `UserCodexAgent` + (a `CliAgent`) runs one Codex session in each task's Harbor environment while a simulated user, written against + `simulate(task, agent, workspace, params)`, talks to it through Codex hooks and a root-owned bridge (messages while it + works, follow-ups, interrupts, then a verdict); `utils/ahe_user.py` puts AHE-Beta's own simulator behind it, its + model reached through Hermit; `utils/judge.py` scores the verdict the host kept; `prepare.py` turns an AHE-Beta + cohort into a run whose learner never reads a persona. AHE-Beta's own demand and delivery Evolver (Gitea, + OpenAgents) is in `delivery/`: its controller and worker run in the run's sandbox; run end to end once (a U4 round + on the paper's models, its delivery bound for the next round), not evaluated. - `examples/officeqa_harbor/`: OfficeQA as Harbor's task set (harbor-datasets' `datasets/officeqa`, pinned) in the OfficeQA paper's evaluation: each question in its own Harbor environment, the paper's agent prompt, the final message's `` scored by the paper's `reward.py` (the OfficeQA repository's at its commit) at a 0.0% diff --git a/docs/index.md b/docs/index.md index 705a1706..e3069cb8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -79,6 +79,7 @@ methods/aspire methods/meta_harness_adapter methods/ace methods/ahe_adapter +methods/ahe_beta_adapter methods/rrsi_adapter methods/evosafe methods/opro diff --git a/docs/methods/ahe_beta_adapter.md b/docs/methods/ahe_beta_adapter.md new file mode 100644 index 00000000..1d2fbc1a --- /dev/null +++ b/docs/methods/ahe_beta_adapter.md @@ -0,0 +1,146 @@ +# AHE-Beta Adapter + +AHE-Beta, Agentic Harness Engineering Beta: Requirement-Centered Evolution of Agent Harnesses +([arXiv:2611.24924](https://arxiv.org/abs/2611.24924), [code](https://github.com/Curry09/AHE-Beta)), evolves a coding +agent's harness from what simulated users ask for while they work with it, in three parts: user-driven evaluation (a +user simulator follows a persona through multi-turn sessions, sends follow-ups and messages while the agent works, +interrupts it, checks the result with its own commands, then rates the session from 1 to 4 and files the issues it +saw), team-based modification (on a Gitea repository, Triage drops invalid and task-specific issues, an Architect merges +issues that share a root cause into an RFC, a PM mines unstated requirements, developers implement) and +requirement-driven selection (a change merges only when it resolves a verified requirement and passes review; no +verifier result or benchmark score is used while the harness evolves). AHE-Beta edits its whole NexAU seed harness: the +agent's configuration and entry point, its tool definitions, its prompts and parameters. **AHE-Beta Adapter is +AHE-Beta's loop confined to an adapter:** the acting agent (Codex), its loop and its tools are fixed, and only the +adapter's files change: Codex's project instructions, command hooks, helper scripts, skills and roles. AHE-Beta's own +Hermit integration makes the same choice: its handoff to the delivery team names "an external Hermit Adapter deployed +to an unchanged host" as the evolving product. Choose it when the learning signal is a user's (here a simulator's) +judgment of interactive sessions rather than a verifier's score. + +## Setup + +```bash +PYTHONPATH="$AHE_ROOT/backend" python -m ahe_beta.integrations.hermit.export \ + --experiment "$AHE_ROOT/examples/experiments/u8-mixed-e2b.json" --output --cache +python examples/ahe_beta_adapter/prepare.py --cohort --ahe-root "$AHE_ROOT" --run-id u8-codex +``` + +`prepare.py` writes the run beside AHE-Beta's export: the rows (`rows.jsonl`: id, Harbor task, instruction), each +session's assignment (`assignments.json`: its persona, scenario and round, read only by the acting agent), the splits +without the sessions it leaves out (a task with a companion container), what the learner is told of the tasks and +their records (`task-info/README.md`) and `run.yaml` (paths shown schematically; prepare.py writes them absolute): + +```yaml +template: examples/ahe_beta_adapter/template # ahe-beta-adapter@1.0 +agent: + name: examples/ahe_beta_adapter/utils/user.py:UserCodexAgent # Codex in each task's Harbor environment + base: codex + params: + user: {simulate: ahe_user:simulate, assignments: assignments.json, params: {model: ...}} # AHE-Beta's simulator +judge: {path: examples/ahe_beta_adapter/utils/judge.py, name: user} # the user's rating, (rating - 1) / 3 +evolver: {name: codex, base: codex, params: {tools: [check_spec]}} # Hermit's Codex Evolver +data: {step_size: , shuffle: false} # one step = one round of the cohort +``` + +The example's [README](https://github.com/Infini-AI-Lab/hermit/tree/main/examples/ahe_beta_adapter) has the setup +(AHE-Beta's pinned checkout, Harbor, the Codex release mounted into each task's container) and AHE-Beta's own demand +and delivery Evolver (`examples/ahe_beta_adapter/delivery/`: its team in the run's sandbox, run end to end once, not +evaluated). + +## The template + +`examples/ahe_beta_adapter/template/` (`ahe-beta-adapter@1.0`): + +| Path | Learnable | Limits | What reaches the acting agent | +|---|---|---|---| +| `ADAPTER.md` | yes | 32 KB | Codex's project instructions | +| `.codex/hooks.json` | yes | 24 KB | command hooks; Stop hooks without a matcher, run inside the user's Stop hook | +| `scripts/*.py` | yes | 40 files, 200 KB each | helpers the shell runs | +| `.agents/skills/*/SKILL.md`, `.agents/skills/*/scripts/*` | yes | 40 skills, 80 scripts | skills (a `description` in the frontmatter) | +| `agents/*.md` | yes | 20 files | Codex roles (`name`, `description`) | +| `exports.yaml`, `README.md` | no | | what the deployment exports | + +`.hermit/check.py` refuses hooks of unknown events, hooks not shaped as Hermit loads them (each event a list of +groups, each hook a `command` hook with a command), a Stop hook with a matcher, an empty `ADAPTER.md` and a script +that does not compile. After every step of the validated route the Trainer checks the adapter against the template and +repairs it (a file outside every path removed, a fixed file restored, a learnable file in a wrong format back to the +parent's); AHE-Beta's own Evolver (`run-delivery.yaml`) refuses a delivery that fails the check instead, and the step +fails with the adapter as it was. + +## One framework step + +```mermaid +flowchart LR + A[adapter H_r] --> R[round r: every seed once,
Codex in its Harbor environment,
AHE-Beta's user over the channel] + R --> V[the users' verdicts: rating, outcome,
reason, issues; their transcripts] + V --> L[one Codex learner session,
AHE-Beta's protocol in EVOLVER.md] + L --> C[check_spec, repair] + C --> B[adapter H_r+1] +``` + +A step is one round of the cohort: every seed once with its persona (`data.step_size` is a round's sessions). Each +session is one `codex exec` in the task's own Harbor environment, led by AHE-Beta's simulator through three Codex hooks +and a root-owned bridge (a message inserted after a tool call, a tool call denied after an interrupt, a Stop that hands +the reply to the user and continues with the user's next message). The judge scores the user's rating and gives the +learner what the user said. The Codex Evolver reads the round's verdicts, the user transcripts and the agent's event +streams (never a persona or the simulator's own records) and edits the adapter following AHE-Beta's protocol in the +template's learner guide (`.hermit/EVOLVER.md`, adapted from its Triage, Architect and PM roles): issues as evidence of +requirements, merged by root cause, changed at the layer that owns the behaviour, with no task names. The next round runs the new adapter; the final adapter is the last step's. + +## Parameters + +The learner is Hermit's [Codex Evolver](agent.md), with `check_spec` as its only Hermit tool (beside its own files +and shell): + +```{literalinclude} ../../hermit/agent/evolver/methods/codex/evolver.yaml +:language: yaml +``` + +`prepare.py` sets the models (`--actor-model`, `--user-model`, `--learner-model`: a Codex model name on the ChatGPT +login, or a `/` reference) and their efforts; the user's options (`user.wait_s`, `exit_wait_s`, +`review_s`) are in `utils/user.py`'s docstring. + +## Records + +Each rollout's log holds `user-transcript.jsonl` (every message, reply and tool event the user could see), +`user-verdict.json` (the visible verdict) and, for a session the user rated, `user-reward.txt`; the simulator's own +records (its session, the persona, its private checks, AHE-Beta's full outcome) stay under the acting agent's +`/user//`, outside every log, and its usage ledger beside them (`user-model/usage.jsonl`). + +## The authors' implementation against this one + +| Dimension | AHE-Beta (43b165f) | AHE-Beta Adapter | Why | Open? | +|---|---|---|---|---| +| When learning happens | after each round: every seed once with its persona; five rounds learn, the sixth is observed | the same: one step is one round (`step_size`: the round's sessions), one epoch; the last round is the evaluation split | Same | no | +| What the learner sees | Triage: issues with their evidence, interaction records, harness logs; PM: ratings and summaries; never a persona prompt or a verifier | the users' verdicts (rating, outcome, reason, issues), their transcripts, the agent's event stream; no persona and no simulator record; the task's verifier verdict is recorded with each rollout (AHE-Beta's exported tasks only copy the user's rating) | Framework: the learning material | no | +| Each component's carrier | NexAU's whole seed harness: configuration, entry point, tool definitions and their code, prompts, parameters; written by the developer agents | the adapter's files (the table above): instructions, command hooks, scripts and skills, roles; written by the learner only; Codex's loop, tools, context handling and sampling fixed | Framework: the acting agent is fixed; the reason for the name | no | +| The update | requirement-driven: Triage, the Architect's RFC, the PM, admission, developers' pull requests, review; a change merges only for a verified requirement | one Codex learner session with AHE-Beta's protocol as text (`.hermit/EVOLVER.md`), `check_spec`; every step kept, no gate, no rollback | Decision: the validated route; AHE-Beta's own pipeline is in the example, run end to end once | yes: requirement-driven selection | +| User simulation | its persona loop, private checks, terminal review | the same code, its transport Hermit's channel in each task's Harbor environment | Same | no | +| Tasks and runtime | 32 seeds; U8, U16 and U32 over six rounds; E2B sandboxes with internet access | the same cohorts as Harbor task directories (local Docker, the public network), without the sessions whose task needs a companion container (one a round in U8 and U16, two in U32) | Framework: a Hermit environment does not reach a companion container yet | yes: companion containers | +| Models and budgets | GLM-5.3-Flash acting and user, GLM-5.3 team, Claude Code developers; the recipes' budgets | configuration (GPT-5.6-Luna on a ChatGPT login by default, GLM-5.3-Flash by reference); the exporter's budgets, Codex's clock ending `review_s` before the deadline | Decision | no | +| What is not ported | | the held-out evaluation suite (38 Harbor-index tasks), its evaluation persona, the human A/B study | Decision | yes: the held-out evaluation | + +## Result + +The first evaluation is on OfficeQA with GPT-5.6-Luna in every role, AHE-Beta's schedule on the 50 training questions +(five rounds that learn, a sixth observed) and one pass over the 172 test questions without a user +([record](https://github.com/Infini-AI-Lab/hermit/tree/main/examples/ahe_beta_adapter#first-evaluation)): + +| Evaluation | No adapter | Starting adapter | Final adapter | Final − starting (paired) | +|---|---|---|---|---| +| `examples/officeqa`, exact match (2026-11-27) | 0.308 | 0.366 | 0.471 | +10.5 points, SE 3.4 | +| `examples/officeqa_harbor`, the OfficeQA paper's scorer at 0.0% (2026-11-28) | 0.576 | 0.622 | 0.605 | −1.7 points, SE 3.0 | + +The first run's gain is the answer's form (22 of its 27 gained questions already held the reference's value), and its +users' ratings did not move, because AHE-Beta's terminal review at `43b165f` reads an 80-character preview of each +reply. The second run fixed that in a local copy of AHE-Beta: the rating then follows a correct answer, but neither +it (3.50 in round 1, 3.46 in round 6) nor the test score rose. No experiment of the paper's has run: its tasks are +coding, optimization, analysis and tool use, and its held-out suite is not packaged. + +## What it is not + +The learner cannot change Codex's own loop, tools, context handling or sampling: a tool is a script the shell runs or a +skill, and a behaviour at run time acts only through what Codex's hooks allow (add context after a tool call, deny a +tool call, block a stop). The validated run (`run.yaml`) gives the learner AHE-Beta's protocol as text; it has neither +AHE-Beta's team nor its requirement-driven selection, which only `run-delivery.yaml` runs (run end to end once on one +round, not evaluated). +The held-out evaluation is not packaged. diff --git a/docs/methods/index.md b/docs/methods/index.md index 9bc3f910..16cc817f 100644 --- a/docs/methods/index.md +++ b/docs/methods/index.md @@ -14,6 +14,7 @@ template–method combinations meaningful. | Refine a policy, sub-agents, skills and memory in place from each step's trajectories, without a gate | [Continual Harness](continual_harness.md) | `continual-harness@1.1` | Learner model endpoint, Codex | | Grow an itemised playbook by incremental deltas from reflections, keeping the best validation playbook | [ACE](ace.md) | `ace@1.0` | Learner model endpoint; optional validation split | | Evolve an agent's harness (prompt, middleware, scripts, skills, sub-agents, memory) from k rollouts per task, with each change attributed and reversible | [AHE Adapter](ahe_adapter.md) | `ahe@1.0` | An acting agent that runs hooks (Codex, Claude Code), a learner CLI (Codex, Claude Code or Pi), k rows per task | +| Evolve a Codex adapter from what simulated users ask for in interactive sessions (their ratings and issues, no verifier score), one round of persona-led sessions per step | [AHE-Beta Adapter](ahe_beta_adapter.md) | the example's `ahe-beta-adapter@1.0` | AHE-Beta's checkout (its user simulator), Harbor task environments with python3 and a Codex release mounted, a ChatGPT login or model references | | Search a dual-surface defense (prompt + tool hooks) for a frozen victim against frozen attack cases | [EvoSafeHarness](evosafe.md) | `evosafe@1.0` | Hook-bridge pipeline, utility/attack judge (verdicts in `JudgeResult.extra`), optional validation split, Claude Code, Codex or Pi | | Search instructions with a model that reads the best earlier instructions with their training scores | [OPRO](opro.md) | `prompt-only@1.0` | Learner model endpoint; validation split for `select: validation` | | Build a persistent world model from an ordered environment stream | [MWM](mwm.md) | `mwm` | Evidence store, deployment description, tools, Linux learner environment, a learner CLI (Codex, Claude Code or Pi) | @@ -42,6 +43,7 @@ task-specific service overhead. Call counts vary with evidence, candidates, and | Continual Harness | Four Refiner calls per step (policy, sub-agents, skills, memory); no candidate rollout, no validation | Step log in `state/`; the memory the agent writes comes back with each trajectory | Current adapter | | ACE | Per sample: one Reflector call, or for a wrong answer up to `max_num_rounds` Reflector calls and agent re-runs, one Curator call; validation at each epoch's end when `data.val` is set | `state/ace.json` (sample records, validation scores) and the best validation playbook | Best validation playbook, else the current one | | AHE Adapter | Per step: one Agent Debugger session per task (up to three attempts) and one Evolve Agent session; no candidate rollout, no validation | `state/`: stats, Debugger reports, manifests, verdicts, rollbacks, best-ever | Best-ever iteration by training pass rate, or the last | +| AHE-Beta Adapter | Each rollout is a whole conversation: the simulated user's model calls (its turns, its checks, its review) beside the actor's; one Codex learner session per step (`run-delivery.yaml`: AHE-Beta's delivery team instead, its demand roles and Claude Code developers); no candidate rollout, no validation | Notes the learner keeps in `state/` (`run-delivery.yaml`: AHE-Beta's controller state and its Gitea repository, outside the run) | Current adapter | | EvoSafeHarness | Per trial: Designer, Criticizer and Analyzer calls, plus candidate runs on the training cases (and the parent's validation cases when a candidate qualifies); the parent reuses the step's rollouts when they match | Lessons archive and trial history | Last promoted bundle | | OPRO | `n_candidates` optimizer calls per step; each new instruction run on every training task; with `select: validation`, the `top_k` best run on validation at the end | `state/opro.json` (every instruction with its per-task training scores) | Best training score, or the best validation mean of the top `top_k` | | MWM | Maintenance and a learner session per eligible block, plus native bootstrap/retry behavior | World-model adapter plus method/session records | Current world-model adapter | diff --git a/examples/ahe_beta_adapter/README.md b/examples/ahe_beta_adapter/README.md new file mode 100644 index 00000000..0c5ed499 --- /dev/null +++ b/examples/ahe_beta_adapter/README.md @@ -0,0 +1,376 @@ +# AHE-Beta Adapter + +**Agentic Harness Engineering Beta: Requirement-Centered Evolution of Agent Harnesses** +([arXiv:2611.24924](https://arxiv.org/abs/2611.24924), [code](https://github.com/Curry09/AHE-Beta)) evolves a coding +agent's harness from what simulated users ask for while they work with it: ❶ a user simulator follows a persona +through multi-turn sessions (follow-ups, mid-run messages, interruptions, its own checks) and files issues and a 1–4 +rating; ❷ a team (Triage, Architect, PM, Developers) turns the issues into requirements and the requirements into +general changes; ❸ a change merges only when it resolves a verified requirement and passes review. No verifier result +or benchmark score is used during evolution. + +AHE-Beta evolves its whole NexAU seed harness (its configuration and entry point, tool definitions, prompts and +parameters). **The AHE-Beta Adapter is AHE-Beta's loop confined to an adapter**, as the [AHE Adapter](../../docs/methods/ahe_adapter.md) +is AHE's: Codex, its loop and its tools are fixed, and only the adapter changes (`template/`: Codex's project +instructions, command hooks, helper scripts, skills and roles); the user simulator, the tasks and their verifiers stay +fixed too. AHE-Beta's own Hermit integration makes the same choice (its handoff to the delivery team names "an external +Hermit Adapter deployed to an unchanged host" as the evolving product). What an adapter cannot express (a change to +Codex's loop, its native tools, its context handling or its sampling) is out of reach, so results are not comparable +with the paper's numbers; the [method page](../../docs/methods/ahe_beta_adapter.md) has the comparison. + +| Route | Acting | User | Learning | State | +|---|---|---|---|---| +| `run.yaml` from [`prepare.py`](prepare.py) | Codex in each task's Harbor environment ([`utils/user.py`](utils/user.py)) | AHE-Beta's own simulator ([`utils/ahe_user.py`](utils/ahe_user.py)), its model through Hermit | Hermit's Codex Evolver on the users' verdicts | run (Validation, below) | +| `run-delivery.yaml` from [`bootstrap.py`](bootstrap.py) | the same | the same | AHE-Beta's own demand and delivery pipeline ([`delivery/`](delivery/): Triage, Architect, PM, admission; OpenAgents developers on a Gitea repository), in the run's sandbox | run end to end once (Validation), not evaluated | +| [`smoke/run.yaml`](smoke/run.yaml) | the same | a scripted user ([`utils/scripted_user.py`](utils/scripted_user.py)) | none (`hermit eval`) | run (Validation) | + +The simulated user lives in this example for now. Its contract, `simulate(task, agent, workspace, params)`, is the one +a Hermit abstraction will keep when it moves into the framework (with real people giving a rollout feedback and +interrupting it); a simulator written against it should not need to change then. + +## The user's contract + +```python +def simulate(task: dict, agent: Conversation, workspace: Workspace, params: dict) -> dict +``` + +| Argument | What it is | +|---|---| +| `task` | `{"id": the row's id, "name": the Harbor task's name, "instruction": its instruction.md}` | +| `agent` | the running Codex session ([`utils/channel.py`](utils/channel.py)): `write(text)` (the first message starts Codex with it as the prompt; a later one reaches the model after the running tool call, or as the next turn), `poll(timeout)` (the next reply `{text, interrupted}`, or None while it works), `send(text, timeout)`, `events()` (tool_start, tool, denied, delivered, adapter_block, interrupted_reply, timeout), `interrupt(text, timeout)` (tool calls are denied until it stops; a running tool is not cancelled; the reply it stops with, or None, and then that reply comes as an `interrupted_reply` event, never as the answer to a later message), `close()` | +| `workspace` | the task's environment as the user reaches it ([`utils/user.py`](utils/user.py)): `run(command, timeout, cwd)` → `{code, stdout, stderr, timed_out}` as the task's agent user, `read`, `write`, `quiesce()` (the agent stopped and what it started ended, so a review sees frozen files); a task service's `service_run` / `service_read` in the main container | +| `params` | `user.params`, the task's assignment (its persona, scenario, round: `user.assignments` or the row's `user.task_field`), `session_id`, `artifact_root` (a private folder of this machine), `adapter_sha256`, `plan_admitted` (the run holds the login's plan admission for the task's environment) | +| returns | `{"score": a number in [0, 1], "rating", "outcome", "reason", "issues", "feedback", "usage", "files", "record", ...}`; `usage.tokens` and `usage.cost_usd` (None for a model without a price), when given, are added to the rollout's; an exception whose `final` is true is a failure no run again mends | + +## How a session runs + +One `codex exec` runs for the whole conversation, in the task's own Harbor environment, through Hermit's Codex agent +(`UserCodexAgent` subclasses `hermit.agent.acting.workspace.CliAgent`: the adapter's deployment, the sign-in, the +stream, the usage and the infra classification are the framework's). Three hooks ([`utils/user_hook.py`](utils/user_hook.py)) +carry the conversation through a bridge ([`utils/channel_server.py`](utils/channel_server.py)), both installed as root +outside the workspace before Codex starts: PostToolUse inserts a waiting message, PreToolUse denies tool calls after an +interrupt, Stop hands the reply to the user and continues the session with the user's next message. The adapter's own +hooks stay; its Stop hooks run inside the user's Stop hook first (Codex runs one event's hooks at the same time), so +they must be command hooks without a matcher (the template's check refuses others); they run one after another, the +first that blocks or ends the session deciding (the later ones are tried again at the next Stop, after the earlier +ones). This machine talks to the bridge +with one command at a time in the environment (a read waits there up to 5 s for new events), so nothing is mounted from +this machine and the agent's writable workspace holds no queue. Codex's clock ends `user.review_s` (600 s) before the +task's deadline (taken when Codex starts, so that the channel's setup and the user's first turn come off Codex's time), +so that the user's last turn and review fit in it. The session ends with the user's end, then +[`utils/processes.py`](utils/processes.py) ends whatever the rollout started (the bridge and the task's registered +services stay): AHE-Beta's freeze before collection and verification, so a task whose tests need a server the agent +left running is graded differently than Harbor grades it. The bridge and the hooks need python3 3.8 or later in the +image. + +The channel is out of the agent's way, not out of its reach: the bridge, its hook and `.codex/` are root's and +read-only, and the bridge answers a process whose command line, or an ancestor's, names the hook and Codex (a check of +`/proc` text, not of identities), which every command the agent runs under Codex can satisfy (AHE-Beta's exported +images also run the agent as root). An agent that looked for it could take a queued message or report a reply or a +tool event the user then reads, and the user's verdict rests on what it read: the judge reads the verdict this machine +kept, never a file in the environment, but what the user observed came through a channel the agent can reach, as the +paper's own transport does. + +What the run places in the workspace (the hooks, the adapter's deployment: `.codex/`, `AGENTS.md`, +`.hermit-deploy.json`, `hermit/