seldon-runtime 0.1.1.dev3__tar.gz → 0.1.1.dev4__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 (74) hide show
  1. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/CHANGELOG.md +20 -0
  2. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/PKG-INFO +47 -7
  3. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/README.md +46 -6
  4. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/pyproject.toml +1 -1
  5. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/runtime_modules.txt +1 -0
  6. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/schemas/compiler-artifact-v1.json +18 -2
  7. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/__init__.py +1 -1
  8. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/artifact.py +26 -11
  9. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/components.py +112 -1
  10. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/conditional.py +2 -0
  11. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/contracts.py +72 -1
  12. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/executor.py +27 -13
  13. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/program_validation.py +2 -0
  14. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/semantic.py +140 -0
  15. seldon_runtime-0.1.1.dev4/seldon_runtime/span_review.py +339 -0
  16. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime.egg-info/PKG-INFO +47 -7
  17. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime.egg-info/SOURCES.txt +4 -0
  18. seldon_runtime-0.1.1.dev4/tests/fixtures/compiler-artifact-reference/manifest.json +207 -0
  19. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/test_artifact.py +16 -1
  20. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/test_native_artifact.py +7 -0
  21. seldon_runtime-0.1.1.dev4/tests/test_reference_program.py +427 -0
  22. seldon_runtime-0.1.1.dev4/tests/test_span_review.py +507 -0
  23. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/wheel_probe.py +25 -0
  24. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/LICENSE +0 -0
  25. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/MANIFEST.in +0 -0
  26. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/NOTICE +0 -0
  27. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/THIRD_PARTY_NOTICES.md +0 -0
  28. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/scripts/export_artifact_schema.py +0 -0
  29. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/attempt_bound.py +0 -0
  30. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/contract_versions.py +0 -0
  31. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/data/o200k_base.tiktoken +0 -0
  32. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/data/provenance.json +0 -0
  33. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/deadline.py +0 -0
  34. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/gliner_normalize.py +0 -0
  35. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/instruction_envelope.py +0 -0
  36. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/json_pointer.py +0 -0
  37. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/local.py +0 -0
  38. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/local_models.py +0 -0
  39. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/local_telemetry.py +0 -0
  40. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/native_adapter.py +0 -0
  41. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/native_schema.py +0 -0
  42. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/output_budget.py +0 -0
  43. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/provider_error.py +0 -0
  44. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/research_kernels.py +0 -0
  45. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/runner.py +0 -0
  46. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/system_one.py +0 -0
  47. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/telemetry.py +0 -0
  48. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/templates.py +0 -0
  49. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/tokenizer.py +0 -0
  50. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime/tool_wire.py +0 -0
  51. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime.egg-info/dependency_links.txt +0 -0
  52. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime.egg-info/requires.txt +0 -0
  53. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/seldon_runtime.egg-info/top_level.txt +0 -0
  54. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/setup.cfg +0 -0
  55. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/fixtures/compiler-artifact/manifest.json +0 -0
  56. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/fixtures/compiler-artifact-dev1/manifest.json +0 -0
  57. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/fixtures/digest_goldens.json +0 -0
  58. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/fixtures/local_gliner_raw.json +0 -0
  59. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/fixtures/serving_compat/function-plan-v1.json +0 -0
  60. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/fixtures/serving_compat/function-plan-v2.json +0 -0
  61. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/fixtures/serving_compat/function-plan-v3.json +0 -0
  62. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/fixtures/serving_compat/function-plan-v4.json +0 -0
  63. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/fixtures/serving_compat/function-plan-v5.json +0 -0
  64. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/fixtures/tokenizer_goldens.json +0 -0
  65. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/installed_local_probe.py +0 -0
  66. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/test_contracts.py +0 -0
  67. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/test_correctness_repairs.py +0 -0
  68. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/test_gliner_normalize.py +0 -0
  69. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/test_import_closure.py +0 -0
  70. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/test_install.py +0 -0
  71. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/test_local.py +0 -0
  72. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/test_runner.py +0 -0
  73. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/test_tokenizer.py +0 -0
  74. {seldon_runtime-0.1.1.dev3 → seldon_runtime-0.1.1.dev4}/tests/tokenizer_cases.py +0 -0
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1.dev4 — unreleased
4
+
5
+ - Add optional data-only `FunctionSpec.reference_program` for existing multi-call
6
+ workflows with deterministic final processing and bounded conditional execution.
7
+ A single central reference-plan constructor preserves the complete graph for
8
+ compiler reference/direct candidates and runtime failure fallback; previously
9
+ each path rebuilt bare LLM steps and lost application output assembly.
10
+ - Preserve exact saved requests and existing step/call limits. Reject altered
11
+ prompts, extra paid calls, native/generated reference steps and recursive fallback.
12
+ Apply frozen graph permissions to the reference even when the selected plan is simple.
13
+ - Require a dev4 artifact reader when the new field is present; retain old source
14
+ digests and dev1/dev2 chat/dev3 native artifact compatibility. Regenerate the schema.
15
+ - Add dependency, pointer, conditional skip, fallback and installed-artifact probes.
16
+ This change does not publish a package or qualify a live provider.
17
+
18
+ - Add source-grounded span decisions, contextual quotation grounding, combined
19
+ overlap reconciliation and bounded ordered JSON serialization for complete
20
+ reference workflows. Raw response quotation metadata cannot grant trusted
21
+ provenance. Historical runtime versions cannot claim support for these kernels.
22
+
3
23
  ## 0.1.1.dev3 — unreleased
