Skip to content

feat(envs): add AppWorld benchmark (react_code protocol) - #471

Open
Yanan (yanan1116) wants to merge 3 commits into
microsoft:mainfrom
yanan1116:pr-appworld
Open

Yanan (yanan1116) wants to merge 3 commits into
microsoft:mainfrom
yanan1116:pr-appworld

Conversation

@yanan1116

@yanan1116 Yanan (yanan1116) commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds AppWorld as a SkillOpt environment (env.name: appworld). Agents complete everyday tasks by writing Python against 9 simulated apps, and each task is graded by AppWorld's own state-based tests. The PR also adds a results page with three executor / optimizer settings and a re-test of their best skills with the current code.

Design

  • Protocol. The episode is an adaptation of AppWorld's react_code agent, not the leaderboard protocol, so scores are not comparable with the AppWorld leaderboard.

    • It keeps AppWorld's few-shot prompt, copied unchanged, and the official budget of 50 executed calls.
    • Code runs through one native execute_code tool instead of fenced code blocks. The few-shot is sent as one message, under a short system prompt of our own.
    • The skill is appended to the system prompt under ## Skill Knowledge, and an empty skill adds nothing.
    • Placeholders are filled as AppWorld's agent fills them, including {{ app_descriptions }}. The app list is read once per process from the AppWorld venv, and a venv that cannot produce it stops the run.
    • Unknown tool names get an error reply and are not executed.
  • Servers. AppWorld's dependencies conflict with SkillOpt's, so servers run from a separate venv (env.appworld_venv or $APPWORLD_VENV).

    • SkillOpt starts AppWorld's environment app directly, with python -m uvicorn appworld.serve.environment:app --host 127.0.0.1. The appworld serve environment CLI is not used: it binds 0.0.0.0 and kills whatever holds its port.
    • A server's environment is an allowlist: PATH, HOME, LANG, LC_*, TMPDIR, APPWORLD_ROOT, APPWORLD_CACHE, NO_PROXY. Requests to it bypass proxies.
    • Only /initialize (with load_ground_truth: false), /execute, /task_completed, /evaluate and /close are used. /close runs after every task, so a reused server starts each task from a fresh world.
    • Each port is claimed with a per-port flock, so concurrent runs can share a range. The lock file records the server pid, and a later run stops a server whose owner died.
    • SIGTERM during a batch runs the normal cleanup. A server that fails to restart shrinks the pool. A batch in which at least 90% of tasks are infrastructure failures raises.
  • Scoring. hard is AppWorld task goal completion; soft is the fraction of tests passed, counting only tests a do-nothing agent fails. An infrastructure failure is kept and counted as a failure.

  • Splits. python -m skillopt.envs.appworld.make_split builds them from the user's local AppWorld data:

    • train: AppWorld train (90 tasks);
    • val: dev (57 tasks), used for gating and Best selection only;
    • test: test_normal + test_challenge (585 tasks);
    • --test_set scen1 gives a 195-task subset (one task per scenario).

    AppWorld distributes its data encrypted, so task instructions are not committed.

  • Failure feedback. For failed train tasks, the analysts see up to 8 failed test descriptions from /evaluate. Val is used only for its score, and test is never seen during training. env.fail_reason_style picks the wording: checks (default) leads with the failed tests; legacy keeps the earlier text.

  • Configs. configs/appworld/ holds default.yaml, a Qwen3.8-27B (thinking off) base, and four arms: gated slow update, force-accepted slow update, slow update off, and Accept Every Edit. The model endpoint comes from QWEN_CHAT_BASE_URL.

  • Licence. The prompt is AppWorld's (Apache-2.0). prompts/LICENSE and prompts/NOTICE (source URL, path, commit 42b5bcf) ship next to it.

  • Docs.

    • docs/guide/appworld.md covers install, servers, splits, running and scoring.
    • docs/guide/appworld-results.md holds the results.
    • The PR also adds a row to the benchmark table on the docs home page, two nav entries and a CHANGELOG entry.

Experiments

Test success rate (AppWorld task goal completion) on all 585 test tasks. Training: 4 epochs × 3 steps (batch 40) on the 90 train tasks, temperature 0.7. "Best skill" has the best val score, with its training step in parentheses. "Last skill" is the final skill, and "= Best" means the two are the same skill. Each cell is one training run and one test run.

