legatolabs 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 (38) hide show
  1. legatolabs-0.1.0/LICENSE +202 -0
  2. legatolabs-0.1.0/NOTICE +28 -0
  3. legatolabs-0.1.0/PKG-INFO +185 -0
  4. legatolabs-0.1.0/README.md +135 -0
  5. legatolabs-0.1.0/legato/__init__.py +16 -0
  6. legatolabs-0.1.0/legato/__main__.py +72 -0
  7. legatolabs-0.1.0/legato/actions.py +166 -0
  8. legatolabs-0.1.0/legato/env.py +274 -0
  9. legatolabs-0.1.0/legato/harness.py +374 -0
  10. legatolabs-0.1.0/legato/hosted.py +133 -0
  11. legatolabs-0.1.0/legato/mcp_server.py +127 -0
  12. legatolabs-0.1.0/legato/prompt.py +40 -0
  13. legatolabs-0.1.0/legato/rl/__init__.py +14 -0
  14. legatolabs-0.1.0/legato/rl/__main__.py +96 -0
  15. legatolabs-0.1.0/legato/rl/bench/__init__.py +1 -0
  16. legatolabs-0.1.0/legato/rl/bench/h2h.py +155 -0
  17. legatolabs-0.1.0/legato/rl/bench/office.py +362 -0
  18. legatolabs-0.1.0/legato/rl/bench/replay.py +126 -0
  19. legatolabs-0.1.0/legato/rl/collect.py +417 -0
  20. legatolabs-0.1.0/legato/rl/fake.py +83 -0
  21. legatolabs-0.1.0/legato/rl/osworld_env.py +394 -0
  22. legatolabs-0.1.0/legato/rl/policy.py +160 -0
  23. legatolabs-0.1.0/legato/rl/profile.py +58 -0
  24. legatolabs-0.1.0/legato/rl/trajectory.py +140 -0
  25. legatolabs-0.1.0/legato/settle.py +106 -0
  26. legatolabs-0.1.0/legatolabs.egg-info/PKG-INFO +185 -0
  27. legatolabs-0.1.0/legatolabs.egg-info/SOURCES.txt +36 -0
  28. legatolabs-0.1.0/legatolabs.egg-info/dependency_links.txt +1 -0
  29. legatolabs-0.1.0/legatolabs.egg-info/entry_points.txt +2 -0
  30. legatolabs-0.1.0/legatolabs.egg-info/requires.txt +26 -0
  31. legatolabs-0.1.0/legatolabs.egg-info/top_level.txt +1 -0
  32. legatolabs-0.1.0/pyproject.toml +52 -0
  33. legatolabs-0.1.0/setup.cfg +4 -0
  34. legatolabs-0.1.0/tests/test_harness.py +209 -0
  35. legatolabs-0.1.0/tests/test_mcp.py +55 -0
  36. legatolabs-0.1.0/tests/test_office_bench.py +128 -0
  37. legatolabs-0.1.0/tests/test_rl.py +199 -0
  38. legatolabs-0.1.0/tests/test_sdk.py +127 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,28 @@