4
24
 
5
25
  - Accept native System One `choice` and Fastino GLiNER `extract` plans in standalone
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: seldon-runtime
3
- Version: 0.1.1.dev3
3
+ Version: 0.1.1.dev4
4
4
  Summary: Standalone Seldon Functions interpreter and local execution client
5
5
  License-Expression: Apache-2.0
6
6
  Project-URL: Source, https://github.com/Deep-Insight-Labs/seldon-runtime
@@ -44,8 +44,8 @@ CLI can compile Functions, produce comparison reports and explicitly export
44
44
  selected artifacts today; it requires no platform account. This standalone path is separate from hosted Runner bundle
45
45
  eligibility and fallback.
46
46
 
47
- The source checkout targets **0.1.1.dev3 (unreleased)**, adding standalone native
48
- artifact bindings. Install this checkout with `python -m pip install .` to use
47
+ The source checkout targets **0.1.1.dev4 (unreleased)**, adding declared reference
48
+ workflows alongside standalone native artifact bindings. Install this checkout with `python -m pip install .` to use
49
49
  that capability; the published dev2 package does not accept native artifacts.
50
50
 
51
51
  ## Install
@@ -175,9 +175,9 @@ a development environment with `python -m pip install '.[schema]'` followed by
175
175
  that generator's `--check` mode, independently of the runtime compatibility matrix.
176
176
 
177
177
  The manifest freezes the compiler version and an explicit runtime version. New
178
- exports target the source runtime version (`0.1.1.dev3`). Its reader accepts
179
- the reviewed set `0.1.1.dev1`, `0.1.1.dev2` and `0.1.1.dev3`; original manifests retain
180
- their pin and hashes. Native artifacts must declare dev3; older runtime contracts
178
+ exports target the source runtime version (`0.1.1.dev4`). Its reader accepts
179
+ the reviewed set `0.1.1.dev1`, `0.1.1.dev2`, `0.1.1.dev3` and `0.1.1.dev4`; original manifests retain
180
+ their pin and hashes. Native artifacts require dev3 or dev4; older runtime contracts
181
181
  remain chat/deterministic-only. dev0 and future versions are rejected until explicitly
182
182
  reviewed; there is no version-prefix or range-based compatibility inference.
183
183
  The manifest also freezes the optimizer contract (v1–v8), evaluation semantics,
@@ -215,7 +215,7 @@ policy before invoking a provider; your transport still owns TLS, credential ori
215
215
  binding, response-size limits and protocol decoding. Known transport failures use
216
216
  `ProviderError`; untyped failures stop without automatic fallback or retry.
217
217
 
218
- The source dev3 handoff supports OpenAI-compatible chat, native `choice`/`extract`
218
+ The source dev4 handoff supports OpenAI-compatible chat, native `choice`/`extract`
219
219
  and deterministic operators, including versioned chunking/conditional graphs.
220
220
  Native bindings declare `protocol="system_one"` with `capabilities=("choice",)` or
221
221
  `protocol="fastino_gliner"` with `capabilities=("extract",)`, a nonempty `upstream_model`
@@ -300,3 +300,43 @@ No stored registry token is required. Registry versions are immutable.
300
300
  Apache-2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE). Optional GLiNER2 code and
301
301
  downloaded weights retain their own upstream licenses. The release is scoped to
302
302
  this repository; it does not license the separately operated Seldon service.
