leagents 0.0.4__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 (49) hide show
  1. leagents-0.0.4/LICENSE +202 -0
  2. leagents-0.0.4/PKG-INFO +106 -0
  3. leagents-0.0.4/README.md +79 -0
  4. leagents-0.0.4/leagents/__init__.py +3 -0
  5. leagents-0.0.4/leagents/agents/__init__.py +21 -0
  6. leagents-0.0.4/leagents/agents/base.py +42 -0
  7. leagents-0.0.4/leagents/agents/data_agent.py +38 -0
  8. leagents-0.0.4/leagents/agents/eval_agent.py +105 -0
  9. leagents-0.0.4/leagents/agents/improve_agent.py +140 -0
  10. leagents-0.0.4/leagents/agents/knowledge_agent.py +156 -0
  11. leagents-0.0.4/leagents/agents/train_agent.py +98 -0
  12. leagents-0.0.4/leagents/cli.py +155 -0
  13. leagents-0.0.4/leagents/config.py +125 -0
  14. leagents-0.0.4/leagents/contracts/__init__.py +3 -0
  15. leagents-0.0.4/leagents/contracts/records.py +46 -0
  16. leagents-0.0.4/leagents/dashboard/__init__.py +0 -0
  17. leagents-0.0.4/leagents/dashboard/server.py +142 -0
  18. leagents-0.0.4/leagents/dashboard/static/index.html +302 -0
  19. leagents-0.0.4/leagents/events/__init__.py +3 -0
  20. leagents-0.0.4/leagents/events/bus.py +44 -0
  21. leagents-0.0.4/leagents/llm/__init__.py +3 -0
  22. leagents-0.0.4/leagents/llm/adapter.py +93 -0
  23. leagents-0.0.4/leagents/orchestrator/__init__.py +23 -0
  24. leagents-0.0.4/leagents/orchestrator/constitution.py +59 -0
  25. leagents-0.0.4/leagents/orchestrator/decision.py +51 -0
  26. leagents-0.0.4/leagents/orchestrator/loop.py +182 -0
  27. leagents-0.0.4/leagents/orchestrator/proposer.py +111 -0
  28. leagents-0.0.4/leagents/scripts/__init__.py +0 -0
  29. leagents-0.0.4/leagents/scripts/collect_rollouts.py +169 -0
  30. leagents-0.0.4/leagents/store/__init__.py +3 -0
  31. leagents-0.0.4/leagents/store/jobstore.py +132 -0
  32. leagents-0.0.4/leagents.egg-info/PKG-INFO +106 -0
  33. leagents-0.0.4/leagents.egg-info/SOURCES.txt +47 -0
  34. leagents-0.0.4/leagents.egg-info/dependency_links.txt +1 -0
  35. leagents-0.0.4/leagents.egg-info/entry_points.txt +2 -0
  36. leagents-0.0.4/leagents.egg-info/requires.txt +16 -0
  37. leagents-0.0.4/leagents.egg-info/top_level.txt +1 -0
  38. leagents-0.0.4/pyproject.toml +43 -0
  39. leagents-0.0.4/setup.cfg +4 -0
  40. leagents-0.0.4/tests/test_agents.py +95 -0
  41. leagents-0.0.4/tests/test_constitution.py +36 -0
  42. leagents-0.0.4/tests/test_dashboard.py +95 -0
  43. leagents-0.0.4/tests/test_decision.py +64 -0
  44. leagents-0.0.4/tests/test_improve.py +215 -0
  45. leagents-0.0.4/tests/test_knowledge.py +97 -0
  46. leagents-0.0.4/tests/test_llm.py +23 -0
  47. leagents-0.0.4/tests/test_llm_proposer.py +45 -0
  48. leagents-0.0.4/tests/test_loop.py +125 -0
  49. leagents-0.0.4/tests/test_store.py +25 -0
