harness-proxy 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.
- harness_proxy-0.1.0/.gitignore +26 -0
- harness_proxy-0.1.0/LICENSE +202 -0
- harness_proxy-0.1.0/PKG-INFO +108 -0
- harness_proxy-0.1.0/README.md +75 -0
- harness_proxy-0.1.0/pyproject.toml +56 -0
- harness_proxy-0.1.0/src/harness_proxy/__init__.py +0 -0
- harness_proxy-0.1.0/src/harness_proxy/backends/__init__.py +19 -0
- harness_proxy-0.1.0/src/harness_proxy/backends/tinker.py +71 -0
- harness_proxy-0.1.0/src/harness_proxy/backends/together.py +150 -0
- harness_proxy-0.1.0/src/harness_proxy/bridge.py +233 -0
- harness_proxy-0.1.0/src/harness_proxy/chat.py +176 -0
- harness_proxy-0.1.0/src/harness_proxy/client.py +305 -0
- harness_proxy-0.1.0/src/harness_proxy/cookbook.py +163 -0
- harness_proxy-0.1.0/src/harness_proxy/dialects/__init__.py +0 -0
- harness_proxy-0.1.0/src/harness_proxy/dialects/anthropic.py +257 -0
- harness_proxy-0.1.0/src/harness_proxy/dialects/openai.py +287 -0
- harness_proxy-0.1.0/src/harness_proxy/keepalive.py +160 -0
- harness_proxy-0.1.0/src/harness_proxy/py.typed +0 -0
- harness_proxy-0.1.0/src/harness_proxy/rendering.py +205 -0
- harness_proxy-0.1.0/src/harness_proxy/serve.py +292 -0
- harness_proxy-0.1.0/src/harness_proxy/server.py +606 -0
- harness_proxy-0.1.0/src/harness_proxy/trial.py +316 -0
- harness_proxy-0.1.0/src/harness_proxy/tunnel.py +158 -0
- harness_proxy-0.1.0/src/harness_proxy/vision.py +254 -0
- harness_proxy-0.1.0/src/harness_proxy/wire.py +561 -0
- harness_proxy-0.1.0/tests/conftest.py +19 -0
- harness_proxy-0.1.0/tests/proxies.py +332 -0
- harness_proxy-0.1.0/tests/test_bridge.py +712 -0
- harness_proxy-0.1.0/tests/test_call_ids.py +42 -0
- harness_proxy-0.1.0/tests/test_client.py +231 -0
- harness_proxy-0.1.0/tests/test_client_records.py +212 -0
- harness_proxy-0.1.0/tests/test_extension.py +273 -0
- harness_proxy-0.1.0/tests/test_follow.py +190 -0
- harness_proxy-0.1.0/tests/test_gpt_oss.py +133 -0
- harness_proxy-0.1.0/tests/test_keepalive.py +163 -0
- harness_proxy-0.1.0/tests/test_lanes.py +154 -0
- harness_proxy-0.1.0/tests/test_proxy_records.py +459 -0
- harness_proxy-0.1.0/tests/test_proxy_server.py +261 -0
- harness_proxy-0.1.0/tests/test_renderer_effort.py +91 -0
- harness_proxy-0.1.0/tests/test_renderers.py +163 -0
- harness_proxy-0.1.0/tests/test_sdk_headers.py +49 -0
- harness_proxy-0.1.0/tests/test_serve.py +459 -0
- harness_proxy-0.1.0/tests/test_thinking.py +311 -0
- harness_proxy-0.1.0/tests/test_tinker_server.py +85 -0
- harness_proxy-0.1.0/tests/test_together.py +121 -0
- harness_proxy-0.1.0/tests/test_tokenize_once.py +92 -0
- harness_proxy-0.1.0/tests/test_tunnel.py +186 -0
- harness_proxy-0.1.0/tests/test_turns.py +197 -0
- harness_proxy-0.1.0/tests/test_vision.py +333 -0
- harness_proxy-0.1.0/tests/test_wire.py +80 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.venv/
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.pyc
|
|
4
|
+
.pytest_cache/
|
|
5
|
+
.ruff_cache/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
/runs/
|
|
10
|
+
/jobs/
|
|
11
|
+
/tasks/
|
|
12
|
+
.env
|
|
13
|
+
.DS_Store
|
|
14
|
+
/site/
|
|
15
|
+
/legacy/
|
|
16
|
+
MAP.md
|
|
17
|
+
experiments/
|
|
18
|
+
.claude
|
|
19
|
+
.agents
|
|
20
|
+
docs/*
|
|
21
|
+
!docs/adr/
|
|
22
|
+
mkdocs.yml
|
|
23
|
+
skills-lock.json
|
|
24
|
+
uv.lock
|
|
25
|
+
reports/
|
|
26
|
+
research_notes/
|
|
@@ -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,108 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: harness-proxy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: OpenAI- and Anthropic-compatible model server for agent harnesses, backed by Tinker, that records every call as token ids.
|
|
5
|
+
Project-URL: Repository, https://github.com/ghidav/shipyard
|
|
6
|
+
Project-URL: Issues, https://github.com/ghidav/shipyard/issues
|
|
7
|
+
Author: Davide Ghilardi
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: agents,llm,proxy,reinforcement-learning,tinker
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Requires-Dist: aiohttp>=3.9
|
|
22
|
+
Requires-Dist: httpx>=0.27
|
|
23
|
+
Requires-Dist: pillow>=10
|
|
24
|
+
Requires-Dist: pypdfium2>=4.30
|
|
25
|
+
Requires-Dist: tinker-cookbook<0.7,>=0.6
|
|
26
|
+
Requires-Dist: tinker<0.39,>=0.38
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
30
|
+
Provides-Extra: together
|
|
31
|
+
Requires-Dist: together<3,>=2.42; extra == 'together'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# harness-proxy
|
|
35
|
+
|
|
36
|
+
A model server that stands in for a provider to agent harnesses: OpenAI Chat Completions and Anthropic Messages, streaming or not, sampled from Tinker or from a Together post-training session. The run opens each trial on it, and closing the trial hands back every call the trial made as token ids and sampler logprobs, so a trainer can train on exactly what was sampled.
|
|
37
|
+
|
|
38
|
+
```mermaid
|
|
39
|
+
flowchart LR
|
|
40
|
+
run["the run, through client"] -->|"open: lane, renderer, weights or follow"| trial["trial: budget, records, bridge index"]
|
|
41
|
+
run -->|"serve: a lane's new weights"| trial
|
|
42
|
+
harness["harness"] -->|"OpenAI or Anthropic call, with the trial's token"| dialect["dialects"]
|
|
43
|
+
dialect --> rendering["rendering: complete the call"]
|
|
44
|
+
rendering -->|render| bridge["bridge"]
|
|
45
|
+
rendering -->|sample| trial
|
|
46
|
+
trial --> backend["backends: tinker, together"]
|
|
47
|
+
run -->|"close: its records"| trial
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
On each call it renders with the model's cookbook renderer, images, PDFs and mid-conversation system messages included, encoding each message once per trial; builds the prompt from its own tokens when the history quotes one of its replies; answers an SDK retry with the first reply; returns thinking in the API's own format; and keeps slow streams alive.
|
|
51
|
+
|
|
52
|
+
## Run it
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
harness-proxy --model Qwen/Qwen3-8B --advertise host.docker.internal
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
It serves the model in one lane, named `agent` unless `--lane` names another, prints `serving <lanes> at http://<host>:<port>` and serves until SIGTERM. Its control token, which opens and closes trials, comes from `HARNESS_PROXY_CONTROL_TOKEN`, or is generated and printed.
|
|
59
|
+
|
|
60
|
+
| Route | Token | What |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `POST /trials` | control | `{"trial": "<name>", "lane": ..., "renderer": ..., "weights": "tinker://..." \| null, "follow": false}` opens a trial and answers `{"token": ...}`; each but `trial` may be left out: the only lane, its first renderer, its base model. With `"follow": true`, each call takes the weights the lane published last as it starts, instead of `weights`. The same opening asked again answers the same token |
|
|
63
|
+
| `POST /lanes/<lane>/serve` | control | `{"weights": "tinker://..." \| null, "version": ...}` publishes the lane's new weights: each call of a trial that follows the lane takes them from then on. `version`, for a backend that serves only the weights published last, is the one it gave them |
|
|
64
|
+
| `POST /v1/chat/completions`, `/v1/messages` | the trial's | the model of the trial's lane, at its weights or the ones the lane published last, rendered with its renderer, recorded under the weights that answered it |
|
|
65
|
+
| `POST /trials/<trial>/close` | control | closes the trial and answers its records, each prompt as a delta of the record it extends; a close asked again within 30 minutes answers the same |
|
|
66
|
+
| `GET /healthz` | none | each lane: its `model`, the per-trial `budget`, and its `renderers` |
|
|
67
|
+
|
|
68
|
+
A call whose token no open trial holds is turned away with a 401, as is a call of a trial that closed. A trial opened on weights keeps them until it closes, so trials on several versions of a lane's model run side by side. A trial that follows its lane takes the weights published last at each call, and a call in flight keeps the ones it started with.
|
|
69
|
+
|
|
70
|
+
By hand, with the control token it printed:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
token=$(curl -s -H "Authorization: Bearer $HARNESS_PROXY_CONTROL_TOKEN" \
|
|
74
|
+
-d '{"trial": "t-0"}' http://localhost:8000/trials | jq -r .token)
|
|
75
|
+
OPENAI_BASE_URL=http://localhost:8000/v1 OPENAI_API_KEY=$token my-harness
|
|
76
|
+
curl -s -X POST -H "Authorization: Bearer $HARNESS_PROXY_CONTROL_TOKEN" \
|
|
77
|
+
http://localhost:8000/trials/t-0/close
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## From Python
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from harness_proxy.client import Proxy
|
|
84
|
+
|
|
85
|
+
settings = {"lanes": [{"name": "agent", "model": "Qwen/Qwen3-8B"}]}
|
|
86
|
+
proxy = await Proxy.local(settings, host="host.docker.internal") # or .tunnelled, or .remote
|
|
87
|
+
lanes = await proxy.ready() # each lane's Served, as /healthz reports it
|
|
88
|
+
await proxy.serve("agent", "tinker://.../sampler_weights/000010")
|
|
89
|
+
token = await proxy.open("trial-0", lane="agent", follow=True) # or weights="tinker://..."
|
|
90
|
+
# the harness dials proxy.address (proxy.local_address from this machine) with `token`
|
|
91
|
+
await proxy.serve("agent", "tinker://.../sampler_weights/000011") # its next call takes them
|
|
92
|
+
records = await proxy.close("trial-0") # harness_proxy.wire.Record, in request order
|
|
93
|
+
proxy.stop()
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- **Lanes:** a proxy serves one or more models, each in a lane of its own, which a trial is opened on. A run lists them in `--settings` as one document, `{"lanes": [...]}`, each lane whole: a `name`, a `model`, and any of its own `renderer`, `temperature`, `top_p`, `top_k`, `max_tokens`, `max_context`, `fill_context`, `metadata`, `backend`, `session`, `base_url` and `api_key_env`. The proxy fills nothing in. A lane needs its model's context length, for the budget and the context fit: its backend reports it, and a lane whose backend cannot must give its own `max_context`, or the proxy refuses to start. `--model` and `--renderer` are shorthand for a document of one lane.
|
|
97
|
+
- **Trials:** each samples the weights it was opened on, or, following its lane, the weights the lane published last as each call starts, through a client its lane holds while a trial or a call uses them; each record names the weights that answered it. A trial keeps its own records, budget and bridge index until it closes. The run opens and closes trials with the control token; a sandbox holds only its own trial's token.
|
|
98
|
+
- **Renderers:** a lane's `renderer`, a list, builds each, such as two reasoning efforts; a trial opened with one is rendered with it.
|
|
99
|
+
- **Tunnels:** `Proxy.tunnelled` puts a Cloudflare quick tunnel in front, for sandboxes with no route back (Modal, Daytona). A proxy the run starts stops once the run is gone, leaving no process, port, session or tunnel.
|
|
100
|
+
- **Together:** a lane's `backend = "together"` samples the generator of the run's session (`session`): the weights published last, whatever a trial names, each record naming them by the version that wrote it, text only, stopping on strings or at the end of sequence. It needs `harness-proxy[together]` and `TOGETHER_API_KEY`.
|
|
101
|
+
|
|
102
|
+
## Develop
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
cd packages/harness-proxy && pytest
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The tests run on fake samplers and renderers (`tests/proxies.py`); one that needs a real tokenizer skips when it is not cached.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# harness-proxy
|
|
2
|
+
|
|
3
|
+
A model server that stands in for a provider to agent harnesses: OpenAI Chat Completions and Anthropic Messages, streaming or not, sampled from Tinker or from a Together post-training session. The run opens each trial on it, and closing the trial hands back every call the trial made as token ids and sampler logprobs, so a trainer can train on exactly what was sampled.
|
|
4
|
+
|
|
5
|
+
```mermaid
|
|
6
|
+
flowchart LR
|
|
7
|
+
run["the run, through client"] -->|"open: lane, renderer, weights or follow"| trial["trial: budget, records, bridge index"]
|
|
8
|
+
run -->|"serve: a lane's new weights"| trial
|
|
9
|
+
harness["harness"] -->|"OpenAI or Anthropic call, with the trial's token"| dialect["dialects"]
|
|
10
|
+
dialect --> rendering["rendering: complete the call"]
|
|
11
|
+
rendering -->|render| bridge["bridge"]
|
|
12
|
+
rendering -->|sample| trial
|
|
13
|
+
trial --> backend["backends: tinker, together"]
|
|
14
|
+
run -->|"close: its records"| trial
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
On each call it renders with the model's cookbook renderer, images, PDFs and mid-conversation system messages included, encoding each message once per trial; builds the prompt from its own tokens when the history quotes one of its replies; answers an SDK retry with the first reply; returns thinking in the API's own format; and keeps slow streams alive.
|
|
18
|
+
|
|
19
|
+
## Run it
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
harness-proxy --model Qwen/Qwen3-8B --advertise host.docker.internal
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
It serves the model in one lane, named `agent` unless `--lane` names another, prints `serving <lanes> at http://<host>:<port>` and serves until SIGTERM. Its control token, which opens and closes trials, comes from `HARNESS_PROXY_CONTROL_TOKEN`, or is generated and printed.
|
|
26
|
+
|
|
27
|
+
| Route | Token | What |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| `POST /trials` | control | `{"trial": "<name>", "lane": ..., "renderer": ..., "weights": "tinker://..." \| null, "follow": false}` opens a trial and answers `{"token": ...}`; each but `trial` may be left out: the only lane, its first renderer, its base model. With `"follow": true`, each call takes the weights the lane published last as it starts, instead of `weights`. The same opening asked again answers the same token |
|
|
30
|
+
| `POST /lanes/<lane>/serve` | control | `{"weights": "tinker://..." \| null, "version": ...}` publishes the lane's new weights: each call of a trial that follows the lane takes them from then on. `version`, for a backend that serves only the weights published last, is the one it gave them |
|
|
31
|
+
| `POST /v1/chat/completions`, `/v1/messages` | the trial's | the model of the trial's lane, at its weights or the ones the lane published last, rendered with its renderer, recorded under the weights that answered it |
|
|
32
|
+
| `POST /trials/<trial>/close` | control | closes the trial and answers its records, each prompt as a delta of the record it extends; a close asked again within 30 minutes answers the same |
|
|
33
|
+
| `GET /healthz` | none | each lane: its `model`, the per-trial `budget`, and its `renderers` |
|
|
34
|
+
|
|
35
|
+
A call whose token no open trial holds is turned away with a 401, as is a call of a trial that closed. A trial opened on weights keeps them until it closes, so trials on several versions of a lane's model run side by side. A trial that follows its lane takes the weights published last at each call, and a call in flight keeps the ones it started with.
|
|
36
|
+
|
|
37
|
+
By hand, with the control token it printed:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
token=$(curl -s -H "Authorization: Bearer $HARNESS_PROXY_CONTROL_TOKEN" \
|
|
41
|
+
-d '{"trial": "t-0"}' http://localhost:8000/trials | jq -r .token)
|
|
42
|
+
OPENAI_BASE_URL=http://localhost:8000/v1 OPENAI_API_KEY=$token my-harness
|
|
43
|
+
curl -s -X POST -H "Authorization: Bearer $HARNESS_PROXY_CONTROL_TOKEN" \
|
|
44
|
+
http://localhost:8000/trials/t-0/close
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## From Python
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from harness_proxy.client import Proxy
|
|
51
|
+
|
|
52
|
+
settings = {"lanes": [{"name": "agent", "model": "Qwen/Qwen3-8B"}]}
|
|
53
|
+
proxy = await Proxy.local(settings, host="host.docker.internal") # or .tunnelled, or .remote
|
|
54
|
+
lanes = await proxy.ready() # each lane's Served, as /healthz reports it
|
|
55
|
+
await proxy.serve("agent", "tinker://.../sampler_weights/000010")
|
|
56
|
+
token = await proxy.open("trial-0", lane="agent", follow=True) # or weights="tinker://..."
|
|
57
|
+
# the harness dials proxy.address (proxy.local_address from this machine) with `token`
|
|
58
|
+
await proxy.serve("agent", "tinker://.../sampler_weights/000011") # its next call takes them
|
|
59
|
+
records = await proxy.close("trial-0") # harness_proxy.wire.Record, in request order
|
|
60
|
+
proxy.stop()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- **Lanes:** a proxy serves one or more models, each in a lane of its own, which a trial is opened on. A run lists them in `--settings` as one document, `{"lanes": [...]}`, each lane whole: a `name`, a `model`, and any of its own `renderer`, `temperature`, `top_p`, `top_k`, `max_tokens`, `max_context`, `fill_context`, `metadata`, `backend`, `session`, `base_url` and `api_key_env`. The proxy fills nothing in. A lane needs its model's context length, for the budget and the context fit: its backend reports it, and a lane whose backend cannot must give its own `max_context`, or the proxy refuses to start. `--model` and `--renderer` are shorthand for a document of one lane.
|
|
64
|
+
- **Trials:** each samples the weights it was opened on, or, following its lane, the weights the lane published last as each call starts, through a client its lane holds while a trial or a call uses them; each record names the weights that answered it. A trial keeps its own records, budget and bridge index until it closes. The run opens and closes trials with the control token; a sandbox holds only its own trial's token.
|
|
65
|
+
- **Renderers:** a lane's `renderer`, a list, builds each, such as two reasoning efforts; a trial opened with one is rendered with it.
|
|
66
|
+
- **Tunnels:** `Proxy.tunnelled` puts a Cloudflare quick tunnel in front, for sandboxes with no route back (Modal, Daytona). A proxy the run starts stops once the run is gone, leaving no process, port, session or tunnel.
|
|
67
|
+
- **Together:** a lane's `backend = "together"` samples the generator of the run's session (`session`): the weights published last, whatever a trial names, each record naming them by the version that wrote it, text only, stopping on strings or at the end of sequence. It needs `harness-proxy[together]` and `TOGETHER_API_KEY`.
|
|
68
|
+
|
|
69
|
+
## Develop
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
cd packages/harness-proxy && pytest
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The tests run on fake samplers and renderers (`tests/proxies.py`); one that needs a real tokenizer skips when it is not cached.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "harness-proxy"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "OpenAI- and Anthropic-compatible model server for agent harnesses, backed by Tinker, that records every call as token ids."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [{ name = "Davide Ghilardi" }]
|
|
9
|
+
keywords = ["reinforcement-learning", "llm", "agents", "tinker", "proxy"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 3 - Alpha",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Intended Audience :: Science/Research",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
19
|
+
"Typing :: Typed",
|
|
20
|
+
]
|
|
21
|
+
requires-python = ">=3.12"
|
|
22
|
+
dependencies = [
|
|
23
|
+
"aiohttp>=3.9",
|
|
24
|
+
"httpx>=0.27",
|
|
25
|
+
# tinker: below 0.39, the first minor no run has used, since a minor can change its API.
|
|
26
|
+
"tinker>=0.38,<0.39",
|
|
27
|
+
# tinker-cookbook: 0.6 is the first to tokenize Inkling 2 Small with its own tokenizer.
|
|
28
|
+
"tinker-cookbook>=0.6,<0.7",
|
|
29
|
+
"pypdfium2>=4.30",
|
|
30
|
+
"pillow>=10",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Repository = "https://github.com/ghidav/shipyard"
|
|
35
|
+
Issues = "https://github.com/ghidav/shipyard/issues"
|
|
36
|
+
|
|
37
|
+
[project.scripts]
|
|
38
|
+
harness-proxy = "harness_proxy.serve:main"
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
dev = ["pytest>=8.3", "pytest-asyncio>=0.24"]
|
|
42
|
+
# The `together` backend, which samples a Together post-training session; below 3, a major no
|
|
43
|
+
# run has used.
|
|
44
|
+
together = ["together>=2.42,<3"]
|
|
45
|
+
|
|
46
|
+
[build-system]
|
|
47
|
+
requires = ["hatchling"]
|
|
48
|
+
build-backend = "hatchling.build"
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.wheel]
|
|
51
|
+
packages = ["src/harness_proxy"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
testpaths = ["tests"]
|
|
55
|
+
pythonpath = ["src", "tests"]
|
|
56
|
+
asyncio_mode = "auto"
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from types import ModuleType
|
|
4
|
+
|
|
5
|
+
from harness_proxy.backends import tinker, together
|
|
6
|
+
|
|
7
|
+
#: Every backend, by the name a run gives it: a module with `PREFIX`, `connect`, `sampler`,
|
|
8
|
+
#: `context_of` and `close`.
|
|
9
|
+
BACKENDS: dict[str, ModuleType] = {"tinker": tinker, "together": together}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def named(name: str) -> ModuleType:
|
|
13
|
+
"""Return the backend called `name`. Raise ValueError for an unknown one."""
|
|
14
|
+
try:
|
|
15
|
+
return BACKENDS[name]
|
|
16
|
+
except KeyError:
|
|
17
|
+
raise ValueError(
|
|
18
|
+
f"no backend {name!r}: the proxy samples from {', '.join(sorted(BACKENDS))}"
|
|
19
|
+
) from None
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
PREFIX = "tinker://"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async def connect(
|
|
13
|
+
*,
|
|
14
|
+
metadata: dict[str, str] | None,
|
|
15
|
+
session: str | None,
|
|
16
|
+
base_url: str | None = None,
|
|
17
|
+
api_key_env: str | None = None,
|
|
18
|
+
) -> Any:
|
|
19
|
+
"""Return Tinker's service client, its session tagged with `metadata`: on the server at
|
|
20
|
+
`base_url`, with the key the variable `api_key_env` holds, or on the one the environment
|
|
21
|
+
names. `ValueError` if that variable is not set."""
|
|
22
|
+
import tinker
|
|
23
|
+
|
|
24
|
+
return tinker.ServiceClient(user_metadata=metadata, **reaching(base_url, api_key_env))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def reaching(base_url: str | None, api_key_env: str | None) -> dict[str, str]:
|
|
28
|
+
"""Return what `tinker.ServiceClient` takes to reach the server at `base_url` with the key
|
|
29
|
+
the variable `api_key_env` holds; nothing for a None, which leaves it to the environment
|
|
30
|
+
(TINKER_BASE_URL, TINKER_API_KEY). `ValueError` if the variable is not set: the SDK would
|
|
31
|
+
send that server TINKER_API_KEY, Tinker's own key."""
|
|
32
|
+
found: dict[str, str] = {}
|
|
33
|
+
if base_url:
|
|
34
|
+
found["base_url"] = base_url
|
|
35
|
+
if api_key_env:
|
|
36
|
+
key = os.environ.get(api_key_env)
|
|
37
|
+
if not key:
|
|
38
|
+
raise ValueError(
|
|
39
|
+
f"{api_key_env} is not set: it holds the key of the Tinker server "
|
|
40
|
+
f"{base_url or 'the run reaches'}"
|
|
41
|
+
)
|
|
42
|
+
found["api_key"] = key
|
|
43
|
+
return found
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
async def sampler(service: Any, base_model: str, weights: str | None) -> Any:
|
|
47
|
+
"""Return a sampling client on the `tinker://` weights, or on the base model for None."""
|
|
48
|
+
if weights is None:
|
|
49
|
+
return await service.create_sampling_client_async(base_model=base_model)
|
|
50
|
+
return await service.create_sampling_client_async(model_path=weights)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
async def context_of(service: Any, base_model: str) -> int | None:
|
|
54
|
+
"""Return the model's context length from `get_server_capabilities`; None on any error."""
|
|
55
|
+
try:
|
|
56
|
+
caps = await service.get_server_capabilities_async()
|
|
57
|
+
for model in getattr(caps, "supported_models", None) or []:
|
|
58
|
+
if getattr(model, "model_name", None) == base_model:
|
|
59
|
+
return int(getattr(model, "max_context_length", 0) or 0) or None
|
|
60
|
+
except Exception: # noqa: BLE001 - the lane refuses, one way for any cause
|
|
61
|
+
logger.warning(
|
|
62
|
+
"could not read the context length of %s",
|
|
63
|
+
base_model,
|
|
64
|
+
exc_info=True,
|
|
65
|
+
)
|
|
66
|
+
return None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
async def close(service: Any) -> None:
|
|
70
|
+
"""Finish the proxy's Tinker session as a success: the proxy's own shutdown was clean."""
|
|
71
|
+
await service.close("success")
|