303
+
304
+ ## Declared reference workflows
305
+
306
+ An optional `FunctionSpec.reference_program` supplies the existing workflow as a
307
+ bounded `Plan`. Use it when the reference performs deterministic processing or
308
+ conditional execution around its saved LLM calls. Without it, reference execution
309
+ remains the ordered saved calls and returns the last result. Omitted or null programs
310
+ preserve existing source serialization and digests.
311
+
312
+ Each saved call must appear exactly once statically, with its original call ID,
313
+ model and request; branches may skip a call at execution time. The program may use
314
+ the existing deterministic operators and forward-only branch/merge/return nodes,
315
+ within the existing step limits. Generated kernels, native model steps, added paid
316
+ calls, altered prompts/configuration and reference fallback are rejected. Input and
317
+ intermediate JSON pointers are validated using the existing program/schema rules.
318
+
319
+ For example, two saved calls can finish with an `object` step whose `inputs` are
320
+ `["validate#", "augment#"]` and whose `config` is
321
+ `{"fields": ["validation", "augmentation"]}`. This returns both results without
322
+ another model request. A downstream deterministic operator can instead produce the
323
+ final domain output. The final value must satisfy the Function's output schema.
324
+
325
+ The compiler's direct substitutions preserve this exact graph and replace only
326
+ LLM models. Explicit failure fallback executes the complete declared reference,
327
+ including its original branching and output processing. Both selected and reference
328
+ graphs must satisfy frozen conditional/chunking permissions before execution.
329
+ Artifacts containing `reference_program` require runtime dev4; older readers fail
330
+ closed rather than discard workflow behavior. Existing dev1/dev2 chat and dev3
331
+ native artifacts remain readable with their original version pins and hashes.
332
+
333
+ The v7 component registry additionally exposes bounded `apply_span_decisions`,
334
+ `ground_span_quotes`, `reconcile_span_candidates`, and `encode_json` kernels.
335
+ Span decisions operate on authoritative source coordinates. Quotation grounding
336
+ retains every exact contextual occurrence and exposes failures for conditional
337
+ repair; raw model responses cannot supply trusted provenance. Reconcile all
338
+ stage claims together before resolving overlaps. Missing configured response
339
+ collections default to empty; explicit nulls and invalid types fail.
340
+ `encode_json` emits standard JSON spacing, supports explicit field order, and
341
+ bounds depth, node count, collection sizes and UTF-8 output bytes. These kernels
342
+ require the dev4 artifact reader and are hidden from historical compiler registries.
@@ -18,8 +18,8 @@ CLI can compile Functions, produce comparison reports and explicitly export
18
18
  selected artifacts today; it requires no platform account. This standalone path is separate from hosted Runner bundle
19
19
  eligibility and fallback.
20
20
 
21
- The source checkout targets **0.1.1.dev3 (unreleased)**, adding standalone native
22
- artifact bindings. Install this checkout with `python -m pip install .` to use
21
+ The source checkout targets **0.1.1.dev4 (unreleased)**, adding declared reference
22
+ workflows alongside standalone native artifact bindings. Install this checkout with `python -m pip install .` to use
23
23
  that capability; the published dev2 package does not accept native artifacts.
24
24
 
25
25
  ## Install
@@ -149,9 +149,9 @@ a development environment with `python -m pip install '.[schema]'` followed by
149
149
  that generator's `--check` mode, independently of the runtime compatibility matrix.
150
150
 
151
151
  The manifest freezes the compiler version and an explicit runtime version. New
152
- exports target the source runtime version (`0.1.1.dev3`). Its reader accepts
153
- the reviewed set `0.1.1.dev1`, `0.1.1.dev2` and `0.1.1.dev3`; original manifests retain
154
- their pin and hashes. Native artifacts must declare dev3; older runtime contracts
152
+ exports target the source runtime version (`0.1.1.dev4`). Its reader accepts
153
+ the reviewed set `0.1.1.dev1`, `0.1.1.dev2`, `0.1.1.dev3` and `0.1.1.dev4`; original manifests retain
154
+ their pin and hashes. Native artifacts require dev3 or dev4; older runtime contracts
155
155
  remain chat/deterministic-only. dev0 and future versions are rejected until explicitly
156
156
  reviewed; there is no version-prefix or range-based compatibility inference.
157
157
  The manifest also freezes the optimizer contract (v1–v8), evaluation semantics,
@@ -189,7 +189,7 @@ policy before invoking a provider; your transport still owns TLS, credential ori
189
189
  binding, response-size limits and protocol decoding. Known transport failures use
190
190
  `ProviderError`; untyped failures stop without automatic fallback or retry.
191
191
 
192
- The source dev3 handoff supports OpenAI-compatible chat, native `choice`/`extract`
192
+ The source dev4 handoff supports OpenAI-compatible chat, native `choice`/`extract`
193
193
  and deterministic operators, including versioned chunking/conditional graphs.
194
194
  Native bindings declare `protocol="system_one"` with `capabilities=("choice",)` or
195
195
  `protocol="fastino_gliner"` with `capabilities=("extract",)`, a nonempty `upstream_model`
@@ -274,3 +274,43 @@ No stored registry token is required. Registry versions are immutable.
274
274
  Apache-2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE). Optional GLiNER2 code and
