agent-s4 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. agent_s4-0.1.0/LICENSE +201 -0
  2. agent_s4-0.1.0/PKG-INFO +182 -0
  3. agent_s4-0.1.0/README.md +159 -0
  4. agent_s4-0.1.0/__init__.py +32 -0
  5. agent_s4-0.1.0/agent_s4.egg-info/PKG-INFO +182 -0
  6. agent_s4-0.1.0/agent_s4.egg-info/SOURCES.txt +134 -0
  7. agent_s4-0.1.0/agent_s4.egg-info/dependency_links.txt +1 -0
  8. agent_s4-0.1.0/agent_s4.egg-info/requires.txt +4 -0
  9. agent_s4-0.1.0/agent_s4.egg-info/top_level.txt +1 -0
  10. agent_s4-0.1.0/benchmark_spec.py +56 -0
  11. agent_s4-0.1.0/builder_sandbox.py +382 -0
  12. agent_s4-0.1.0/builder_scratch_vm.py +126 -0
  13. agent_s4-0.1.0/cli.py +415 -0
  14. agent_s4-0.1.0/config/__init__.py +0 -0
  15. agent_s4-0.1.0/config/experiment.py +200 -0
  16. agent_s4-0.1.0/config/island.py +16 -0
  17. agent_s4-0.1.0/config/scheduler.py +93 -0
  18. agent_s4-0.1.0/constants.py +44 -0
  19. agent_s4-0.1.0/costs.py +218 -0
  20. agent_s4-0.1.0/db.py +656 -0
  21. agent_s4-0.1.0/driver.py +304 -0
  22. agent_s4-0.1.0/eval/__init__.py +0 -0
  23. agent_s4-0.1.0/eval/grader_image_limit.py +60 -0
  24. agent_s4-0.1.0/eval/osworld.py +1928 -0
  25. agent_s4-0.1.0/eval/osworld_v2.py +729 -0
  26. agent_s4-0.1.0/eval/scienceboard_prime.py +654 -0
  27. agent_s4-0.1.0/git_utils.py +176 -0
  28. agent_s4-0.1.0/harness/__init__.py +59 -0
  29. agent_s4-0.1.0/harness/base.py +67 -0
  30. agent_s4-0.1.0/harness/builder_common.py +214 -0
  31. agent_s4-0.1.0/harness/opencode/__init__.py +0 -0
  32. agent_s4-0.1.0/harness/opencode/builder.py +141 -0
  33. agent_s4-0.1.0/harness/opencode/config.py +349 -0
  34. agent_s4-0.1.0/harness/opencode/evaluator.py +253 -0
  35. agent_s4-0.1.0/harness/opencode/hermes_sanitizer.js +29 -0
  36. agent_s4-0.1.0/harness/opencode/runner.py +399 -0
  37. agent_s4-0.1.0/harness/opencode/source.py +62 -0
  38. agent_s4-0.1.0/harness/opencode/tool_limits.js +21 -0
  39. agent_s4-0.1.0/harness/prime/__init__.py +0 -0
  40. agent_s4-0.1.0/harness/prime/builder.py +331 -0
  41. agent_s4-0.1.0/harness/prime/compaction.py +114 -0
  42. agent_s4-0.1.0/harness/prime/context_window.py +44 -0
  43. agent_s4-0.1.0/harness/prime/evaluator.py +549 -0
  44. agent_s4-0.1.0/harness/prime/ipython_timeout_patch.py +310 -0
  45. agent_s4-0.1.0/harness/prime/openrouter.py +122 -0
  46. agent_s4-0.1.0/harness/prime/overflow_patch.py +58 -0
  47. agent_s4-0.1.0/harness/prime/runner.py +242 -0
  48. agent_s4-0.1.0/harness/prime/source.py +350 -0
  49. agent_s4-0.1.0/harness/prime/step_runner.py +260 -0
  50. agent_s4-0.1.0/harness/prime/temperature.py +42 -0
  51. agent_s4-0.1.0/harness/ubuntu_vm.py +831 -0
  52. agent_s4-0.1.0/operators/__init__.py +0 -0
  53. agent_s4-0.1.0/operators/base.py +18 -0
  54. agent_s4-0.1.0/operators/crossover.py +450 -0
  55. agent_s4-0.1.0/operators/elimination.py +148 -0
  56. agent_s4-0.1.0/operators/migration.py +399 -0
  57. agent_s4-0.1.0/operators/mutation.py +469 -0
  58. agent_s4-0.1.0/operators/reevaluation.py +271 -0
  59. agent_s4-0.1.0/orchestrator.py +863 -0
  60. agent_s4-0.1.0/osworld_v2_preflight.py +856 -0
  61. agent_s4-0.1.0/paths.py +47 -0
  62. agent_s4-0.1.0/pyproject.toml +54 -0
  63. agent_s4-0.1.0/scienceboard_synthetic_runtime.py +291 -0
  64. agent_s4-0.1.0/scoring.py +44 -0
  65. agent_s4-0.1.0/scratch_vm.py +825 -0
  66. agent_s4-0.1.0/setup.cfg +4 -0
  67. agent_s4-0.1.0/state.py +38 -0
  68. agent_s4-0.1.0/synthetic_tasks.py +275 -0
  69. agent_s4-0.1.0/tournament.py +167 -0
  70. agent_s4-0.1.0/utils.py +152 -0
  71. agent_s4-0.1.0/vm/__init__.py +0 -0
  72. agent_s4-0.1.0/vm/owner_tag.py +92 -0
  73. agent_s4-0.1.0/vm/utils.py +672 -0