These three tables were produced with an earlier revision of this environment, and no training run has been made with the current code. That revision differed in four ways:

  • the app list was left unfilled;
  • failure text was legacy;
  • the system-prompt wording was different;
  • servers were started through the CLI without /close.

The re-test below checks whether these changes move the scores.

Qwen3.8-27B executor, Qwen3.8-27B optimizer (both thinking off)

Skill slow update (Gated) slow update (Force-accept) slow update (turned off) Accept Every Edit
No skill 68.0% (398/585) 68.0% (398/585) 68.0% (398/585) 68.0% (398/585)
Best skill 84.6% (495/585) (step 8) 86.7% (507/585) (step 10) 75.7% (443/585) (step 3) 86.5% (506/585) (step 1)
Last skill 84.6% (495/585) (= Best) 86.3% (505/585) 75.7% (443/585) (= Best) 87.5% (512/585)

Qwen3.5-4B executor, Qwen3.5-4B optimizer (both thinking on)

Skill slow update (Gated) slow update (Force-accept) slow update (turned off) Accept Every Edit
No skill 24.1% (141/585) 24.1% (141/585) 24.1% (141/585) 24.1% (141/585)
Best skill 30.9% (181/585) (step 6) 29.2% (171/585) (step 1) 29.7% (174/585) (step 8) 34.5% (202/585) (step 9)
Last skill 30.9% (181/585) (= Best) 33.2% (194/585) 29.7% (174/585) (= Best) 35.0% (205/585)

Qwen3.5-4B executor (thinking on), Qwen3.8-27B optimizer (thinking off)

Skill slow update (Gated) slow update (Force-accept) slow update (turned off) Accept Every Edit
No skill 24.1% (141/585) 24.1% (141/585) 24.1% (141/585) 24.1% (141/585)
Best skill 25.8% (151/585) (step 9) 35.6% (208/585) (step 6) 39.8% (233/585) (step 9) 37.4% (219/585) (step 12)
Last skill 25.8% (151/585) (= Best) 35.0% (205/585) 39.8% (233/585) (= Best) 36.1% (211/585)

In this table the trajectory budget also differs between columns: 480,000 characters for Gated and turned off, 330,000 for the other two.