275
275
  downloaded weights retain their own upstream licenses. The release is scoped to
276
276
  this repository; it does not license the separately operated Seldon service.
277
+
278
+ ## Declared reference workflows
279
+
280
+ An optional `FunctionSpec.reference_program` supplies the existing workflow as a
281
+ bounded `Plan`. Use it when the reference performs deterministic processing or
282
+ conditional execution around its saved LLM calls. Without it, reference execution
283
+ remains the ordered saved calls and returns the last result. Omitted or null programs
284
+ preserve existing source serialization and digests.
285
+
286
+ Each saved call must appear exactly once statically, with its original call ID,
287
+ model and request; branches may skip a call at execution time. The program may use
288
+ the existing deterministic operators and forward-only branch/merge/return nodes,
289
+ within the existing step limits. Generated kernels, native model steps, added paid
290
+ calls, altered prompts/configuration and reference fallback are rejected. Input and
291
+ intermediate JSON pointers are validated using the existing program/schema rules.
292
+
293
+ For example, two saved calls can finish with an `object` step whose `inputs` are
294
+ `["validate#", "augment#"]` and whose `config` is
295
+ `{"fields": ["validation", "augmentation"]}`. This returns both results without
296
+ another model request. A downstream deterministic operator can instead produce the
297
+ final domain output. The final value must satisfy the Function's output schema.
298
+
299
+ The compiler's direct substitutions preserve this exact graph and replace only
300
+ LLM models. Explicit failure fallback executes the complete declared reference,
301
+ including its original branching and output processing. Both selected and reference
302
+ graphs must satisfy frozen conditional/chunking permissions before execution.
303
+ Artifacts containing `reference_program` require runtime dev4; older readers fail
304
+ closed rather than discard workflow behavior. Existing dev1/dev2 chat and dev3
305
+ native artifacts remain readable with their original version pins and hashes.
306
+
307
+ The v7 component registry additionally exposes bounded `apply_span_decisions`,
308
+ `ground_span_quotes`, `reconcile_span_candidates`, and `encode_json` kernels.
309
+ Span decisions operate on authoritative source coordinates. Quotation grounding
310
+ retains every exact contextual occurrence and exposes failures for conditional
311
+ repair; raw model responses cannot supply trusted provenance. Reconcile all
312
+ stage claims together before resolving overlaps. Missing configured response
313
+ collections default to empty; explicit nulls and invalid types fail.
314
+ `encode_json` emits standard JSON spacing, supports explicit field order, and
315
+ bounds depth, node count, collection sizes and UTF-8 output bytes. These kernels
316
+ require the dev4 artifact reader and are hidden from historical compiler registries.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "seldon-runtime"
7
- version = "0.1.1.dev3"
7
+ version = "0.1.1.dev4"
8
8
  description = "Standalone Seldon Functions interpreter and local execution client"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -4,6 +4,7 @@ templates
4
4
  tool_wire
5
5
  conditional
6
6
  semantic
7
+ span_review
7
8
  executor
8
9
  components
9
10
  research_kernels
@@ -674,6 +674,17 @@
674
674
  "title": "Output Schema",
675
675
  "type": "object"
676
676
  },