agent_s4-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,182 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-s4
3
+ Version: 0.1.0
4
+ Summary: Agent S4: evolving tool interfaces for computer-use agents
5
+ Author: Simular AI
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Source, https://github.com/simular-ai/Agent-S
8
+ Project-URL: Paper, https://arxiv.org/abs/2610.28601
9
+ Project-URL: Issues, https://github.com/simular-ai/Agent-S/issues
10
+ Keywords: ai,llm,agent,computer-use,evolution
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Requires-Python: >=3.12
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: boto3
19
+ Requires-Dist: python-dotenv[cli]
20
+ Requires-Dist: requests
21
+ Requires-Dist: playwright
22
+ Dynamic: license-file
23
+
24
+ # agent_s4
25
+
26
+ The Agent S4 package, from the paper
27
+ [Evolving Agent Interfaces](https://arxiv.org/abs/2610.28601). It evolves a
28
+ **shadow interface**: a small Python tool library that a computer-use agent
29
+ imports to operate a desktop. Each step, a **Builder** agent edits an
30
+ interface on the host. A **task agent** then runs benchmark tasks on fresh AWS
31
+ VMs with that interface installed, and its score becomes the variant's
32
+ fitness.
33
+
34
+ This file describes the code. For setup, credentials and the launch scripts
35
+ behind the published runs, see the workspace READMEs in the
36
+ [Agent-S repository](https://github.com/simular-ai/Agent-S):
37
+
38
+ - [`osworld_setup/s4/README.md`](https://github.com/simular-ai/Agent-S/blob/main/osworld_setup/s4/README.md):
39
+ OSWorld-V2, which is the default benchmark.
40
+ - [`scienceboard_setup/s4/README.md`](https://github.com/simular-ai/Agent-S/blob/main/scienceboard_setup/s4/README.md):
41
+ ScienceBoard.
42
+
43
+ ## Install
44
+
45
+ `agent-s4` is its own package; installing `gui-agents` does not include it.
46
+
47
+ The package contains only the code. A run also reads setup files from the
48
+ Agent-S repository: the Builder prompts, the seed interface, the task splits
49
+ and the pinned Prime Agent runtime, all under `osworld_setup/s4/`. So you
50
+ need a clone of the repository either way. Install the package from the
51
+ clone:
52
+
53
+ ```bash
54
+ git clone https://github.com/simular-ai/Agent-S.git
55
+ cd Agent-S
56
+ pip install -e ./agent_s4
57
+ ```
58
+
59
+ or install it from PyPI and point it at the clone:
60
+
61
+ ```bash
62
+ pip install agent-s4
63
+ export SHADOW_EVOL_SHARED_ROOT=/path/to/Agent-S/osworld_setup/s4
64
+ ```
65
+
66
+ Without those files, `python -m agent_s4.cli run` stops and says what to set.
67
+ The benchmark itself (the OSWorld-V2 checkout, AWS and model credentials) is
68
+ set up as described in the workspace READMEs above.
69
+
70
+ ## Entry points
71
+
72
+ | Command | What it does |
73
+ |---|---|
74
+ | `python -m agent_s4.cli run ...` | Starts or resumes an experiment (`--help` lists the options). |
75
+ | `python -m agent_s4.cli rerun --config-path runs/<timestamp>/config.json` | Runs again from a saved config. |
76
+ | `python -m agent_s4.osworld_v2_preflight` | Runs the offline OSWorld-V2 workspace checks on their own. |
77
+ | `python -m agent_s4.eval.osworld_v2 ...`, `python -m agent_s4.eval.scienceboard_prime ...` | Eval workers. The evaluator harness normally starts these; they can also be run by hand on chosen tasks. |
78
+
79
+ `run` defaults to `--benchmark osworld_v2`, which uses the splits pinned in
80
+ `config/osworld_v2_release_pin.json`: `osworld_v2_train_50.json`,
81
+ `osworld_v2_val_25.json` and `osworld_v2_test.json` as the held-out set. No
82
+ train or val splits ship for `--benchmark osworld` (the original OSWorld) or
83
+ `--benchmark scienceboard`, so both require `--train-set` and `--val-set`.
84
+
85
+ ## How a run works
86
+
87
+ **1. Bootstrap** (`orchestrator.run`):
88
+ - If Prime Agent is used, checks its pinned runtime. For OSWorld-V2 it also
89
+ runs the workspace preflight and checks the configured splits against the
90
+ release pin.
91
+ - Makes one clone of the benchmark's Evol checkout per island, named
92
+ `<template>_<island>` (for example `OSWorldV2_Evol_<island>`).
93
+ - Copies the seed interface into the clone's `shadow_interface/` directory,
94
+ which has its own git repository, and records it as the seed variant.
95
+ - Evaluates the seed on every island in parallel, writes the resolved config
96
+ to `runs/<timestamp>/config.json`, and hands over to the driver.
97
+
98
+ **2. Driver loop** (`driver.Driver`):
99
+ - Keeps one global step counter.
100
+ - Each step, the scheduler (`config/scheduler.py`) picks one operator, which
101
+ runs on every island in parallel. The step ends only when all islands have
102
+ finished.
103
+ - Every dispatch is logged in the database, so a step interrupted by a crash
104
+ is resumed rather than run twice.
105
+ - Validation reevaluation runs every `--reevaluation-interval` steps.
106
+ - The loop stops at `--max-steps` or `--max-cost`.
107
+
108
+ **3. Operators** (`operators/`): each step runs one of these.
109
+
110
+ | Operator | What it does |
111
+ |---|---|
112
+ | `mutation` | The usual step; see the sequence below. |
113
+ | `crossover` | The Builder combines two parents from the same island into one child, which is then evaluated like a mutation. |
114
+ | `migration` | Two phases: each island sends a tournament pick to another island, and the receiving island evaluates the migrant with its own task agent before adding it. `--migration-mode` and `--migration-topology` control the details. |
115
+ | `elimination` | Removes the lowest-ranked variants from each island. |
116
+ | `reevaluation` | Evaluates each island's current leaders on validation again and averages the results with their earlier scores. It creates no new variants. |
117
+
118
+ A mutation runs these steps:
119
+ 1. A tournament picks the parent (`tournament.py`).
120
+ 2. The parent is checked out, and its task trajectories are staged for the
121
+ Builder to read.
122
+ 3. Optionally, a scratch VM is started (`scratch_vm.py`) so the Builder can
123
+ try things in a live app.
124
+ 4. The Builder harness edits `shadow_interface/`. For OSWorld-V2 and
125
+ ScienceBoard it runs inside a Landlock sandbox, because the Base checkout
126
+ next to the clone holds the benchmark's gated evaluators.
127
+ 5. Edits outside the allowed scope are reverted, and the child is tagged
128
+ `evol/<island>/if-NNN`.
129
+ 6. The evaluator harness runs the child on the train and val splits. The
130
+ per-task results, scores and costs go into the database.
131
+
132
+ ## Module map
133
+
134
+ | Area | Modules |
135
+ |---|---|
136
+ | Configuration | `cli.py` (argument parsing), `config/experiment.py` (`ExperimentConfig`, default splits per benchmark), `config/island.py`, `config/scheduler.py` |
137
+ | Control loop | `orchestrator.py` (bootstrap and seed eval), `driver.py`, `state.py` (`LoopState`, passed to each operator), `operators/`, `tournament.py`, `scoring.py` |
138
+ | State | `db.py` (SQLite tables: variants, per-task eval results, islands, history, cost events, dispatch log, reevaluation samples), `costs.py`, `git_utils.py` (variant tags and checkouts in each island's `shadow_interface/` repo) |
139
+ | Builder side | `harness/builder_common.py` (shared Builder subprocess and log parsing), `builder_sandbox.py` (Landlock), `builder_scratch_vm.py`, `scratch_vm.py` |
140
+ | Agent harnesses | `harness/prime/`, `harness/opencode/`: each has the Builder (`builder.py`), the task-agent install and VM command (`evaluator.py`), a runner, and pin checks (`source.py`); see the README in each directory. `harness/__init__.py` is the registry. |
141
+ | Evaluation | `harness/ubuntu_vm.py` (`UbuntuVMEvaluator`: starts an eval worker as a subprocess), `eval/osworld.py` (worker code shared by every benchmark), `eval/osworld_v2.py`, `eval/scienceboard_prime.py`, `eval/grader_image_limit.py` |
142
+ | Benchmarks | `benchmark_spec.py` (template and base checkout names, how run artefacts are named), `osworld_v2_preflight.py`, `synthetic_tasks.py`, `scienceboard_synthetic_runtime.py` |
143
+ | VMs | `vm/utils.py` (shared VM helpers), `vm/owner_tag.py` (adds an `Owner` tag to every EC2 instance) |
144
+ | Paths | `paths.py`, `constants.py`, `utils.py` |
145
+
146
+ ## Where files go
147
+
148
+ `paths.py` sets two roots:
149
+
150
+ - **Shared root** (`SHADOW_EVOL_SHARED_ROOT`; defaults to `osworld_setup/s4/`):
151
+ the vendored Prime runtime, `vm_assets/`, the seed interfaces and the generic
152
+ Builder prompts.
153
+ - **Project root** (`SHADOW_EVOL_PROJECT_ROOT`; defaults to the shared root):
154
+ the run workspace. It holds the benchmark's prompts, splits, data, release
155
+ pin, checkouts and every run artefact. The ScienceBoard launchers set it to
156
+ `scienceboard_setup/s4/`.
157
+
158
+ Run artefacts are named per benchmark (and per `SHADOW_EVOL_RUN_NAMESPACE`) by
159
+ `benchmark_spec.ns()`. For example, OSWorld-V2 uses
160
+ `shadow_evolution_osworld_v2_<ns>.db`, `eval_cache_osworld_v2_<ns>/` and
161
+ `builder_logs_osworld_v2_<ns>/`.
162
+
163
+ ## Extending
164
+
165
+ **Add an agent harness:**
166
+ - Subclass `BuilderHarness` (`harness/base.py`) in `harness/<name>/builder.py`.
167
+ - Put the VM install and task-agent command in `harness/<name>/evaluator.py`.
168
+ - Register the key in both `BUILDER_HARNESSES` and `EVALUATOR_HARNESSES`.
169
+ - Teach `UbuntuVMEvaluator` and `eval/osworld.py` to dispatch on the key. Both
170
+ currently accept only `prime_agent` and `opencode`.
171
+ - Pin and verify the upstream release in a `source.py`, and record it in a
172
+ README, as the existing two harnesses do.
173
+
174
+ **Add a benchmark:**
175
+ - Add an entry to `benchmark_spec.BENCHMARKS`, and to `_DEFAULT_SPLITS` in
176
+ `config/experiment.py` if it ships default splits.
177
+ - Write an eval worker that plugs into `eval.osworld.main(impl=...)`, as
178
+ `eval/scienceboard_prime.py` does.
179
+ - The benchmark-specific branches in `harness/ubuntu_vm.py` and
180
+ `orchestrator.py` (search for `config.benchmark ==`) cover how the base
181
+ checkout is chosen, which prompt addenda are added and how splits are
182
+ checked.
@@ -0,0 +1,159 @@
1
+ # agent_s4
2
+
3
+ The Agent S4 package, from the paper
4
+ [Evolving Agent Interfaces](https://arxiv.org/abs/2610.28601). It evolves a
5
+ **shadow interface**: a small Python tool library that a computer-use agent
6
+ imports to operate a desktop. Each step, a **Builder** agent edits an
7
+ interface on the host. A **task agent** then runs benchmark tasks on fresh AWS
8
+ VMs with that interface installed, and its score becomes the variant's
9
+ fitness.
10
+
11
+ This file describes the code. For setup, credentials and the launch scripts
12
+ behind the published runs, see the workspace READMEs in the
13
+ [Agent-S repository](https://github.com/simular-ai/Agent-S):
14
+
15
+ - [`osworld_setup/s4/README.md`](https://github.com/simular-ai/Agent-S/blob/main/osworld_setup/s4/README.md):
16
+ OSWorld-V2, which is the default benchmark.
17
+ - [`scienceboard_setup/s4/README.md`](https://github.com/simular-ai/Agent-S/blob/main/scienceboard_setup/s4/README.md):
18
+ ScienceBoard.
19
+
20
+ ## Install
21
+
22
+ `agent-s4` is its own package; installing `gui-agents` does not include it.
23
+
24
+ The package contains only the code. A run also reads setup files from the
25
+ Agent-S repository: the Builder prompts, the seed interface, the task splits
26
+ and the pinned Prime Agent runtime, all under `osworld_setup/s4/`. So you
27
+ need a clone of the repository either way. Install the package from the
28
+ clone:
29
+
30
+ ```bash
31
+ git clone https://github.com/simular-ai/Agent-S.git
32
+ cd Agent-S
33
+ pip install -e ./agent_s4
34
+ ```
35
+
36
+ or install it from PyPI and point it at the clone:
37
+
38
+ ```bash
39
+ pip install agent-s4
40
+ export SHADOW_EVOL_SHARED_ROOT=/path/to/Agent-S/osworld_setup/s4
41
+ ```
42
+
43
+ Without those files, `python -m agent_s4.cli run` stops and says what to set.
44
+ The benchmark itself (the OSWorld-V2 checkout, AWS and model credentials) is
45
+ set up as described in the workspace READMEs above.
46
+
47
+ ## Entry points
48
+
49
+ | Command | What it does |
50
+ |---|---|
51
+ | `python -m agent_s4.cli run ...` | Starts or resumes an experiment (`--help` lists the options). |
52
+ | `python -m agent_s4.cli rerun --config-path runs/<timestamp>/config.json` | Runs again from a saved config. |
53
+ | `python -m agent_s4.osworld_v2_preflight` | Runs the offline OSWorld-V2 workspace checks on their own. |
54
+ | `python -m agent_s4.eval.osworld_v2 ...`, `python -m agent_s4.eval.scienceboard_prime ...` | Eval workers. The evaluator harness normally starts these; they can also be run by hand on chosen tasks. |
55
+
56
+ `run` defaults to `--benchmark osworld_v2`, which uses the splits pinned in
57
+ `config/osworld_v2_release_pin.json`: `osworld_v2_train_50.json`,
58
+ `osworld_v2_val_25.json` and `osworld_v2_test.json` as the held-out set. No
59
+ train or val splits ship for `--benchmark osworld` (the original OSWorld) or
60
+ `--benchmark scienceboard`, so both require `--train-set` and `--val-set`.
61
+
62
+ ## How a run works
63
+
64
+ **1. Bootstrap** (`orchestrator.run`):
65
+ - If Prime Agent is used, checks its pinned runtime. For OSWorld-V2 it also
66
+ runs the workspace preflight and checks the configured splits against the
67
+ release pin.
68
+ - Makes one clone of the benchmark's Evol checkout per island, named
69
+ `<template>_<island>` (for example `OSWorldV2_Evol_<island>`).
70
+ - Copies the seed interface into the clone's `shadow_interface/` directory,
71
+ which has its own git repository, and records it as the seed variant.
72
+ - Evaluates the seed on every island in parallel, writes the resolved config
73
+ to `runs/<timestamp>/config.json`, and hands over to the driver.
74
+
75
+ **2. Driver loop** (`driver.Driver`):
76
+ - Keeps one global step counter.
77
+ - Each step, the scheduler (`config/scheduler.py`) picks one operator, which
78
+ runs on every island in parallel. The step ends only when all islands have
79
+ finished.
80
+ - Every dispatch is logged in the database, so a step interrupted by a crash
81
+ is resumed rather than run twice.
82
+ - Validation reevaluation runs every `--reevaluation-interval` steps.
83
+ - The loop stops at `--max-steps` or `--max-cost`.
84
+
85
+ **3. Operators** (`operators/`): each step runs one of these.
86
+
87
+ | Operator | What it does |
88
+ |---|---|
89
+ | `mutation` | The usual step; see the sequence below. |
90
+ | `crossover` | The Builder combines two parents from the same island into one child, which is then evaluated like a mutation. |
91
+ | `migration` | Two phases: each island sends a tournament pick to another island, and the receiving island evaluates the migrant with its own task agent before adding it. `--migration-mode` and `--migration-topology` control the details. |
92
+ | `elimination` | Removes the lowest-ranked variants from each island. |
93
+ | `reevaluation` | Evaluates each island's current leaders on validation again and averages the results with their earlier scores. It creates no new variants. |
94
+
95
+ A mutation runs these steps:
96
+ 1. A tournament picks the parent (`tournament.py`).
97
+ 2. The parent is checked out, and its task trajectories are staged for the
98
+ Builder to read.
99
+ 3. Optionally, a scratch VM is started (`scratch_vm.py`) so the Builder can
100
+ try things in a live app.
101
+ 4. The Builder harness edits `shadow_interface/`. For OSWorld-V2 and
102
+ ScienceBoard it runs inside a Landlock sandbox, because the Base checkout
103
+ next to the clone holds the benchmark's gated evaluators.
104
+ 5. Edits outside the allowed scope are reverted, and the child is tagged
105
+ `evol/<island>/if-NNN`.
106
+ 6. The evaluator harness runs the child on the train and val splits. The
107
+ per-task results, scores and costs go into the database.
108
+
109
+ ## Module map
110
+
111
+ | Area | Modules |
112
+ |---|---|
113
+ | Configuration | `cli.py` (argument parsing), `config/experiment.py` (`ExperimentConfig`, default splits per benchmark), `config/island.py`, `config/scheduler.py` |
114
+ | Control loop | `orchestrator.py` (bootstrap and seed eval), `driver.py`, `state.py` (`LoopState`, passed to each operator), `operators/`, `tournament.py`, `scoring.py` |
115
+ | State | `db.py` (SQLite tables: variants, per-task eval results, islands, history, cost events, dispatch log, reevaluation samples), `costs.py`, `git_utils.py` (variant tags and checkouts in each island's `shadow_interface/` repo) |
116
+ | Builder side | `harness/builder_common.py` (shared Builder subprocess and log parsing), `builder_sandbox.py` (Landlock), `builder_scratch_vm.py`, `scratch_vm.py` |
117
+ | Agent harnesses | `harness/prime/`, `harness/opencode/`: each has the Builder (`builder.py`), the task-agent install and VM command (`evaluator.py`), a runner, and pin checks (`source.py`); see the README in each directory. `harness/__init__.py` is the registry. |
118
+ | Evaluation | `harness/ubuntu_vm.py` (`UbuntuVMEvaluator`: starts an eval worker as a subprocess), `eval/osworld.py` (worker code shared by every benchmark), `eval/osworld_v2.py`, `eval/scienceboard_prime.py`, `eval/grader_image_limit.py` |
119
+ | Benchmarks | `benchmark_spec.py` (template and base checkout names, how run artefacts are named), `osworld_v2_preflight.py`, `synthetic_tasks.py`, `scienceboard_synthetic_runtime.py` |
120
+ | VMs | `vm/utils.py` (shared VM helpers), `vm/owner_tag.py` (adds an `Owner` tag to every EC2 instance) |
121
+ | Paths | `paths.py`, `constants.py`, `utils.py` |
122
+
123
+ ## Where files go
124
+
125
+ `paths.py` sets two roots:
126
+
127
+ - **Shared root** (`SHADOW_EVOL_SHARED_ROOT`; defaults to `osworld_setup/s4/`):
128
+ the vendored Prime runtime, `vm_assets/`, the seed interfaces and the generic
129
+ Builder prompts.
130
+ - **Project root** (`SHADOW_EVOL_PROJECT_ROOT`; defaults to the shared root):
131
+ the run workspace. It holds the benchmark's prompts, splits, data, release
132
+ pin, checkouts and every run artefact. The ScienceBoard launchers set it to
133
+ `scienceboard_setup/s4/`.
134
+
135
+ Run artefacts are named per benchmark (and per `SHADOW_EVOL_RUN_NAMESPACE`) by
136
+ `benchmark_spec.ns()`. For example, OSWorld-V2 uses
137
+ `shadow_evolution_osworld_v2_<ns>.db`, `eval_cache_osworld_v2_<ns>/` and
138
+ `builder_logs_osworld_v2_<ns>/`.
139
+
140
+ ## Extending
141
+
142
+ **Add an agent harness:**
143
+ - Subclass `BuilderHarness` (`harness/base.py`) in `harness/<name>/builder.py`.
144
+ - Put the VM install and task-agent command in `harness/<name>/evaluator.py`.
145
+ - Register the key in both `BUILDER_HARNESSES` and `EVALUATOR_HARNESSES`.
146
+ - Teach `UbuntuVMEvaluator` and `eval/osworld.py` to dispatch on the key. Both
147
+ currently accept only `prime_agent` and `opencode`.
148
+ - Pin and verify the upstream release in a `source.py`, and record it in a
149
+ README, as the existing two harnesses do.
150
+
151
+ **Add a benchmark:**
152
+ - Add an entry to `benchmark_spec.BENCHMARKS`, and to `_DEFAULT_SPLITS` in
153
+ `config/experiment.py` if it ships default splits.
154
+ - Write an eval worker that plugs into `eval.osworld.main(impl=...)`, as
155
+ `eval/scienceboard_prime.py` does.
156
+ - The benchmark-specific branches in `harness/ubuntu_vm.py` and
157
+ `orchestrator.py` (search for `config.benchmark ==`) cover how the base
158
+ checkout is chosen, which prompt addenda are added and how splits are
159
+ checked.
@@ -0,0 +1,32 @@
1
+ """Shadow interface evolution framework.
2
+
3
+ Side-effect on import: set PROXY_CONFIG_FILE to an OSWorld template copy
4
+ if the env var isn't already set and one of the templates carries it.
5
+
6
+ This has to happen BEFORE `desktop_env` is imported anywhere under
7
+ agent_s4/, because desktop_env.controllers.setup initializes its
8
+ global ProxyPool from PROXY_CONFIG_FILE at module-import time. The
9
+ default is a cwd-relative path that only resolves when run from inside
10
+ a clone — the orchestrator runs from the repo root, one level up.
11
+
12
+ Both OSWorld templates ship the same dataimpulse.json, so the first one
13
+ present wins; a checkout with only one of them still resolves.
14
+ """
15
+
16
+ import os
17
+
18
+ from agent_s4.paths import PROJECT_ROOT as _REPO_ROOT
19
+
20
+ if "PROXY_CONFIG_FILE" not in os.environ:
21
+ for _template in ("OSWorld_Evol", "OSWorldV2_Evol"):
22
+ _proxy = (
23
+ _REPO_ROOT
24
+ / _template
25
+ / "evaluation_examples"
26
+ / "settings"
27
+ / "proxy"
28
+ / "dataimpulse.json"
29
+ )
30
+ if _proxy.is_file():
31
+ os.environ["PROXY_CONFIG_FILE"] = str(_proxy)
32
+ break