Findings

  • Skills beat No skill in every setting. The gain is +7.7 to +19.5 points with Qwen3.8 / Qwen3.8, +5.1 to +10.9 with 4B / 4B, and +1.7 to +15.7 with 4B / Qwen3.8.
  • A 4B optimizer gives smaller gains than a Qwen3.8 optimizer for the same 4B executor in three of four columns. Gated is the exception.
  • The slow update shows no consistent effect.
    • Turning it off gives the lowest column with Qwen3.8 / Qwen3.8 (that run's val score reached 56/57 at step 3 and then stopped changing).
    • It gives the highest column with 4B / Qwen3.8.
    • With 4B / 4B, the four columns are within a few points of each other.
  • Small differences are noise.
    • With the 4B executor, re-testing an identical skill moves its score by about ±2 points.
    • Tests of the near-empty initial skill ranged from 22.2% to 26.2%, against 24.1% for No skill.
  • Val saturates with the Qwen3.8 executor (89–98% on 57 tasks), so the gate and the Best choice hinge on one or two tasks.

Re-test with the current code

The No-skill baseline and the best cell of each table were tested again with this PR's code on all 585 test tasks, with the same executor settings. The skills are the ones trained with the earlier revision; nothing was retrained.

Skill Earlier revision Current code Tasks won / lost (current vs earlier)
4B executor: No skill 24.1% (141/585) 25.0% (146/585) 58 / 53
4B / 4B, Accept Every Edit, Last skill 35.0% (205/585) 35.2% (206/585) 80 / 79
4B / Qwen3.8, slow update turned off, Best skill 39.8% (233/585) 37.9% (222/585) 67 / 78
  • No 4B score moved by more than 2 points. Two-sided sign tests on the per-task wins and losses give p ≥ 0.41.
  • Both 4B skills still beat No skill, by 10.2 and 12.9 points. They win 118 tasks and lose 58, and win 121 and lose 45; p < 1e-5 in both cases.
  • The executor now rarely looks up the app list itself. show_app_descriptions was called in 44% of No-skill episodes (94% before) and in 9–12% of skill episodes (76–79% before).
  • There were no infrastructure failures.
  • The Qwen3.8 re-tests are partial. They were stopped before finishing, so they are not on the results page. On the tasks they finished, both match the earlier revision on the same tasks:
    • No skill: 65.7% (280/426) with the current code vs 64.6% (275/426), 40 tasks won / 35 lost. This covers all 168 test_normal tasks and 258 of the 417 test_challenge tasks.
    • Accept Every Edit, Last skill: 95.6% (131/137) vs 96.4% (132/137), 4 won / 5 lost. All of these are test_normal tasks.

Code layout

  • episode.py: the episode loop, the server process (command, environment, start and stop), the prompt, execute_code dispatch and budgets.
  • rollout.py: the SkillOpt side, i.e. the target-model call, skill injection, the server pool with port locks, failure text and the reflection conversation.
  • grading.py: turns AppWorld's /evaluate output into hard and soft.
  • prompts/react_code_instructions.txt: AppWorld's prompt, copied unchanged, with LICENSE and NOTICE. pyproject.toml ships the prompt, licence files and split lists, so a wheel install has them.

Test plan

  • tests/test_appworld_env.py (37 tests, offline). A fake AppWorld venv whose bin/python serves the routes backs end-to-end tests of run_batch:

    • /initialize sends load_ground_truth: false;
    • only allowlisted variables reach the server;
    • the server binds 127.0.0.1;
    • /close runs once per task;
    • nothing is left running and the locks are released;
    • queued tasks are cancelled on an error;
    • the all-infrastructure-failure abort.

    There are also unit tests for the port lock, pool exhaustion, stop(), the SIGTERM handler, unknown tools, splits, grading, failure text and prompt filling.

  • python -m pytest -q tests: 2655 passed, 23 skipped, 4 xfailed. ruff check is clean on the changed files.

  • Live checks against a real AppWorld install:

    • the server environment matches the allowlist (/proc/<pid>/environ);
    • ss shows 127.0.0.1 only;
    • two tasks graded correctly in a row on one server;
    • after the owner process was SIGKILLed, the next run stopped the orphaned server.
  • End-to-end smoke against a Qwen3.8-27B endpoint: 4 train, 3 val and 3 test tasks, 2 epochs, then eval_only.

    • Both exit 0.
    • It covered baseline selection, rollouts, reflection, the gate, a real slow-update call, the meta skill and the final tests.
    • All 43 episodes had the app list in the prompt.
  • The 585-task re-tests above, run with this code: 0 infrastructure failures, and no server or lock left afterwards.

@yanan1116

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@Yif-Yang

Copy link
Copy Markdown
Contributor

Thank you for this. It's a carefully built environment and it was a pleasure to review. Things I especially liked:

  • load_ground_truth=False with only the official routes;
  • the no_op_pass-aware soft score;
  • keeping task instructions out of the repo and building splits locally;
  • failure feedback that only ever reaches the optimizer from train;
  • the placeholder check that raises;
  • the honest write-up of the legacy vs checks A/B.

It's also stdlib-only, so people who don't use AppWorld get no new dependencies, and the wheel ships the prompt and split files.

Before merging I'd like a few small, concrete changes, mostly about the AppWorld server processes:

  1. Child environment. episode.py:170 passes dict(os.environ) to the server that executes model-written code, so every provider key (Azure, OpenAI, Qwen, …) is visible inside it. AppWorld's guard is in-process, not an OS sandbox. An allowlist (PATH, HOME, LANG/LC_*, TMPDIR, APPWORLD_ROOT/APPWORLD_CACHE, NO_PROXY) should be enough.

  2. Bind address. Could you confirm which address appworld serve environment binds to, and pass a loopback host if the CLI supports one? The upstream examples suggest 0.0.0.0, which would expose /execute on the network. While you're there, could you also confirm whether a reused server should get /close between tasks? Upstream's parallelization guide says one world per server.

  3. Shutdown and failure paths.

    • If a replacement server fails to start in ServerPool.release, the run hangs: workers block in idle.get() and the executor exit waits forever.
    • Ctrl-C keeps running every queued task.

    Could you use the repo convention shutdown(wait=False, cancel_futures=True) in a finally, make acquire() fail or time out when the pool can't be refilled, and tolerate ProcessLookupError in stop()?

  4. Orphaned servers. With atexit-only cleanup and start_new_session=True, a SIGTERM, scheduler kill or OOM leaves servers alive and holding ports. Any of these would cover it: a SIGTERM handler that raises SystemExit, PR_SET_PDEATHSIG on Linux, or a sweep for stale servers at startup.

  5. Port claiming across runs. The readiness probe accepts any listener. If two runs share a range (all four arm configs default to 23100), one run's server can die with "address in use" while that run silently drives the other run's server. A per-port flock held for the server's lifetime, plus checking that your own process is still alive after the probe, would close this.

  6. Proxies. urllib honours http_proxy for the 127.0.0.1 calls. With a proxy set, every task became an infrastructure failure scored 0 and the run still finished "successfully". Please use an opener with ProxyHandler({}), and consider failing the batch when nearly all tasks are infrastructure failures, as searchqa does.

  7. Licence. The few-shot prompt is Apache-2.0 upstream. Please ship the licence text and a short notice (source URL, commit, "copied unchanged") next to it, add it to package-data, and mention it in the guide.

  8. Docs. All the caveats are there, thank you. Please add a one-line summary above the results table, e.g. "produced with an earlier revision: unfilled app list, legacy failure text; no run with this code yet". It would also help to:

  9. Tests. A small offline contract test with a fake bin/appworld serving the four routes would protect what matters most: the /initialize payload (load_ground_truth: false), the environment allowlist, servers stopped after run_batch, and cancellation on error. Today, flipping load_ground_truth to True still passes the suite.

Small nits, not blocking:

  • Unknown tool names become code; I'd return an error instead.
  • An empty appworld_venv falls back to ./bin/appworld.
  • The app list is read per batch rather than once.
  • The system prompt mentions an "enterprise workflow" and an "attached document".
  • Which split did the 48-failure A/B use?

Thanks again. With these changes this will be a great addition.

@yanan1116

Copy link
Copy Markdown
Contributor Author

Yifan Yang (@Yif-Yang) thanks. working on it. and will report test results soon.

@yanan1116

Copy link
Copy Markdown
Contributor Author

Thank you for the careful review. Yifan Yang (@Yif-Yang)

All nine points and the nits are addressed in the new commit, and the branch is rebased on current main (#469 and #470 had touched CHANGELOG.md).

  1. Child environment. A server now gets only PATH, HOME, LANG, LC_*, TMPDIR, APPWORLD_ROOT, APPWORLD_CACHE and NO_PROXY (episode.server_environment). Checked against a real AppWorld server through /proc/<pid>/environ.

  2. Bind address and /close.

    • appworld serve environment has no host option: appworld/serve/environment.py calls uvicorn.run(app, host="0.0.0.0", port=port). Its run() also calls maybe_kill_processes("port", [port]) first, so it kills whatever holds the port, including another run's server.
    • SkillOpt therefore starts the same app directly, python -m uvicorn appworld.serve.environment:app --host 127.0.0.1 --port N, from the AppWorld venv. ss -ltnp shows 127.0.0.1:<port> only.
    • /initialize replaces the global world without closing the previous one, so a reused server kept the last task's DB cache, temp output DBs and frozen clock. run_episode now calls /close in a finally after grading. If /close fails, the server is replaced. Two tasks in a row on one real server both grade correctly.
  3. Shutdown and failure paths.

    • run_batch uses shutdown(wait=False, cancel_futures=True) in a finally, and ServerPool.close() now also stops busy servers, so running episodes end at their next request.
    • If a replacement server fails to start, the pool shrinks by one and logs a warning. acquire() raises once no server is left, instead of blocking.
    • stop() tolerates ProcessLookupError.
    • Server start-up failures inside the pool constructor now stop the servers that did start.
  4. Orphaned servers. Two layers:

    • SIGTERM becomes SystemExit while a batch runs (main thread only, and only if no other handler is installed), so the cleanup runs.
    • Each port's lock file records the server pid. When a later run claims the port and the owner is gone, it stops the leftover server after checking /proc/<pid>/cmdline. Tested by SIGKILLing a run's owner process: the next run stopped the orphan and reused the port.
  5. Port claiming across runs. A per-port flock (one lock file per port in the system temp directory) is held for the server's lifetime, and the readiness probe also checks that our own process is still alive after the port answers. Runs with overlapping ranges now get different ports, so the shared default 23100 is safe. Not calling the CLI also removes its kill-on-port.

  6. Proxies. All requests to the servers go through an opener with ProxyHandler({}). A batch in which at least 90% of tasks are infrastructure failures now raises, as searchqa does for 100%.

  7. Licence. skillopt/envs/appworld/prompts/LICENSE (AppWorld's Apache-2.0 text) and NOTICE (source URL, path, commit 42b5bcf, "copied unchanged") ship next to the prompt, are in package-data, and the guide mentions them. I re-checked the prompt: it is byte-identical to the file at that commit.

  8. Docs. Results moved to a new page, docs/guide/appworld-results.md, linked from the guide and the nav.

    • It opens with a bold line saying the three tables come from an earlier revision and no training run with this code exists yet, and lists the four differences (unfilled app list, legacy failure text, old system-prompt wording, CLI-started servers without /close).
    • A "Re-test with the current code" section re-tests the No-skill baseline and the best skills with this code (results below).
    • It explains the shared "No skill" row, fix(optimizer): insert_after a target that ends in a newline right after it #408 and fix(trainer): re-measure the force-written slow-update skill (#404) #422 (with links), and the 4B noise figure.
    • It also adds two tables with a Qwen3.5-4B executor (one with a 4B optimizer, one with a Qwen3.8 optimizer), each with its models, thinking mode and trajectory budget.
    • The guide's intro now says the protocol is an adaptation (native tool calls, single-message few-shot, own system prompt) and not comparable with the leaderboard.
    • A new "Servers" section in the guide describes points 1 to 6.
  9. Tests. A fake AppWorld venv whose bin/python serves the routes now backs these tests:

    • /initialize sends load_ground_truth: false;
    • only allowlisted variables reach the server, with a bogus http_proxy set and no_proxy cleared;
    • the server binds 127.0.0.1;
    • /close is called once per task;
    • no server is left running after run_batch and lock files are released;
    • queued tasks are cancelled on an error;
    • the all-infrastructure-failure abort.

    There are also unit tests for the port lock, pool exhaustion, stop(), the SIGTERM handler and unknown tools. Flipping load_ground_truth to True, passing the full environment, binding 0.0.0.0, dropping ProxyHandler({}) or dropping /close each fail at least one test.

Nits:

  • Unknown tool names now get an error reply and are not executed or counted against the budget.
  • An empty appworld_venv (and no $APPWORLD_VENV) raises a clear error.
  • The app list is cached per venv per process.
  • The system prompt no longer mentions an "enterprise workflow" or an "attached document".
  • The 48-failure A/B used train failures: 48 failed train trajectories from 7 Qwen3.8-27B runs.

Validation: full suite 2655 passed, 23 skipped, 4 xfailed; ruff has nothing new beyond the 6 pre-existing E402 in scripts/. The wheel contains prompts/LICENSE and prompts/NOTICE. End-to-end smoke on this branch against a real AppWorld install and a Qwen3.8-27B endpoint: 4 train, 3 val and 3 test tasks, 2 epochs, then eval_only on test. Both exit 0 with no tracebacks. The run covered baseline selection, train rollouts, reflection, the gate, a real slow-update call with its gated validation, the meta skill, the final tests and eval_only. All 43 episodes had the app list in the prompt and no leftover placeholder. Servers listened on 127.0.0.1 only, and no server or port lock was left afterwards.

Re-test with this code on all 585 test tasks, using the skills trained with the earlier revision. Nothing was retrained.

Skill Earlier revision This code Tasks won / lost
4B executor: No skill 24.1% (141/585) 25.0% (146/585) 58 / 53
4B / 4B, Accept Every Edit, Last skill 35.0% (205/585) 35.2% (206/585) 80 / 79
4B / Qwen3.8, slow update turned off, Best skill 39.8% (233/585) 37.9% (222/585) 67 / 78
  • No score moved by more than 2 points (sign test p ≥ 0.41).
  • Both skills still beat No skill by 10 to 13 points (p < 1e-5).
  • There were no infrastructure failures.
  • With the app list in the prompt, show_app_descriptions calls dropped from 94% to 44% of No-skill episodes.
  • The two Qwen3.8 re-tests were stopped before finishing, so they are not on the results page. On the tasks they finished, they match the earlier revision on the same tasks:
    • No skill: 65.7% (280/426) vs 64.6% (275/426), covering all of test_normal and 258 test_challenge tasks;
    • Accept Every Edit, Last skill: 95.6% (131/137) vs 96.4% (132/137), all from test_normal.

This branch has not been deployed

No deployments
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