1
+ Legato
2
+ Copyright 2026 the Legato authors
3
+
4
+ This product includes software from the following projects:
5
+
6
+ - OSWorld (https://github.com/xlang-ai/OSWorld), Apache License 2.0.
7
+ `legato/rl/osworld_env.py` subclasses OSWorld's DesktopEnv. `LegatoDesktopEnv.step` is DesktopEnv.step from commit
8
+ 8903ebeb0efdf74331bd7dc37ed91ccbbff22317, modified: the final fixed sleep before the observation is replaced by the
9
+ configured wait.
10
+
11
+ - Anthropic computer-use demo (https://github.com/anthropics/claude-quickstarts, computer-use-demo), MIT License,
12
+ Copyright 2024 Anthropic, PBC. (computer-use-demo/LICENSE)
13
+ `legato/harness.py` (`REFERENCE_SYSTEM`) quotes two lines of the demo's system prompt. `Harness.reference`
14
+ re-implements the demo's loop behaviour: a 2 s screenshot delay, a screenshot per action, the screenshot sizes and
15
+ keep-all history. The MIT license text follows.
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
18
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
19
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
20
+ permit persons to whom the Software is furnished to do so, subject to the following conditions:
21
+
22
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of
23
+ the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
26
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
27
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.4
2
+ Name: legatolabs
3
+ Version: 0.1.0
4
+ Summary: Open computer-use harness for any OpenAI-compatible model (Qwen, DeepSeek, Claude, vLLM, OpenRouter): ready-wait instead of fixed sleeps, bounded calls, measured against the reference loops.
5
+ Author: Legato authors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://legato.computer
8
+ Project-URL: Documentation, https://legato.computer/docs
9
+ Project-URL: Benchmarks, https://legato.computer/docs/benchmarks
10
+ Project-URL: Source, https://github.com/legatolabs/legato
11
+ Project-URL: Issues, https://github.com/legatolabs/legato/issues
12
+ Keywords: computer-use,computer use agent,gui agent,desktop agent,osworld,qwen,openrouter,vllm,e2b,llm agents,reinforcement learning,rollouts
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Software Development :: Libraries
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ License-File: NOTICE
28
+ Requires-Dist: httpx>=0.27
29
+ Requires-Dist: Pillow>=10
30
+ Provides-Extra: e2b
31
+ Requires-Dist: e2b-desktop>=2.7; extra == "e2b"
32
+ Provides-Extra: office
33
+ Requires-Dist: python-pptx>=1.0; extra == "office"
34
+ Requires-Dist: openpyxl>=3.1; extra == "office"
35
+ Provides-Extra: mcp
36
+ Requires-Dist: mcp>=1.2; extra == "mcp"
37
+ Provides-Extra: video
38
+ Requires-Dist: imageio>=2.30; extra == "video"
39
+ Requires-Dist: imageio-ffmpeg>=0.5; extra == "video"
40
+ Requires-Dist: numpy; extra == "video"
41
+ Provides-Extra: dev
42
+ Requires-Dist: pytest>=8; extra == "dev"
43
+ Requires-Dist: mcp>=1.2; extra == "dev"
44
+ Requires-Dist: python-pptx>=1.0; extra == "dev"
45
+ Requires-Dist: openpyxl>=3.1; extra == "dev"
46
+ Requires-Dist: imageio>=2.30; extra == "dev"
47
+ Requires-Dist: imageio-ffmpeg>=0.5; extra == "dev"
48
+ Requires-Dist: numpy; extra == "dev"
49
+ Dynamic: license-file
50
+
51
+ # Legato
52
+
53
+ **Legato is an open-source computer-use harness for any OpenAI-compatible model** (Qwen, DeepSeek, Claude, or your
54
+ own vLLM or SGLang server, directly or through OpenRouter). It drives a desktop sandbox (E2B, or any sandbox you can
55
+ screenshot and send input to) with a Claude-style `computer` tool. It waits until the screen is ready instead of
56
+ sleeping a fixed time, and it bounds every model call. Apache-2.0.
57
+
58
+ ```bash
59
+ pip install "legatolabs[e2b]" # the package is legatolabs on PyPI; you import it as `legato`
60
+ ```
61
+
62
+ ## Results
63
+
64
+ Same model, same desktops, same tasks, all arms run at the same time. The tasks are 24 Excel-to-PowerPoint office
65
+ workflows on real Ubuntu desktops (LibreOffice). Times are agent time: first screenshot to last model turn. Ranges are
66
+ 95% task-bootstrap intervals. Full method, raw data and losses: [docs/benchmarks.md](docs/benchmarks.md).
67
+
68
+ | Model | Legato compared with | Time | Success |
69
+ |---|---|---|---|
70
+ | Claude Sonnet 5.5 | Anthropic's computer-use reference loop (re-implemented) | **1.48x faster** (0.678 [0.604, 0.757]) | 48/48 vs 48/48 |
71
+ | Qwen3.8-27B | OSWorld's Qwen agent scaffold (`mm_agents/qwen`) | about the same (0.953 [0.798, 1.134]) | **71/96 vs 53/96** (74% vs 55%, two runs) |
72
+
73
+ - **The Claude result** is one run. The saving is almost all fixed waiting: 14 s vs 45 s per task. Model time is the
74
+ same.
75
+ - **The Qwen success gain** held on two independent task sets: +21 and +17 points.
76
+ - **The Qwen speed result.** In the first run, OSWorld's agent let four rollouts generate up to 32,768 tokens in one
77
+ reply, so Legato looked 2.4x faster. On fresh tasks, without those runaways, the two are tied. We report the tie.
78
+ - On OSWorld tasks with OSWorld's own harness (120 tasks, Qwen3.5-9B), Legato's ready-wait and fast reset cut task
79
+ time to 0.52 [0.43, 0.65] of the 5 s fixed-wait setting, at equal success. That is not an official OSWorld-Verified
80
+ submission.
81
+
82
+ ## Quickstart
83
+
84
+ An open model through OpenRouter, on an E2B desktop:
85
+
86
+ ```python
87
+ import os
88
+ import legato
89
+ from e2b_desktop import Sandbox
90
+
91
+ agent = legato.Harness(model="qwen/qwen3.8-27b", base_url="https://openrouter.ai/api/v1",
92
+ api_key=os.environ["OPENROUTER_API_KEY"])
93
+ desk = Sandbox.create() # needs E2B_API_KEY
94
+ try:
95
+ result = agent.run("Open the terminal and print the date", legato.attach(desk), max_steps=30)
96
+ print(result.report()) # where the time went: model, actions, waiting for the screen
97
+ finally:
98
+ desk.kill()
99
+ ```
100
+
101
+ The same harness works with Claude: `legato.Harness(model="anthropic/claude-sonnet-5.5", ...)`. It switches to pixel
102
+ coordinates and Anthropic's recommended screenshot size. It also works with your own server:
103
+ `base_url="http://localhost:8000/v1"`. From the command line:
104
+
105
+ ```bash
106
+ legato run "Open the terminal and print the date" --model qwen/qwen3.8-27b --base-url https://openrouter.ai/api/v1
107
+ ```
108
+
109
+ Any sandbox, without E2B: pass a screenshot function and an action executor.
110
+
111
+ ```python
112
+ env = legato.attach(screenshot=lambda: png_bytes(), execute=lambda action: send_input(action))
113
+ ```
114
+
115
+ `action` is a `legato.Action` (`type` click / double_click / right_click / type / key / scroll / drag / wait, with
116
+ pixel `x`, `y`, `text`, `keys`). More in [docs/sandboxes.md](docs/sandboxes.md) and [docs/models.md](docs/models.md).
117
+
118
+ ## What it does differently
119
+
120
+ | | Legato | Typical reference loop |
121
+ |---|---|---|
122
+ | After each action | waits until the screen stops changing; on E2B the check runs inside the sandbox in one call | fixed sleep (Anthropic's demo: 2 s; OSWorld runners: 0–5 s) |
123
+ | Actions per turn | up to 3, one screenshot after them | one per call, or all returned with a screenshot after each |
124
+ | Screenshot history | old screenshots dropped 4 at a time past 8, so the provider's prompt cache keeps hitting | all kept, or one dropped per step |
125
+ | Model calls | timeout, retry, 4,096-token budget; a reply cut off before acting gets a note on the next turn | often unbounded |
126
+ | Timing | `result.report()` splits each run into model, action, waiting and screenshot time | none |
127
+
128
+ `legato.Harness.reference(...)` is a re-implementation of Anthropic's reference loop on the same plumbing, so you can
129
+ measure the difference on your own tasks.
130
+
131
+ ## Reproduce the benchmarks
132
+
133
+ ```bash
134
+ pip install "legatolabs[office,video]"
135
+ legato bench office generate --out bench --repeat 2 # 24 tasks: .xlsx data, .pptx decks, grader specs
136
+ legato rl collect --tasks bench/tasks.json --harness legato --policy-url https://openrouter.ai/api/v1 \
137
+ --model qwen/qwen3.8-27b --api-key-env OPENROUTER_API_KEY --eval-only --osworld ~/OSWorld \
138
+ --version legato --out runs/legato --desktops 6 --group 2 --max-steps 25
139
+ legato rl collect ... --harness qwen --no-ready-signal --fixed-wait 0 --version qwen-osworld --out runs/qwen-osworld
140
+ legato bench h2h --tasks bench/tasks.json --arm qwen-osworld=runs/qwen-osworld --arm legato=runs/legato \
141
+ --ref qwen-osworld --out report
142
+ ```
143
+
144
+ The desktops are OSWorld's Docker VMs, so you need a Linux host with KVM and an
145
+ [OSWorld](https://github.com/xlang-ai/OSWorld) checkout. See [docs/benchmarks.md](docs/benchmarks.md).
146
+
147
+ ## Comparisons and migration
148
+
149
+ - [Legato vs Anthropic's computer-use demo](docs/compare/anthropic-computer-use-demo.md)
150
+ - [Legato vs OSWorld's Qwen agent](docs/compare/osworld-qwen-agent.md)
151
+ - [Legato vs Agent S3](docs/compare/agent-s3.md)
152
+ - [Legato vs UI-TARS-desktop](docs/compare/ui-tars-desktop.md)
153
+ - [Migrating from cua-agent](docs/migrate/from-cua-agent.md) (cua-agent is no longer maintained)
154
+ - [Migrating from Bytebot](docs/migrate/from-bytebot.md) (Bytebot is archived)
155
+
156
+ ## MCP server
157
+
158
+ `legato mcp` gives Claude Code, Cursor or any MCP client a cloud desktop. Each action returns once the screen has
159
+ settled, with the new screenshot. See [docs/mcp.md](docs/mcp.md).
160
+
161
+ ```bash
162
+ pip install "legatolabs[e2b,mcp]"
163
+ claude mcp add legato -e E2B_API_KEY=your_key -- legato mcp
164
+ ```
165
+
166
+ ## RL rollouts
167
+
168
+ `legato rl` collects graded desktop rollouts for computer-use RL. It records token logprobs and token ids, runs
169
+ GRPO-style groups with oversampling and straggler cancel, caps in-flight requests, and profiles each batch. You bring
170
+ the model server and the trainer. See [docs/rl.md](docs/rl.md).
171
+
172
+ ## FAQ
173
+
174
+ - **Why `pip install legatolabs` but `import legato`?** The PyPI name `legato` was taken, so the package is published as
175
+ `legatolabs`. The module, the command line tool and the docs all use `legato`.
176
+ - **Is Legato an alternative to cua-agent or Bytebot?** Yes, for the agent loop. Both are no longer maintained; see
177
+ the migration guides above.
178
+ - **Which models work?** Any model behind an OpenAI-compatible chat API that accepts images. Native tool calls are
179
+ used when the server supports them; otherwise JSON in the reply text is parsed. Measured so far: Claude Sonnet 5.5
180
+ and Qwen3.8-27B. See [docs/models.md](docs/models.md).
181
+ - **Does it need a GPU?** No. Point it at a hosted API or your own server.
182
+ - **Is there a hosted version?** Optional: [legato.computer](https://legato.computer) runs desktops with pause,
183
+ resume and fork. Nothing in this package requires it.
184
+
185
+ More in [docs/faq.md](docs/faq.md). License: Apache-2.0.
@@ -0,0 +1,135 @@
1
+ # Legato
2
+
3
+ **Legato is an open-source computer-use harness for any OpenAI-compatible model** (Qwen, DeepSeek, Claude, or your
4
+ own vLLM or SGLang server, directly or through OpenRouter). It drives a desktop sandbox (E2B, or any sandbox you can
5
+ screenshot and send input to) with a Claude-style `computer` tool. It waits until the screen is ready instead of
6
+ sleeping a fixed time, and it bounds every model call. Apache-2.0.
7
+
8
+ ```bash
9
+ pip install "legatolabs[e2b]" # the package is legatolabs on PyPI; you import it as `legato`
10
+ ```
11
+
12
+ ## Results
13
+
14
+ Same model, same desktops, same tasks, all arms run at the same time. The tasks are 24 Excel-to-PowerPoint office
15
+ workflows on real Ubuntu desktops (LibreOffice). Times are agent time: first screenshot to last model turn. Ranges are
16
+ 95% task-bootstrap intervals. Full method, raw data and losses: [docs/benchmarks.md](docs/benchmarks.md).
17
+
18
+ | Model | Legato compared with | Time | Success |
19
+ |---|---|---|---|
20
+ | Claude Sonnet 5.5 | Anthropic's computer-use reference loop (re-implemented) | **1.48x faster** (0.678 [0.604, 0.757]) | 48/48 vs 48/48 |
21
+ | Qwen3.8-27B | OSWorld's Qwen agent scaffold (`mm_agents/qwen`) | about the same (0.953 [0.798, 1.134]) | **71/96 vs 53/96** (74% vs 55%, two runs) |
22
+
23
+ - **The Claude result** is one run. The saving is almost all fixed waiting: 14 s vs 45 s per task. Model time is the
24
+ same.
25
+ - **The Qwen success gain** held on two independent task sets: +21 and +17 points.
26
+ - **The Qwen speed result.** In the first run, OSWorld's agent let four rollouts generate up to 32,768 tokens in one
27
+ reply, so Legato looked 2.4x faster. On fresh tasks, without those runaways, the two are tied. We report the tie.
28
+ - On OSWorld tasks with OSWorld's own harness (120 tasks, Qwen3.5-9B), Legato's ready-wait and fast reset cut task
29
+ time to 0.52 [0.43, 0.65] of the 5 s fixed-wait setting, at equal success. That is not an official OSWorld-Verified
30
+ submission.
31
+
32
+ ## Quickstart
33
+
34
+ An open model through OpenRouter, on an E2B desktop:
35
+
36
+ ```python
37
+ import os
38
+ import legato
39
+ from e2b_desktop import Sandbox
40
+
41
+ agent = legato.Harness(model="qwen/qwen3.8-27b", base_url="https://openrouter.ai/api/v1",
42
+ api_key=os.environ["OPENROUTER_API_KEY"])
43
+ desk = Sandbox.create() # needs E2B_API_KEY
44
+ try:
45
+ result = agent.run("Open the terminal and print the date", legato.attach(desk), max_steps=30)
46
+ print(result.report()) # where the time went: model, actions, waiting for the screen
47
+ finally:
48
+ desk.kill()
49
+ ```
50
+
51
+ The same harness works with Claude: `legato.Harness(model="anthropic/claude-sonnet-5.5", ...)`. It switches to pixel
52
+ coordinates and Anthropic's recommended screenshot size. It also works with your own server:
53
+ `base_url="http://localhost:8000/v1"`. From the command line:
54
+
55
+ ```bash
56
+ legato run "Open the terminal and print the date" --model qwen/qwen3.8-27b --base-url https://openrouter.ai/api/v1
57
+ ```
58
+
59
+ Any sandbox, without E2B: pass a screenshot function and an action executor.
60
+
61
+ ```python
62
+ env = legato.attach(screenshot=lambda: png_bytes(), execute=lambda action: send_input(action))
63
+ ```
64
+
65
+ `action` is a `legato.Action` (`type` click / double_click / right_click / type / key / scroll / drag / wait, with
66
+ pixel `x`, `y`, `text`, `keys`). More in [docs/sandboxes.md](docs/sandboxes.md) and [docs/models.md](docs/models.md).
67
+
68
+ ## What it does differently
69
+
70
+ | | Legato | Typical reference loop |
71
+ |---|---|---|
72
+ | After each action | waits until the screen stops changing; on E2B the check runs inside the sandbox in one call | fixed sleep (Anthropic's demo: 2 s; OSWorld runners: 0–5 s) |
73
+ | Actions per turn | up to 3, one screenshot after them | one per call, or all returned with a screenshot after each |
74
+ | Screenshot history | old screenshots dropped 4 at a time past 8, so the provider's prompt cache keeps hitting | all kept, or one dropped per step |
75
+ | Model calls | timeout, retry, 4,096-token budget; a reply cut off before acting gets a note on the next turn | often unbounded |
76
+ | Timing | `result.report()` splits each run into model, action, waiting and screenshot time | none |
77
+
78
+ `legato.Harness.reference(...)` is a re-implementation of Anthropic's reference loop on the same plumbing, so you can
79
+ measure the difference on your own tasks.
80
+
81
+ ## Reproduce the benchmarks
82
+
83
+ ```bash
84
+ pip install "legatolabs[office,video]"
85
+ legato bench office generate --out bench --repeat 2 # 24 tasks: .xlsx data, .pptx decks, grader specs
86
+ legato rl collect --tasks bench/tasks.json --harness legato --policy-url https://openrouter.ai/api/v1 \
87
+ --model qwen/qwen3.8-27b --api-key-env OPENROUTER_API_KEY --eval-only --osworld ~/OSWorld \
88
+ --version legato --out runs/legato --desktops 6 --group 2 --max-steps 25
89
+ legato rl collect ... --harness qwen --no-ready-signal --fixed-wait 0 --version qwen-osworld --out runs/qwen-osworld
90
+ legato bench h2h --tasks bench/tasks.json --arm qwen-osworld=runs/qwen-osworld --arm legato=runs/legato \
91
+ --ref qwen-osworld --out report
92
+ ```
93
+
94
+ The desktops are OSWorld's Docker VMs, so you need a Linux host with KVM and an
95
+ [OSWorld](https://github.com/xlang-ai/OSWorld) checkout. See [docs/benchmarks.md](docs/benchmarks.md).
96
+
97
+ ## Comparisons and migration
98
+
99
+ - [Legato vs Anthropic's computer-use demo](docs/compare/anthropic-computer-use-demo.md)
100
+ - [Legato vs OSWorld's Qwen agent](docs/compare/osworld-qwen-agent.md)
101
+ - [Legato vs Agent S3](docs/compare/agent-s3.md)
102
+ - [Legato vs UI-TARS-desktop](docs/compare/ui-tars-desktop.md)
103
+ - [Migrating from cua-agent](docs/migrate/from-cua-agent.md) (cua-agent is no longer maintained)
104
+ - [Migrating from Bytebot](docs/migrate/from-bytebot.md) (Bytebot is archived)
105
+
106
+ ## MCP server
107
+
108
+ `legato mcp` gives Claude Code, Cursor or any MCP client a cloud desktop. Each action returns once the screen has
109
+ settled, with the new screenshot. See [docs/mcp.md](docs/mcp.md).
110
+
111
+ ```bash
112
+ pip install "legatolabs[e2b,mcp]"
113
+ claude mcp add legato -e E2B_API_KEY=your_key -- legato mcp
114
+ ```
115
+
116
+ ## RL rollouts
117
+
118
+ `legato rl` collects graded desktop rollouts for computer-use RL. It records token logprobs and token ids, runs
119
+ GRPO-style groups with oversampling and straggler cancel, caps in-flight requests, and profiles each batch. You bring
120
+ the model server and the trainer. See [docs/rl.md](docs/rl.md).
121
+
122
+ ## FAQ
123
+
124
+ - **Why `pip install legatolabs` but `import legato`?** The PyPI name `legato` was taken, so the package is published as
125
+ `legatolabs`. The module, the command line tool and the docs all use `legato`.
126
+ - **Is Legato an alternative to cua-agent or Bytebot?** Yes, for the agent loop. Both are no longer maintained; see
127
+ the migration guides above.
128
+ - **Which models work?** Any model behind an OpenAI-compatible chat API that accepts images. Native tool calls are
129
+ used when the server supports them; otherwise JSON in the reply text is parsed. Measured so far: Claude Sonnet 5.5
130
+ and Qwen3.8-27B. See [docs/models.md](docs/models.md).
131
+ - **Does it need a GPU?** No. Point it at a hosted API or your own server.
132
+ - **Is there a hosted version?** Optional: [legato.computer](https://legato.computer) runs desktops with pause,
133
+ resume and fork. Nothing in this package requires it.
134
+
135
+ More in [docs/faq.md](docs/faq.md). License: Apache-2.0.
@@ -0,0 +1,16 @@
1
+ """legato: an open computer-use harness for any OpenAI-compatible model. https://legato.computer
2
+
3
+ agent = legato.Harness(model, base_url, api_key)
4
+ result = agent.run(task, legato.attach(sandbox))
5
+
6
+ The optional hosted API (legato.computer) lives in `legato.hosted`.
7
+ """
8
+ from legato import hosted
9
+ from legato.actions import Action, parse
10
+ from legato.env import Env, Obs, attach
11
+ from legato.harness import Harness, RunResult, computer_tool
12
+ from legato.settle import Waiter, wrap
13
+
14
+ __all__ = ["Action", "Env", "Harness", "Obs", "RunResult", "Waiter", "attach", "computer_tool", "hosted", "parse",
15
+ "wrap"]
16
+ __version__ = "0.1.0"
@@ -0,0 +1,72 @@
1
+ """legato command line.
2
+
3
+ legato run "Add a Total row under the table and save" \\
4
+ --model qwen/qwen3-vl-235b-a22b-instruct --base-url https://openrouter.ai/api/v1 [--api-key-env OPENROUTER_API_KEY]
5
+ [--max-steps 30] [--coords norm1000|pixels] [--sandbox e2b]
6
+
7
+ Runs the open harness on a fresh E2B Desktop sandbox (needs `pip install "legatolabs[e2b]"` and E2B_API_KEY) and prints
8
+ where the time went.
9
+
10
+ legato bench office generate|report ... the Legato Office Bench (Excel to PowerPoint tasks)
11
+ legato bench h2h --tasks ... --arm a=DIR --arm b=DIR --ref a --out DIR compare harness runs
12
+ legato rl probe|collect|export|profile ... graded rollouts for RL (see docs/rl.md)
13
+ legato mcp an MCP server: cloud desktops for any agent (see docs/mcp.md)
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import argparse
18
+ import os
19
+ import sys
20
+
21
+
22
+ def main(argv=None) -> int:
23
+ argv = sys.argv[1:] if argv is None else list(argv)
24
+ if argv[:1] == ["rl"]:
25
+ from legato.rl.__main__ import main as rl_main
26
+ return rl_main(argv[1:])
27
+ if argv[:1] == ["mcp"]:
28
+ from legato.mcp_server import main as mcp_main
29
+ return mcp_main(argv[1:])
30
+ if argv[:1] == ["bench"]:
31
+ which = argv[1] if len(argv) > 1 else ""
32
+ if which == "office":
33
+ from legato.rl.bench.office import main as office_main
34
+ return office_main(argv[2:])
35
+ if which == "h2h":
36
+ from legato.rl.bench.h2h import main as h2h_main
37
+ return h2h_main(argv[2:])
38
+ print("usage: legato bench office|h2h ...", file=sys.stderr)
39
+ return 2
40
+ ap = argparse.ArgumentParser(prog="legato", epilog="also: legato bench office|h2h ... (benchmarks), "
41
+ "legato rl probe|collect|export|profile ... (RL rollouts), legato mcp (MCP server)")
42
+ sub = ap.add_subparsers(dest="cmd", required=True)
43
+ r = sub.add_parser("run", help="run one task with the open harness on a fresh sandbox")
44
+ r.add_argument("task")
45
+ r.add_argument("--model", required=True)
46
+ r.add_argument("--base-url", required=True, help="OpenAI-compatible root, e.g. https://openrouter.ai/api/v1")
47
+ r.add_argument("--api-key-env", default="OPENROUTER_API_KEY")
48
+ r.add_argument("--max-steps", type=int, default=30)
49
+ r.add_argument("--coords", default=None, choices=["norm1000", "pixels"],
50
+ help="default: pixels for Claude models, norm1000 (0-1000 grid) otherwise")
51
+ r.add_argument("--sandbox", default="e2b", choices=["e2b"])
52
+ a = ap.parse_args(argv)
53
+ from legato import Harness, attach
54
+ try:
55
+ from e2b_desktop import Sandbox
56
+ except ImportError:
57
+ print('E2B Desktop is not installed: pip install "legatolabs[e2b]"', file=sys.stderr)
58
+ return 2
59
+ agent = Harness(model=a.model, base_url=a.base_url, api_key=os.environ.get(a.api_key_env, ""), coords=a.coords)
60
+ desk = Sandbox.create()
61
+ try:
62
+ res = agent.run(a.task, attach(desk), max_steps=a.max_steps,
63
+ on_step=lambda i, acts, t: print(f"turn {i + 1}: {', '.join(x.describe() for x in acts) or '-'} "
64
+ f"(model {t['model_s']:.1f} s, waiting {t['settle_s']:.1f} s)"))
65
+ finally:
66
+ desk.kill()
67
+ print(res.report())
68
+ return 0 if res.done else 1
69
+
70
+
71
+ if __name__ == "__main__":
72
+ sys.exit(main())