leagents-0.0.4/LICENSE ADDED
@@ -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,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: leagents
3
+ Version: 0.0.4
4
+ Summary: LeAgents — agentic orchestration for the LeRobot pipeline: collect -> train -> eval -> improve
5
+ Author: ratel
6
+ License: Apache-2.0
7
+ Project-URL: Repository, https://github.com/ratelcode/LeAgents
8
+ Project-URL: Documentation, https://github.com/ratelcode/LeAgents/blob/main/DESIGN.md
9
+ Project-URL: Changelog, https://github.com/ratelcode/LeAgents/releases
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: pydantic>=2.5
14
+ Requires-Dist: PyYAML>=6.0
15
+ Provides-Extra: lerobot
16
+ Requires-Dist: lerobot[libero,smolvla]>=0.5; extra == "lerobot"
17
+ Provides-Extra: dash
18
+ Requires-Dist: fastapi>=0.110; extra == "dash"
19
+ Requires-Dist: uvicorn>=0.29; extra == "dash"
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest>=8; extra == "dev"
22
+ Requires-Dist: ruff>=0.4; extra == "dev"
23
+ Requires-Dist: fastapi>=0.110; extra == "dev"
24
+ Requires-Dist: uvicorn>=0.29; extra == "dev"
25
+ Requires-Dist: httpx>=0.27; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # LeAgents
29
+
30
+ Agentic orchestration for the [LeRobot](https://github.com/huggingface/lerobot) robotics pipeline — an orchestrator drives an automated **collect → train → eval → improve** loop over [LeRobotDataset v3.0](https://huggingface.co/docs/lerobot/lerobot-dataset-v3), with a deterministic loop controller, a constitution safety gate, verification gates before promotion, and (M2) a dashboard for visualizing the flow.
31
+
32
+ <p align="center"><img src="https://raw.githubusercontent.com/ratelcode/LeAgents/main/docs/architecture.svg" alt="LeAgents architecture — a deterministic loop controller dispatches data/train/eval/knowledge agents over LeRobotDataset v3.0 on the Hugging Face Hub, with a constitution safety gate, an OKF knowledge wiki feeding the proposer, and a flow dashboard reading the event log" width="880"></p>
33
+
34
+ Architecture, research grounding (verified 2023–2026 papers), and roadmap: **[DESIGN.md](DESIGN.md)**.
35
+
36
+ ## Status — v0.0.4
37
+
38
+ | Milestone | Scope | Status |
39
+ |---|---|---|
40
+ | **M0** | Sim-only loop on LIBERO: seed dataset → SmolVLA fine-tune → `lerobot-eval` gate → promote/iterate/escalate/rollback | ✅ pipeline verified end-to-end on a real GPU (PushT + LIBERO smoke configs); full-scale training run pending |
41
+ | **M1** | DexFlyWheel-style self-improvement, RoboGene-style task curation, policy escalation, OKF knowledge layer (Karpathy-wiki-style, DESIGN.md §3.6) + provider-agnostic LLM proposer | 🚧 knowledge layer + LLM adapter landed |
42
+ | **M2** | Flow dashboard (Rerun episode replay, WandB curves, OTel agent traces) | 🚧 flow view v1 landed: runs → cycles → decisions live, eval chart, event log, knowledge browser (`leagents dash`) |
43
+ | M3 | Real robot: teleop collection, HIL-SERL adapter (requires lerobot ≥ 0.6.0, see CVE note in DESIGN.md §6) | planned |
44
+
45
+ What works today: the full loop state machine with budgets, the constitution gate, SQLite job store, JSONL event log, subprocess wrappers for `lerobot-train` / `lerobot-eval`, the OKF knowledge layer (`knowledge/` pages with provenance, updated every cycle, linted), the DexFlyWheel data path (success-filtered rollout harvesting → accumulated mix → adaptation training), and a provider-agnostic LLM adapter (`llm: anthropic:*|openai:*[@base_url]`, or none at all — every flow has a deterministic fallback). All covered by tests that run without a GPU or lerobot installed.
46
+
47
+ ## First full-scale autonomous run (2026-07-04)
48
+
49
+ One M0 run on a single RTX 5070 Ti (16 GB), fully autonomous — 3 cycles, 6.1 GPU-hours, zero human intervention, every decision/event/knowledge-page update logged:
50
+
51
+ | Cycle | Data | Train | LIBERO spatial eval (100 episodes) | Decision |
52
+ |---|---|---|---|---|
53
+ | 0 | 40 episodes | 20k steps from `smolvla_base` (loss → 0.030) | 0% success — arm reaches targets, never completes | **promote** (baseline) |
54
+ | 1 | 80 | 20k steps, continued from the blessed checkpoint | 0% | **iterate** |
55
+ | 2 | 160 | 20k steps | 0% | **iterate** — the `escalate_floor` guard correctly refused to escalate a 0%-plateau to a bigger policy |
56
+
57
+ The 0% success is the expected outcome of the data budget, not a pipeline failure: 4→16 episodes per task versus the ~50-per-variation guidance the design research verified for SmolVLA. This run validates the *loop* — budgets held, weights carried over, and the decision function behaved exactly as specified. The next run scales the data schedule to 200→500 episodes (20→50 per task).
58
+
59
+ ## Quickstart
60
+
61
+ ```bash
62
+ pip install -e ".[dev]"
63
+ pytest
64
+
65
+ # dry run — no GPU, no lerobot; synthetic eval scores exercise the decision logic
66
+ leagents run -c configs/m0_libero.yaml --dry-run
67
+
68
+ # real run (Linux; needs a GPU and the LIBERO extras)
69
+ pip install -e ".[lerobot]"
70
+ leagents run -c configs/m0_libero.yaml
71
+
72
+ # inspect runs, cycles, decisions, blessed checkpoints
73
+ leagents status
74
+
75
+ # flow dashboard — runs, cycle pipeline, decisions, eval chart, events, knowledge
76
+ pip install -e ".[dash]"
77
+ leagents dash # → http://127.0.0.1:8321
78
+ ```
79
+
80
+ ## How the loop decides
81
+
82
+ Each cycle trains a candidate checkpoint and evaluates it on LIBERO. The decision is a pure function of success-rate deltas vs. the blessed baseline (`leagents/orchestrator/decision.py`):
83
+
84
+ - **promote** — candidate beats baseline by ≥ `promote_delta`; it becomes the new blessed checkpoint
85
+ - **iterate** — small improvement; collect more data on failing task variations
86
+ - **escalate** — plateaued for `plateau_cycles`; move up the policy ladder (SmolVLA → π0.5)
87
+ - **rollback** — regression; the blessed checkpoint stands
88
+
89
+ Control flow is deterministic Python persisted to SQLite — LLM agents (task proposal, curation; M1) only make proposals *inside* the gates, never control-flow decisions.
90
+
91
+ ## Layout
92
+
93
+ ```
94
+ leagents/
95
+ ├── orchestrator/ # loop controller, decision logic, constitution gate, proposer
96
+ ├── agents/ # data / train / eval / improve agents (LeRobot CLI wrappers)
97
+ ├── contracts/ # typed records: DatasetRef, CheckpointRecord, EvalReport
98
+ ├── events/ # JSONL event bus (dashboard reads this in M2)
99
+ └── store/ # SQLite job store (runs, cycles, checkpoints)
100
+ configs/ # m0_libero.yaml, constitution.yaml
101
+ tests/ # loop e2e with fake runners — no GPU needed
102
+ ```
103
+
104
+ ## License
105
+
106
+ Apache-2.0
@@ -0,0 +1,79 @@
1
+ # LeAgents
2
+
3
+ Agentic orchestration for the [LeRobot](https://github.com/huggingface/lerobot) robotics pipeline — an orchestrator drives an automated **collect → train → eval → improve** loop over [LeRobotDataset v3.0](https://huggingface.co/docs/lerobot/lerobot-dataset-v3), with a deterministic loop controller, a constitution safety gate, verification gates before promotion, and (M2) a dashboard for visualizing the flow.
4
+
5
+ <p align="center"><img src="https://raw.githubusercontent.com/ratelcode/LeAgents/main/docs/architecture.svg" alt="LeAgents architecture — a deterministic loop controller dispatches data/train/eval/knowledge agents over LeRobotDataset v3.0 on the Hugging Face Hub, with a constitution safety gate, an OKF knowledge wiki feeding the proposer, and a flow dashboard reading the event log" width="880"></p>
6
+
7
+ Architecture, research grounding (verified 2023–2026 papers), and roadmap: **[DESIGN.md](DESIGN.md)**.
8
+
9
+ ## Status — v0.0.4
10
+
11
+ | Milestone | Scope | Status |
12
+ |---|---|---|
13
+ | **M0** | Sim-only loop on LIBERO: seed dataset → SmolVLA fine-tune → `lerobot-eval` gate → promote/iterate/escalate/rollback | ✅ pipeline verified end-to-end on a real GPU (PushT + LIBERO smoke configs); full-scale training run pending |
14
+ | **M1** | DexFlyWheel-style self-improvement, RoboGene-style task curation, policy escalation, OKF knowledge layer (Karpathy-wiki-style, DESIGN.md §3.6) + provider-agnostic LLM proposer | 🚧 knowledge layer + LLM adapter landed |
15
+ | **M2** | Flow dashboard (Rerun episode replay, WandB curves, OTel agent traces) | 🚧 flow view v1 landed: runs → cycles → decisions live, eval chart, event log, knowledge browser (`leagents dash`) |
16
+ | M3 | Real robot: teleop collection, HIL-SERL adapter (requires lerobot ≥ 0.6.0, see CVE note in DESIGN.md §6) | planned |
17
+
18
+ What works today: the full loop state machine with budgets, the constitution gate, SQLite job store, JSONL event log, subprocess wrappers for `lerobot-train` / `lerobot-eval`, the OKF knowledge layer (`knowledge/` pages with provenance, updated every cycle, linted), the DexFlyWheel data path (success-filtered rollout harvesting → accumulated mix → adaptation training), and a provider-agnostic LLM adapter (`llm: anthropic:*|openai:*[@base_url]`, or none at all — every flow has a deterministic fallback). All covered by tests that run without a GPU or lerobot installed.
19
+
20
+ ## First full-scale autonomous run (2026-07-04)
21
+
22
+ One M0 run on a single RTX 5070 Ti (16 GB), fully autonomous — 3 cycles, 6.1 GPU-hours, zero human intervention, every decision/event/knowledge-page update logged:
23
+
24
+ | Cycle | Data | Train | LIBERO spatial eval (100 episodes) | Decision |
25
+ |---|---|---|---|---|
26
+ | 0 | 40 episodes | 20k steps from `smolvla_base` (loss → 0.030) | 0% success — arm reaches targets, never completes | **promote** (baseline) |
27
+ | 1 | 80 | 20k steps, continued from the blessed checkpoint | 0% | **iterate** |
28
+ | 2 | 160 | 20k steps | 0% | **iterate** — the `escalate_floor` guard correctly refused to escalate a 0%-plateau to a bigger policy |
29
+
30
+ The 0% success is the expected outcome of the data budget, not a pipeline failure: 4→16 episodes per task versus the ~50-per-variation guidance the design research verified for SmolVLA. This run validates the *loop* — budgets held, weights carried over, and the decision function behaved exactly as specified. The next run scales the data schedule to 200→500 episodes (20→50 per task).
31
+
32
+ ## Quickstart
33
+
34
+ ```bash
35
+ pip install -e ".[dev]"
36
+ pytest
37
+
38
+ # dry run — no GPU, no lerobot; synthetic eval scores exercise the decision logic
39
+ leagents run -c configs/m0_libero.yaml --dry-run
40
+
41
+ # real run (Linux; needs a GPU and the LIBERO extras)
42
+ pip install -e ".[lerobot]"
43
+ leagents run -c configs/m0_libero.yaml
44
+
45
+ # inspect runs, cycles, decisions, blessed checkpoints
46
+ leagents status
47
+
48
+ # flow dashboard — runs, cycle pipeline, decisions, eval chart, events, knowledge
49
+ pip install -e ".[dash]"
50
+ leagents dash # → http://127.0.0.1:8321
51
+ ```
52
+
53
+ ## How the loop decides
54
+
55
+ Each cycle trains a candidate checkpoint and evaluates it on LIBERO. The decision is a pure function of success-rate deltas vs. the blessed baseline (`leagents/orchestrator/decision.py`):
56
+
57
+ - **promote** — candidate beats baseline by ≥ `promote_delta`; it becomes the new blessed checkpoint
58
+ - **iterate** — small improvement; collect more data on failing task variations
59
+ - **escalate** — plateaued for `plateau_cycles`; move up the policy ladder (SmolVLA → π0.5)
60
+ - **rollback** — regression; the blessed checkpoint stands
61
+
62
+ Control flow is deterministic Python persisted to SQLite — LLM agents (task proposal, curation; M1) only make proposals *inside* the gates, never control-flow decisions.
63
+
64
+ ## Layout
65
+
66
+ ```
67
+ leagents/
68
+ ├── orchestrator/ # loop controller, decision logic, constitution gate, proposer
69
+ ├── agents/ # data / train / eval / improve agents (LeRobot CLI wrappers)
70
+ ├── contracts/ # typed records: DatasetRef, CheckpointRecord, EvalReport
71
+ ├── events/ # JSONL event bus (dashboard reads this in M2)
72
+ └── store/ # SQLite job store (runs, cycles, checkpoints)
73
+ configs/ # m0_libero.yaml, constitution.yaml
74
+ tests/ # loop e2e with fake runners — no GPU needed
75
+ ```
76
+
77
+ ## License
78
+
79
+ Apache-2.0
@@ -0,0 +1,3 @@
1
+ """leagents — agentic orchestration for the LeRobot pipeline."""
2
+
3
+ __version__ = "0.0.4"
@@ -0,0 +1,21 @@
1
+ from leagents.agents.base import RunResult, Runner, dry_runner, subprocess_runner
2
+ from leagents.agents.data_agent import DataAgent
3
+ from leagents.agents.eval_agent import EvalAgent, EvalError
4
+ from leagents.agents.improve_agent import ImproveAgent, ImproveError
5
+ from leagents.agents.knowledge_agent import KnowledgeAgent
6
+ from leagents.agents.train_agent import TrainAgent, TrainError
7
+
8
+ __all__ = [
9
+ "RunResult",
10
+ "Runner",
11
+ "dry_runner",
12
+ "subprocess_runner",
13
+ "DataAgent",
14
+ "EvalAgent",
15
+ "EvalError",
16
+ "ImproveAgent",
17
+ "ImproveError",
18
+ "KnowledgeAgent",
19
+ "TrainAgent",
20
+ "TrainError",
21
+ ]
@@ -0,0 +1,42 @@
1
+ """Shared subprocess runner for agents that wrap LeRobot CLIs.
2
+
3
+ Runners are injectable so tests (and --dry-run) exercise the full loop
4
+ without lerobot installed or a GPU present.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import subprocess
10
+ import time
11
+ from dataclasses import dataclass
12
+ from pathlib import Path
13
+ from typing import Callable, Sequence
14
+
15
+
16
+ @dataclass
17
+ class RunResult:
18
+ cmd: list[str]
19
+ exit_code: int
20
+ duration_s: float
21
+ log_path: Path | None = None
22
+
23
+
24
+ Runner = Callable[[Sequence[str], Path], RunResult]
25
+
26
+
27
+ def subprocess_runner(cmd: Sequence[str], log_path: Path) -> RunResult:
28
+ """Run a command, teeing stdout+stderr to a log file.
29
+
30
+ Training jobs stream output for hours — never buffer it in memory.
31
+ """
32
+ log_path.parent.mkdir(parents=True, exist_ok=True)
33
+ start = time.monotonic()
34
+ with log_path.open("w") as log:
35
+ proc = subprocess.run(list(cmd), stdout=log, stderr=subprocess.STDOUT)
36
+ return RunResult(list(cmd), proc.returncode, time.monotonic() - start, log_path)
37
+
38
+
39
+ def dry_runner(cmd: Sequence[str], log_path: Path) -> RunResult:
40
+ log_path.parent.mkdir(parents=True, exist_ok=True)
41
+ log_path.write_text("DRY RUN: " + " ".join(cmd) + "\n")
42
+ return RunResult(list(cmd), 0, 0.0, log_path)
@@ -0,0 +1,38 @@
1
+ """Data Agent — M0 scope (DESIGN.md §3.2, §8).
2
+
3
+ M0 collects no new data: the agent resolves the seed dataset from the
4
+ proposal and records provenance for the cycle. RoboGene-style curation,
5
+ MimicGen-style amplification, and GenAug-style augmentation land in M1.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from leagents.contracts import DatasetRef, Proposal
11
+ from leagents.events import Event, EventBus
12
+
13
+
14
+ class DataAgent:
15
+ def __init__(self, bus: EventBus):
16
+ self.bus = bus
17
+
18
+ def run(self, *, run_id: str, cycle: int, proposal: Proposal) -> DatasetRef:
19
+ ref = DatasetRef(
20
+ repo_id=proposal.dataset,
21
+ num_episodes=proposal.num_episodes,
22
+ notes=proposal.notes,
23
+ )
24
+ self.bus.emit(
25
+ Event(
26
+ run_id=run_id,
27
+ stage="collect",
28
+ kind="dataset_resolved",
29
+ cycle=cycle,
30
+ payload={
31
+ "action": proposal.action,
32
+ "repo_id": ref.repo_id,
33
+ "num_episodes": ref.num_episodes,
34
+ "notes": ref.notes,
35
+ },
36
+ )
37
+ )
38
+ return ref
@@ -0,0 +1,105 @@
1
+ """Eval Agent — `lerobot-eval` LIBERO gate (DESIGN.md §3.4)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ from leagents.agents.base import Runner, subprocess_runner
10
+ from leagents.config import EvalConfig
11
+ from leagents.contracts import CheckpointRecord, EvalReport
12
+ from leagents.events import Event, EventBus
13
+ from leagents.orchestrator.constitution import Constitution, ConstitutionError
14
+
15
+
16
+ class EvalError(Exception):
17
+ pass
18
+
19
+
20
+ class EvalAgent:
21
+ def __init__(
22
+ self,
23
+ cfg: EvalConfig,
24
+ constitution: Constitution,
25
+ bus: EventBus,
26
+ runner: Runner = subprocess_runner,
27
+ ):
28
+ self.cfg = cfg
29
+ self.constitution = constitution
30
+ self.bus = bus
31
+ self.runner = runner
32
+
33
+ def build_command(self, checkpoint: CheckpointRecord, output_dir: Path) -> list[str]:
34
+ return [
35
+ "lerobot-eval",
36
+ f"--policy.path={checkpoint.path}",
37
+ f"--env.type={self.cfg.env_type}",
38
+ f"--env.task={self.cfg.task_suite}",
39
+ f"--eval.n_episodes={self.cfg.n_episodes}",
40
+ # lerobot-eval rejects batch_size > n_episodes (default batch is 50)
41
+ f"--eval.batch_size={min(self.cfg.batch_size, self.cfg.n_episodes)}",
42
+ f"--output_dir={output_dir}",
43
+ *self.cfg.extra_args,
44
+ ]
45
+
46
+ def run(
47
+ self, *, run_id: str, cycle: int, checkpoint: CheckpointRecord, workdir: Path
48
+ ) -> EvalReport:
49
+ output_dir = workdir / f"cycle_{cycle}" / "eval"
50
+ cmd = self.build_command(checkpoint, output_dir)
51
+
52
+ for verdict in (self.constitution.check_eval(self.cfg.env_type, self.cfg.n_episodes),
53
+ self.constitution.check_command(cmd)):
54
+ if not verdict.allowed:
55
+ self.bus.emit(Event(run_id, "eval", "constitution_denied", cycle,
56
+ {"rule": verdict.rule, "reason": verdict.reason}))
57
+ raise ConstitutionError(verdict)
58
+
59
+ self.bus.emit(Event(run_id, "eval", "job_started", cycle, {"cmd": cmd}))
60
+ # log lives outside output_dir: lerobot CLIs refuse a pre-existing output_dir
61
+ result = self.runner(cmd, output_dir.parent / "eval.log")
62
+ self.bus.emit(Event(run_id, "eval", "job_finished", cycle,
63
+ {"exit_code": result.exit_code, "duration_s": result.duration_s,
64
+ "log": str(result.log_path)}))
65
+ if result.exit_code != 0:
66
+ raise EvalError(f"lerobot-eval exited {result.exit_code}, see {result.log_path}")
67
+
68
+ success_rate, per_task, raw = self._parse_eval_info(output_dir / "eval_info.json")
69
+ report = EvalReport(
70
+ checkpoint=checkpoint.path,
71
+ env_type=self.cfg.env_type,
72
+ task_suite=self.cfg.task_suite,
73
+ n_episodes=self.cfg.n_episodes,
74
+ success_rate=success_rate,
75
+ per_task=per_task,
76
+ raw=raw,
77
+ )
78
+ self.bus.emit(Event(run_id, "eval", "report", cycle,
79
+ {"success_rate": success_rate, "task_suite": self.cfg.task_suite}))
80
+ return report
81
+
82
+ @staticmethod
83
+ def _parse_eval_info(path: Path) -> tuple[float, dict[str, float], dict[str, Any]]:
84
+ """Parse lerobot-eval's eval_info.json.
85
+
86
+ lerobot 0.5 schema: {"overall": {"pc_success": <0-100>, ...},
87
+ "per_group": {<group>: {"pc_success": ...}}, "per_task": [...]}.
88
+ Returns (success fraction, per-group success fractions, raw data).
89
+ """
90
+ if not path.exists():
91
+ raise EvalError(f"eval output missing: {path}")
92
+ data: dict[str, Any] = json.loads(path.read_text())
93
+ aggregate = data.get("overall") or data.get("aggregated") or data
94
+ if "pc_success" in aggregate: # percentage 0-100 by definition
95
+ success = float(aggregate["pc_success"]) / 100.0
96
+ elif "success_rate" in aggregate: # fraction 0-1
97
+ success = float(aggregate["success_rate"])
98
+ else:
99
+ raise EvalError(f"no success metric found in {path}")
100
+ per_task = {
101
+ group: float(metrics["pc_success"]) / 100.0
102
+ for group, metrics in (data.get("per_group") or {}).items()
103
+ if isinstance(metrics, dict) and "pc_success" in metrics
104
+ }
105
+ return success, per_task, data