677
+ "reference_program": {
678
+ "anyOf": [
679
+ {
680
+ "$ref": "#/$defs/Plan"
681
+ },
682
+ {
683
+ "type": "null"
684
+ }
685
+ ],
686
+ "default": null
687
+ },
677
688
  "evaluator": {
678
689
  "default": "exact",
679
690
  "enum": [
@@ -1410,7 +1421,11 @@
1410
1421
  "project_records",
1411
1422
  "merge_spans",
1412
1423
  "merge_records",
1413
- "merge_labels"
1424
+ "merge_labels",
1425
+ "apply_span_decisions",
1426
+ "ground_span_quotes",
1427
+ "reconcile_span_candidates",
1428
+ "encode_json"
1414
1429
  ],
1415
1430
  "title": "Op",
1416
1431
  "type": "string"
@@ -1639,7 +1654,8 @@
1639
1654
  "enum": [
1640
1655
  "0.1.1.dev1",
1641
1656
  "0.1.1.dev2",
1642
- "0.1.1.dev3"
1657
+ "0.1.1.dev3",
1658
+ "0.1.1.dev4"
1643
1659
  ],
1644
1660
  "title": "Runtime Version",
1645
1661
  "type": "string"
@@ -1,3 +1,3 @@
1
1
  """Standalone Seldon Functions interpreter and local execution client."""
2
2
 
3
- __version__ = "0.1.1.dev3"
3
+ __version__ = "0.1.1.dev4"
@@ -27,7 +27,7 @@ from .program_validation import validate_program
27
27
  from .provider_error import ProviderError
28
28
 
29
29
  MAX_ARTIFACT_BYTES = 2 * 1024 * 1024
30
- RUNTIME_VERSION = "0.1.1.dev3"
30
+ RUNTIME_VERSION = "0.1.1.dev4"
31
31
  _SHA256 = r"^[0-9a-f]{64}$"
32
32
  Capability = Literal["chat", "structured_output", "tools", "choice", "extract"]
33
33
  OptimizerContract = Literal[
@@ -87,7 +87,7 @@ class ArtifactManifest(_Data):
87
87
  compiler_version: str = Field(min_length=1, max_length=64, pattern=r"^[a-zA-Z0-9.+_-]+$")
88
88
  # Explicit reviewed reader compatibility, never a version-prefix/range guess.
89
89
  # dev3 adds explicit native bindings; older artifacts retain their restrictions.
90
- runtime_version: Literal["0.1.1.dev1", "0.1.1.dev2", "0.1.1.dev3"]
90
+ runtime_version: Literal["0.1.1.dev1", "0.1.1.dev2", "0.1.1.dev3", "0.1.1.dev4"]
91
91
  optimizer_contract_version: OptimizerContract
92
92
  instruction_envelope: Literal["instruction-envelope-v1"] | None
93
93
  conditional: bool = Field(strict=True)
@@ -164,7 +164,12 @@ def _parse(data: bytes) -> ArtifactManifest:
164
164
  raise ValueError
165
165
  manifest = ArtifactManifest.model_validate(raw)
166
166
  native = [step for step in manifest.plan.steps if step.op in {"choice", "extract"}]
167
- if native and manifest.runtime_version != RUNTIME_VERSION:
167
+ if native and manifest.runtime_version not in {"0.1.1.dev3", "0.1.1.dev4"}:
168
+ raise ValueError
169
+ if (
170
+ manifest.spec.reference_program is not None
171
+ and manifest.runtime_version != RUNTIME_VERSION
172
+ ):
168
173
  raise ValueError
169
174
  if (
170
175
  digest({k: v for k, v in raw.items() if k != "manifest_digest"})
@@ -178,16 +183,26 @@ def _parse(data: bytes) -> ArtifactManifest:
178
183
  raise ValueError
179
184
  plan = manifest.plan
180
185
  contract = manifest.optimizer_contract_version
181
- if plan.version == "function-plan-v4" and contract in {
182
- "optimizer-correctness-v1",
183
- "optimizer-correctness-v2",
184
- }:
185
- raise ValueError
186
- if plan.version == "function-plan-v5" and (
187
- not manifest.conditional
188
- or contract in {f"optimizer-correctness-v{i}" for i in range(1, 5)}
186
+ checked_plans = [plan]
187
+ if manifest.spec.reference_program is not None:
188
+ checked_plans.append(manifest.spec.reference_program)
189
+ from .semantic import SPAN_REVIEW_OPERATORS
190
+
191
+ if manifest.runtime_version != RUNTIME_VERSION and any(
192
+ step.op in SPAN_REVIEW_OPERATORS for checked in checked_plans for step in checked.steps
189
193
  ):
190
194
  raise ValueError
195
+ for checked in checked_plans:
196
+ if checked.version == "function-plan-v4" and contract in {
197
+ "optimizer-correctness-v1",
198
+ "optimizer-correctness-v2",
199
+ }:
200
+ raise ValueError
201
+ if checked.version == "function-plan-v5" and (
202
+ not manifest.conditional
203
+ or contract in {f"optimizer-correctness-v{i}" for i in range(1, 5)}
204
+ ):
205
+ raise ValueError
191
206
  validate_program(plan, manifest.spec)
192
207
  required = _required_capabilities(plan, manifest.spec)
193
208
  if set(manifest.models) != set(required):
@@ -45,7 +45,7 @@ def collection(properties, maximum, required=None):
45
45
  "items": {
46
46
  "type": "object",
47
47
  "properties": properties,
48
- "required": required or list(properties),
48
+ "required": list(properties) if required is None else required,
49
49
  },
50
50
  }
51
51
 
@@ -84,7 +84,106 @@ LINKS = collection(
84
84
  32,
85
85
  )
86
86
 
87
+ SPAN_TEXT = {"type": "string", "maxLength": 262144}
88
+ SPAN_LABEL = {"type": "string", "minLength": 1, "maxLength": 128}
89
+ SPAN_PROPERTIES = {
90
+ "text": SPAN_TEXT,
91
+ "label": SPAN_LABEL,
92
+ "start": {"type": "integer", "minimum": 0},
93
+ "end": {"type": "integer", "minimum": 1},
94
+ "accepted": {"type": "boolean"},
95
+ "source_priority": {"type": "integer", "minimum": 0},
96
+ "source_instance": {"type": "string", "maxLength": 256},
97
+ "score_group": {"type": "string", "maxLength": 256},
98
+ "score": {"type": "number"},
99
+ }
100
+ REVIEW_CANDIDATES = collection(
101
+ {
102
+ **SPAN_PROPERTIES,
103
+ "id": {"type": "string", "minLength": 1, "maxLength": 128},
104
+ "needs_review": {"type": "boolean"},
105
+ },
106
+ 1000,
107
+ ["id", "text", "label", "start", "end"],
108
+ )
109
+ REVIEW_DECISIONS = collection(
110
+ {
111
+ "id": {"type": "string", "maxLength": 128},
112
+ "decision": {"enum": [None, "keep", "drop", "reclass"]},
113
+ "proposed_label": {"type": ["string", "null"], "maxLength": 128},
114
+ },
115
+ 1000,
116
+ [],
117
+ )
118
+ REVIEW_SPANS = collection(
119
+ SPAN_PROPERTIES, 1000, ["text", "label", "start", "end", "accepted", "source_priority"]
120
+ )
121
+ SPAN_POLICY = {
122
+ "type": "object",
123
+ "properties": {
124
+ "allowed_labels": {"type": ["array", "null"], "maxItems": 128, "items": SPAN_LABEL},
125
+ "excluded_labels": {"type": "array", "maxItems": 128, "items": SPAN_LABEL},
126
+ },
127
+ "additionalProperties": False,
128
+ }
129
+ SPAN_QUOTES = collection(
130
+ {"label": SPAN_LABEL, "reason": {"type": ["string", "null"]}}, 1000, ["label"]
131
+ )
132
+ GROUNDED_QUOTES = {
133
+ "type": "object",
134
+ "properties": {
135
+ "spans": REVIEW_SPANS,
136
+ "failed_quotes": collection(
137
+ {
138
+ "index": {"type": "integer", "minimum": 0},
139
+ "quote": {"type": "object"},
140
+ "reason": {
141
+ "enum": [
142
+ "non_verbatim_value",
143
+ "missing_context",
144
+ "non_verbatim_context",
145
+ "zero_contextual_matches",
146
+ ]
147
+ },
148
+ },
149
+ 1000,
150
+ ),
151
+ "failed_count": {"type": "integer", "minimum": 0, "maximum": 1000},
152
+ "repair_quotes": {"type": "array", "maxItems": 1000, "items": {"type": "object"}},
153
+ "normalized_quotes": SPAN_QUOTES,
154
+ },
155
+ "required": ["spans", "failed_quotes", "failed_count", "repair_quotes", "normalized_quotes"],
156
+ "additionalProperties": False,
157
+ }
158
+
87
159
  SEMANTIC_IO = {
160
+ "apply_span_decisions": (
161
+ [
162
+ SPAN_TEXT,
163
+ REVIEW_CANDIDATES,
164
+ {"anyOf": [REVIEW_DECISIONS, {"type": "object"}]},
165
+ SPAN_POLICY,
166
+ ],
167
+ REVIEW_SPANS,
168
+ ),
169
+ "ground_span_quotes": (
170
+ [SPAN_TEXT, {"anyOf": [SPAN_QUOTES, {"type": "object"}]}, SPAN_POLICY],
171
+ GROUNDED_QUOTES,
172
+ ),
173
+ "reconcile_span_candidates": (
174
+ [
175
+ SPAN_TEXT,
176
+ {
177
+ "type": "object",
178
+ "maxProperties": 1000,
179
+ "additionalProperties": collection(
180
+ SPAN_PROPERTIES, 1000, ["text", "label", "start", "end"]
181
+ ),
182
+ },
183
+ ],
184
+ REVIEW_SPANS,
185
+ ),
186
+ "encode_json": ([{}], {"type": "string", "maxLength": 262144}),
88
187
  "align_spans": (
89
188
  [STRING, collection({"text": STRING, "label": STRING}, 32)],
90
189
  collection(
@@ -134,6 +233,18 @@ SEMANTIC_IO = {
134
233
  }
135
234
 
136
235
  CONFIG_FIELDS = {
236
+ "decisions_field": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"},
237
+ "quotes_field": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"},
238
+ "quote_field": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"},
239
+ "before_field": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"},
240
+ "after_field": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"},
241
+ "source_priority": {"type": "integer", "minimum": 0},
242
+ "field_order": {
243
+ "type": "array",
244
+ "maxItems": 64,
245
+ "uniqueItems": True,
246
+ "items": {"type": "string", "minLength": 1, "maxLength": 128},
247
+ },
137
248
  "casefold": {"type": "boolean"},
138
249
  "unique": {"type": "boolean"},
139
250
  "size": {"type": "integer", "minimum": 1, "maximum": 16384},
@@ -225,6 +225,8 @@ def binding_states(plan, spec):
225
225
  if step.bind_call not in calls:
226
226
  raise ValueError("unknown_call")
227
227
  shared[step.bind_call] = step.id
228
+ if spec.reference_program is not None:
229
+ shared[step.id] = step.id
228
230
  after[step.id] = shared
229
231
  return before
230
232
 
@@ -545,6 +545,7 @@ class FunctionSpec(Contract):
545
545
  template_syntax: Literal["python_format", "jinja_variables"] | None = None
546
546
  bindings: list[Binding] = Field(default_factory=list, max_length=64)
547
547
  output_schema: dict[str, Any]
548
+ reference_program: Plan | None = None
548
549
  evaluator: Literal["exact", "records", "decimal", "rubric"] = "exact"
549
550
  evaluation_pending: bool = False
550
551
  rubric: Rubric | None = None
@@ -566,6 +567,8 @@ class FunctionSpec(Contract):
566
567
  value.pop("evaluation", None)
567
568
  if self.input_schema is None:
568
569
  value.pop("input_schema", None)
570
+ if self.reference_program is None:
571
+ value.pop("reference_program", None)
569
572
  if self.preparation is None:
570
573
  value.pop("preparation", None)
571
574
  if self.template_syntax is None:
@@ -622,13 +625,49 @@ class FunctionSpec(Contract):
622
625
  ids = [c.id for c in self.calls]
623
626
  if len(set(ids)) != len(ids) or "input" in ids:
624
627
  raise ValueError("duplicate_call_id")
628
+ if self.reference_program is not None:
629
+ program = self.reference_program
630
+ if program.fallback:
631
+ raise ValueError("reference_program_has_fallback")
632
+ declared = {call.id: call for call in self.calls}
633
+ bound = []
634
+ for step in program.steps:
635
+ if step.op in {"generated_kernel", "choice", "extract"}:
636
+ raise ValueError("unsupported_reference_operation")
637
+ if step.op == "llm":
638
+ call = declared.get(step.call)
639
+ if call is None or step.id != call.id or step.model != call.model:
640
+ raise ValueError("reference_call_mismatch")
641
+ if (
642
+ step.instruction_mode != "original_call_ref"
643
+ or step.prompt is not None
644
+ or step.messages is not None
645
+ or step.output_schema is not None
646
+ or step.inputs
647
+ or step.config
648
+ or step.output_binding != "call"
649
+ or step.over is not None
650
+ or step.max_chunks is not None
651
+ ):
652
+ raise ValueError("reference_call_modified")
653
+ bound.append(step.call)
654
+ if len(bound) != len(self.calls) or set(bound) != set(declared):
655
+ raise ValueError("reference_calls_incomplete")
656
+ from .program_validation import validate_program
657
+
658
+ validate_program(program, self)
625
659
  occupied = set()
626
660
  for binding in self.bindings:
627
661
  if binding.call not in ids:
628
662
  raise ValueError("unknown_call")
629
663
  call = self.calls[ids.index(binding.call)]
630
664
  root, _ = reference(binding.source)
631
- if root != "input" and root not in ids[: ids.index(binding.call)]:
665
+ prior_roots = ids[: ids.index(binding.call)]
666
+ if self.reference_program is not None:
667
+ steps = self.reference_program.steps
668
+ call_position = next(i for i, step in enumerate(steps) if step.call == binding.call)
669
+ prior_roots = [step.id for step in steps[:call_position]]
670
+ if root != "input" and root not in prior_roots:
632
671
  raise ValueError("forward_reference")
633
672
  if binding.message >= len(call.messages):
634
673
  raise ValueError("missing_message")
@@ -682,6 +721,10 @@ class Step(Contract):
682
721
  "merge_spans",
683
722
  "merge_records",
684
723
  "merge_labels",
724
+ "apply_span_decisions",
725
+ "ground_span_quotes",
726
+ "reconcile_span_candidates",
727
+ "encode_json",
685
728
  ]
686
729
  inputs: list[str] = Field(default_factory=list, max_length=32)
687
730
  config: dict[str, Any] = Field(default_factory=dict)
@@ -858,3 +901,31 @@ class Plan(Contract):
858
901
  elif learned > 3:
859
902
  raise ValueError("model_call_limit")
860
903
  return self
904
+
905
+
906
+ def reference_plan(
907
+ spec: FunctionSpec,
908
+ *,
909
+ model_overrides: dict[str, str] | None = None,
910
+ version: str = "function-plan-v2",
911
+ ) -> Plan:
912
+ """Preserve declared workflow control and deterministic processing in every reader."""
913
+ overrides = model_overrides or {}
914
+ if not set(overrides) <= {call.id for call in spec.calls}:
915
+ raise ValueError("unknown_call")
916
+ if spec.reference_program is not None:
917
+ values = spec.reference_program.model_dump(mode="json")
918
+ for step in values["steps"]:
919
+ if step["op"] == "llm":
920
+ step["model"] = overrides.get(step["call"], step["model"])
921
+ return Plan.model_validate(values)
922
+ return Plan(
923
+ version=version,
924
+ steps=[
925
+ Step(id=call.id, op="llm", model=overrides.get(call.id, call.model), call=call.id)
926
+ for call in spec.calls
927
+ ],
928
+ )
929
+
930
+
931
+ FunctionSpec.model_rebuild()
@@ -17,7 +17,15 @@ from typing import Any
17
17
 
18
18
  from jsonschema import Draft202012Validator
19
19
 
20
- from .contracts import FunctionSpec, Plan, Step, canonical, digest, reference, semantic_plan
20
+ from .contracts import (
21
+ FunctionSpec,
22
+ Plan,
23
+ canonical,
24
+ digest,
25
+ reference,
26
+ reference_plan,
27
+ semantic_plan,
28
+ )
21
29
  from .provider_error import ProviderError
22
30
 
23
31
 
@@ -381,7 +389,8 @@ def step_payload(spec, step, inputs, prior, values, *, instruction_envelope=None
381
389
 
382
390
  if instruction_envelope != INSTRUCTION_ENVELOPE_CONTRACT:
383
391
  raise ValueError("instruction_envelope_unsupported")
384
- payload = render_request(spec, step.call, inputs, prior)
392
+ bindings = {**values, **prior} if spec.reference_program is not None else prior
393
+ payload = render_request(spec, step.call, inputs, bindings)
385
394
  if "max_tokens" not in payload:
386
395
  # Explicit null freezes provider omission even when a run normally sizes
387
396
  # output itself; the request marker also reserves the endpoint ceiling.
@@ -598,6 +607,9 @@ async def _execute(
598
607
  if not probe and len(canonical(value).encode()) > 262144:
599
608
  raise ValueError("intermediate_size_limit")
600
609
  values[step.id] = value
610
+ if spec.reference_program is not None:
611
+ # Match validation's latest dominating producer for step/call collisions.
612
+ prior[step.id] = value
601
613
  if trace is not None:
602
614
  record["output"] = evidence_value(value)
603
615
  predecessor = step.id
@@ -683,8 +695,9 @@ async def execute(
683
695
  in {EVALUATION_FIDELITY_CONTRACT, SPAN_GROUNDING_CONTRACT, CORRECTNESS_REPAIR_CONTRACT}
684
696
  and conditional is not False
685
697
  )
686
- if plan.version == "function-plan-v5" and not v5_allowed:
687
- raise ValueError("plan_version_unsupported")
698
+ checked_plans = [plan]
699
+ if spec.reference_program is not None:
700
+ checked_plans.append(spec.reference_program)
688
701
  chunking = {
689
702
  CONTEXT_CHUNKING_CONTRACT,
690
703
  "optimizer-correctness-v4",
@@ -693,12 +706,15 @@ async def execute(
693
706
  SPAN_GROUNDING_CONTRACT,
694
707
  CORRECTNESS_REPAIR_CONTRACT,
695
708
  }
696
- if plan.version == "function-plan-v4" and contract not in chunking:
697
- raise ValueError("plan_version_unsupported")
698
- if any(step.config.get("view") == "bindings" for step in plan.steps) and (
699
- contract not in chunking
700
- ):
701
- raise ValueError("view_requires_v3")
709
+ for checked in checked_plans:
710
+ if checked.version == "function-plan-v5" and not v5_allowed:
711
+ raise ValueError("plan_version_unsupported")
712
+ if checked.version == "function-plan-v4" and contract not in chunking:
713
+ raise ValueError("plan_version_unsupported")
714
+ if any(step.config.get("view") == "bindings" for step in checked.steps) and (
715
+ contract not in chunking
716
+ ):
717
+ raise ValueError("view_requires_v3")
702
718
  from .deadline import admission_deadline
703
719
 
704
720
  with admission_deadline(time.monotonic() + timeout):
@@ -829,9 +845,7 @@ async def _execute_with_fallback(
829
845
  )
830
846
  if not plan.fallback or not allowed:
831
847
  raise
832
- original = Plan(
833
- steps=[Step(id=c.id, op="llm", model=c.model, call=c.id) for c in spec.calls]
834
- )
848
+ original = reference_plan(spec, version="function-plan-v1")
835
849
  fallback_phase = True
836
850
  remaining = timeout - (time.monotonic() - start)
837
851
  result = await _execute(