helios-serve 0.3.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.
- helios_serve-0.3.0/.gitignore +18 -0
- helios_serve-0.3.0/PKG-INFO +163 -0
- helios_serve-0.3.0/README.md +136 -0
- helios_serve-0.3.0/pyproject.toml +58 -0
- helios_serve-0.3.0/src/helios_serve/__init__.py +44 -0
- helios_serve-0.3.0/src/helios_serve/checks.py +141 -0
- helios_serve-0.3.0/src/helios_serve/commands.py +104 -0
- helios_serve-0.3.0/src/helios_serve/evaluation.py +462 -0
- helios_serve-0.3.0/src/helios_serve/py.typed +0 -0
- helios_serve-0.3.0/src/helios_serve/registry.py +286 -0
- helios_serve-0.3.0/src/helios_serve/stores.py +194 -0
- helios_serve-0.3.0/src/helios_serve/tools.py +532 -0
- helios_serve-0.3.0/tests/conftest.py +3 -0
- helios_serve-0.3.0/tests/fixtures/customer360.ossie.json +105 -0
- helios_serve-0.3.0/tests/fixtures/shop.ossie.json +229 -0
- helios_serve-0.3.0/tests/test_evaluation_library.py +313 -0
- helios_serve-0.3.0/tests/test_serve_health.py +119 -0
- helios_serve-0.3.0/tests/test_serve_package.py +50 -0
- helios_serve-0.3.0/tests/test_tool_behaviour.py +208 -0
- helios_serve-0.3.0/tests/test_tool_registry.py +204 -0
- helios_serve-0.3.0/tests/test_tools.py +259 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: helios-serve
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Helios tools: list, describe, compile and query published semantic models, as plain Python functions
|
|
5
|
+
Project-URL: Homepage, https://github.com/christopheraburns/helios
|
|
6
|
+
Project-URL: Documentation, https://github.com/christopheraburns/helios/tree/main/packages/helios-serve#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/christopheraburns/helios
|
|
8
|
+
Project-URL: Issues, https://github.com/christopheraburns/helios/issues
|
|
9
|
+
Author: Helios Team
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
Keywords: evaluation,llm tools,ossie,semantic layer,text-to-sql
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Database
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: helios-cortex>=0.3.0
|
|
24
|
+
Provides-Extra: eval
|
|
25
|
+
Requires-Dist: helios-cortex[llm]>=0.3.0; extra == 'eval'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# helios-serve
|
|
29
|
+
|
|
30
|
+
The Helios tools, as plain Python functions: list the published semantic models,
|
|
31
|
+
describe one, search their semantics, compile a question into SQL, run it as the
|
|
32
|
+
caller, and explain a column's lineage.
|
|
33
|
+
|
|
34
|
+
helios-serve depends only on helios-cortex. It has no MCP dependency and no HTTP
|
|
35
|
+
server: Daedalus serves the tools to shared, governed deployments, and helios-mcp
|
|
36
|
+
serves them over stdio to one developer's local agent.
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from helios_cortex import Caller
|
|
40
|
+
from helios_cortex.settings import Settings
|
|
41
|
+
from helios_serve import Stores, tools
|
|
42
|
+
|
|
43
|
+
stores = Stores.from_settings(Settings()) # the registry and the published models
|
|
44
|
+
alice = Caller("alice") # whoever the host says is asking
|
|
45
|
+
|
|
46
|
+
tools.search_semantics(alice, stores, question="revenue by region")
|
|
47
|
+
tools.compile_query(alice, stores, metrics=["revenue"], dimensions=["shop.customers.c_region"])
|
|
48
|
+
tools.run_query(alice, stores, metrics=["revenue"], dimensions=["shop.customers.c_region"])
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Every tool is `tool(caller, stores, **arguments) -> dict`, with keyword arguments:
|
|
52
|
+
|
|
53
|
+
| Tool | What it returns |
|
|
54
|
+
|---|---|
|
|
55
|
+
| `list_models` | `{"models": [{"name", "status"}]}`: the published models the caller may see |
|
|
56
|
+
| `describe_model` | datasets, fields, metrics and relationships of a model (the first when `model` is omitted) |
|
|
57
|
+
| `search_semantics` | the datasets, fields and metrics a natural-language `question` involves |
|
|
58
|
+
| `describe` | one dataset, column (`database.table.column`) or metric by `name` |
|
|
59
|
+
| `compile_query` | SQL for `metrics`, `dimensions`, `filters`, in `dialect` (default: the model's own connection's) |
|
|
60
|
+
| `run_query` | the query's `columns` and `rows`, run on the model's connection as the caller |
|
|
61
|
+
| `explain_lineage` | a `column`'s lineage from a catalog that has it (Atlas in helios-cloudera) |
|
|
62
|
+
|
|
63
|
+
Only published models are served; an unreviewed proposal never is. A tool returns
|
|
64
|
+
`{"error": code, "message": ..., "retryable": ...}` for anything the caller can fix
|
|
65
|
+
rather than raising.
|
|
66
|
+
|
|
67
|
+
`Stores` holds what the tools read, and each part is the host's to replace:
|
|
68
|
+
`visibility` (which models a caller may see), `data_policy` (which queries may run;
|
|
69
|
+
by default only those the warehouse runs as the caller), `audit` (where a record of
|
|
70
|
+
each call goes, with administrator-only diagnostics for errors), `engines` and
|
|
71
|
+
`catalogs` (how a connection or a catalog is built).
|
|
72
|
+
|
|
73
|
+
## The tool registry
|
|
74
|
+
|
|
75
|
+
A server (Daedalus, helios-mcp) offers the tools from one source, the registry:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from helios_serve import load_registry
|
|
79
|
+
|
|
80
|
+
registry = load_registry()
|
|
81
|
+
for tool in registry.tools():
|
|
82
|
+
tool.name, tool.description, tool.input_schema, tool.effect # what a server offers
|
|
83
|
+
registry.call("run_query", alice, stores, metrics=["revenue"]) # same as tools.run_query
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`input_schema` is JSON Schema built from the function's type hints (`Annotated[T,
|
|
87
|
+
"text"]` describes a parameter; a `TypedDict` is an object). It keeps to what MCP and
|
|
88
|
+
OpenAPI 3.0 share: an optional argument is left out of `required`, never typed `null`.
|
|
89
|
+
`effect` is `read` (Helios metadata only) or `query` (runs SQL on the warehouse as the
|
|
90
|
+
caller: `run_query` alone); no tool changes data. `registry.tools(effects={"read"})` is
|
|
91
|
+
a read-only metadata server.
|
|
92
|
+
|
|
93
|
+
`explain_lineage` is offered only when an installed catalog plugin has lineage (Atlas,
|
|
94
|
+
in helios-cloudera), so a base install lists six tools and one with helios-cloudera
|
|
95
|
+
seven.
|
|
96
|
+
|
|
97
|
+
Another package adds a tool by marking a function and registering it under the tool's
|
|
98
|
+
name:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from helios_serve import tool
|
|
102
|
+
|
|
103
|
+
@tool(effect="read", description="What an agent reads to decide when to call it.")
|
|
104
|
+
def row_count(caller, stores, *, table: str) -> dict: ...
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```toml
|
|
108
|
+
[project.entry-points."helios.tools"]
|
|
109
|
+
row_count = "my_package.tools:row_count"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Health
|
|
113
|
+
|
|
114
|
+
`health(stores)` says whether the deployment can answer, for a host to serve wherever it
|
|
115
|
+
reports health (an HTTP `/healthz`, a Daedalus probe, a CLI):
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from helios_serve import health
|
|
119
|
+
|
|
120
|
+
health(stores) # the model registry and the published models
|
|
121
|
+
health(stores, deep=True) # also pings each warehouse connection and the catalog
|
|
122
|
+
# {"status": "healthy", "version": "0.1.0", "model_count": 3,
|
|
123
|
+
# "components": [{"id": "registry", "label": ..., "status": "healthy", "description": ...}, ...]}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
A component is `healthy`, `degraded` (reachable but not ready: a registry schema that
|
|
127
|
+
needs `helios registry upgrade`, or nothing published yet), `unavailable`, or `unknown`
|
|
128
|
+
(nothing configured to check). The deployment is `unavailable` when the registry or the
|
|
129
|
+
models are, `degraded` when any checked component is not healthy, and `healthy`
|
|
130
|
+
otherwise. Descriptions are fixed sentences: an exception's text never reaches the
|
|
131
|
+
result or the log. A deep check pings with the connection's own (service) credentials.
|
|
132
|
+
|
|
133
|
+
## Evaluation
|
|
134
|
+
|
|
135
|
+
`helios_serve.evaluation` measures how well an LLM answers questions through the tools.
|
|
136
|
+
A suite is a JSON list of questions, each with the SQL whose result is the right answer;
|
|
137
|
+
the LLM answers through the registry's tools, called directly as the caller (no MCP
|
|
138
|
+
server), and an answer is accurate when its last query returns the reference result.
|
|
139
|
+
Path metrics (tool calls, invalid and redundant calls, recovery, grounding, tokens, time)
|
|
140
|
+
are aggregated per LLM variant. It needs an LLM client: `pip install "helios-serve[eval]"`.
|
|
141
|
+
|
|
142
|
+
```sh
|
|
143
|
+
helios eval sample-suite.json # a suite file: helios init --sample writes this one
|
|
144
|
+
helios eval sample-suite.json --candidate-model claude-opus-5-5 # compare the configured model with another
|
|
145
|
+
helios eval --list # the suites saved in this deployment
|
|
146
|
+
helios eval my-suite --json # a saved suite by id; the full report
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from helios_serve.evaluation import read_suite, run_evaluation
|
|
151
|
+
|
|
152
|
+
report = run_evaluation(read_suite("sample-suite.json"), stores, {"baseline": llm, "candidate": other},
|
|
153
|
+
caller=alice)
|
|
154
|
+
report.metrics["candidate"]["answer_accuracy"]
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
No suite ships in the package. A deployment keeps its own in `<data_dir>/state/eval-suites`
|
|
158
|
+
(`save_suite`, then `load_suite(id)`); the repository's `examples/eval/tpcds-v1.json` has 20
|
|
159
|
+
questions for a full TPC-DS warehouse. Without `--as`,
|
|
160
|
+
`helios eval` is one user running with the configured credentials, so it allows queries
|
|
161
|
+
on a service-identity connection (`single_user_policy()`); with `--as USER` the
|
|
162
|
+
warehouse enforces that user's access, as for any caller.
|
|
163
|
+
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# helios-serve
|
|
2
|
+
|
|
3
|
+
The Helios tools, as plain Python functions: list the published semantic models,
|
|
4
|
+
describe one, search their semantics, compile a question into SQL, run it as the
|
|
5
|
+
caller, and explain a column's lineage.
|
|
6
|
+
|
|
7
|
+
helios-serve depends only on helios-cortex. It has no MCP dependency and no HTTP
|
|
8
|
+
server: Daedalus serves the tools to shared, governed deployments, and helios-mcp
|
|
9
|
+
serves them over stdio to one developer's local agent.
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from helios_cortex import Caller
|
|
13
|
+
from helios_cortex.settings import Settings
|
|
14
|
+
from helios_serve import Stores, tools
|
|
15
|
+
|
|
16
|
+
stores = Stores.from_settings(Settings()) # the registry and the published models
|
|
17
|
+
alice = Caller("alice") # whoever the host says is asking
|
|
18
|
+
|
|
19
|
+
tools.search_semantics(alice, stores, question="revenue by region")
|
|
20
|
+
tools.compile_query(alice, stores, metrics=["revenue"], dimensions=["shop.customers.c_region"])
|
|
21
|
+
tools.run_query(alice, stores, metrics=["revenue"], dimensions=["shop.customers.c_region"])
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Every tool is `tool(caller, stores, **arguments) -> dict`, with keyword arguments:
|
|
25
|
+
|
|
26
|
+
| Tool | What it returns |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `list_models` | `{"models": [{"name", "status"}]}`: the published models the caller may see |
|
|
29
|
+
| `describe_model` | datasets, fields, metrics and relationships of a model (the first when `model` is omitted) |
|
|
30
|
+
| `search_semantics` | the datasets, fields and metrics a natural-language `question` involves |
|
|
31
|
+
| `describe` | one dataset, column (`database.table.column`) or metric by `name` |
|
|
32
|
+
| `compile_query` | SQL for `metrics`, `dimensions`, `filters`, in `dialect` (default: the model's own connection's) |
|
|
33
|
+
| `run_query` | the query's `columns` and `rows`, run on the model's connection as the caller |
|
|
34
|
+
| `explain_lineage` | a `column`'s lineage from a catalog that has it (Atlas in helios-cloudera) |
|
|
35
|
+
|
|
36
|
+
Only published models are served; an unreviewed proposal never is. A tool returns
|
|
37
|
+
`{"error": code, "message": ..., "retryable": ...}` for anything the caller can fix
|
|
38
|
+
rather than raising.
|
|
39
|
+
|
|
40
|
+
`Stores` holds what the tools read, and each part is the host's to replace:
|
|
41
|
+
`visibility` (which models a caller may see), `data_policy` (which queries may run;
|
|
42
|
+
by default only those the warehouse runs as the caller), `audit` (where a record of
|
|
43
|
+
each call goes, with administrator-only diagnostics for errors), `engines` and
|
|
44
|
+
`catalogs` (how a connection or a catalog is built).
|
|
45
|
+
|
|
46
|
+
## The tool registry
|
|
47
|
+
|
|
48
|
+
A server (Daedalus, helios-mcp) offers the tools from one source, the registry:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from helios_serve import load_registry
|
|
52
|
+
|
|
53
|
+
registry = load_registry()
|
|
54
|
+
for tool in registry.tools():
|
|
55
|
+
tool.name, tool.description, tool.input_schema, tool.effect # what a server offers
|
|
56
|
+
registry.call("run_query", alice, stores, metrics=["revenue"]) # same as tools.run_query
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`input_schema` is JSON Schema built from the function's type hints (`Annotated[T,
|
|
60
|
+
"text"]` describes a parameter; a `TypedDict` is an object). It keeps to what MCP and
|
|
61
|
+
OpenAPI 3.0 share: an optional argument is left out of `required`, never typed `null`.
|
|
62
|
+
`effect` is `read` (Helios metadata only) or `query` (runs SQL on the warehouse as the
|
|
63
|
+
caller: `run_query` alone); no tool changes data. `registry.tools(effects={"read"})` is
|
|
64
|
+
a read-only metadata server.
|
|
65
|
+
|
|
66
|
+
`explain_lineage` is offered only when an installed catalog plugin has lineage (Atlas,
|
|
67
|
+
in helios-cloudera), so a base install lists six tools and one with helios-cloudera
|
|
68
|
+
seven.
|
|
69
|
+
|
|
70
|
+
Another package adds a tool by marking a function and registering it under the tool's
|
|
71
|
+
name:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from helios_serve import tool
|
|
75
|
+
|
|
76
|
+
@tool(effect="read", description="What an agent reads to decide when to call it.")
|
|
77
|
+
def row_count(caller, stores, *, table: str) -> dict: ...
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```toml
|
|
81
|
+
[project.entry-points."helios.tools"]
|
|
82
|
+
row_count = "my_package.tools:row_count"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Health
|
|
86
|
+
|
|
87
|
+
`health(stores)` says whether the deployment can answer, for a host to serve wherever it
|
|
88
|
+
reports health (an HTTP `/healthz`, a Daedalus probe, a CLI):
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from helios_serve import health
|
|
92
|
+
|
|
93
|
+
health(stores) # the model registry and the published models
|
|
94
|
+
health(stores, deep=True) # also pings each warehouse connection and the catalog
|
|
95
|
+
# {"status": "healthy", "version": "0.1.0", "model_count": 3,
|
|
96
|
+
# "components": [{"id": "registry", "label": ..., "status": "healthy", "description": ...}, ...]}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
A component is `healthy`, `degraded` (reachable but not ready: a registry schema that
|
|
100
|
+
needs `helios registry upgrade`, or nothing published yet), `unavailable`, or `unknown`
|
|
101
|
+
(nothing configured to check). The deployment is `unavailable` when the registry or the
|
|
102
|
+
models are, `degraded` when any checked component is not healthy, and `healthy`
|
|
103
|
+
otherwise. Descriptions are fixed sentences: an exception's text never reaches the
|
|
104
|
+
result or the log. A deep check pings with the connection's own (service) credentials.
|
|
105
|
+
|
|
106
|
+
## Evaluation
|
|
107
|
+
|
|
108
|
+
`helios_serve.evaluation` measures how well an LLM answers questions through the tools.
|
|
109
|
+
A suite is a JSON list of questions, each with the SQL whose result is the right answer;
|
|
110
|
+
the LLM answers through the registry's tools, called directly as the caller (no MCP
|
|
111
|
+
server), and an answer is accurate when its last query returns the reference result.
|
|
112
|
+
Path metrics (tool calls, invalid and redundant calls, recovery, grounding, tokens, time)
|
|
113
|
+
are aggregated per LLM variant. It needs an LLM client: `pip install "helios-serve[eval]"`.
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
helios eval sample-suite.json # a suite file: helios init --sample writes this one
|
|
117
|
+
helios eval sample-suite.json --candidate-model claude-opus-5-5 # compare the configured model with another
|
|
118
|
+
helios eval --list # the suites saved in this deployment
|
|
119
|
+
helios eval my-suite --json # a saved suite by id; the full report
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from helios_serve.evaluation import read_suite, run_evaluation
|
|
124
|
+
|
|
125
|
+
report = run_evaluation(read_suite("sample-suite.json"), stores, {"baseline": llm, "candidate": other},
|
|
126
|
+
caller=alice)
|
|
127
|
+
report.metrics["candidate"]["answer_accuracy"]
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
No suite ships in the package. A deployment keeps its own in `<data_dir>/state/eval-suites`
|
|
131
|
+
(`save_suite`, then `load_suite(id)`); the repository's `examples/eval/tpcds-v1.json` has 20
|
|
132
|
+
questions for a full TPC-DS warehouse. Without `--as`,
|
|
133
|
+
`helios eval` is one user running with the configured credentials, so it allows queries
|
|
134
|
+
on a service-identity connection (`single_user_policy()`); with `--as USER` the
|
|
135
|
+
warehouse enforces that user's access, as for any caller.
|
|
136
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "helios-serve"
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "Helios tools: list, describe, compile and query published semantic models, as plain Python functions"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{name = "Helios Team"}]
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
|
+
keywords = ["semantic layer", "text-to-sql", "llm tools", "ossie", "evaluation"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Database",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
# helios-cortex only. No MCP SDK and no web framework: the tools are plain functions with
|
|
27
|
+
# metadata; Daedalus (shared) and helios-mcp (local stdio) serve them over MCP.
|
|
28
|
+
dependencies = [
|
|
29
|
+
"helios-cortex>=0.3.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/christopheraburns/helios"
|
|
34
|
+
Documentation = "https://github.com/christopheraburns/helios/tree/main/packages/helios-serve#readme"
|
|
35
|
+
Repository = "https://github.com/christopheraburns/helios"
|
|
36
|
+
Issues = "https://github.com/christopheraburns/helios/issues"
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
# helios eval and helios_serve.evaluation talk to an LLM (helios-cortex's LLM client).
|
|
40
|
+
eval = ["helios-cortex[llm]>=0.3.0"]
|
|
41
|
+
|
|
42
|
+
# The tool registry (helios_serve.load_registry) reads this group; the entry-point name
|
|
43
|
+
# is the tool's name. explain_lineage is offered only beside a catalog with lineage.
|
|
44
|
+
[project.entry-points."helios.tools"]
|
|
45
|
+
list_models = "helios_serve.tools:list_models"
|
|
46
|
+
describe_model = "helios_serve.tools:describe_model"
|
|
47
|
+
search_semantics = "helios_serve.tools:search_semantics"
|
|
48
|
+
describe = "helios_serve.tools:describe"
|
|
49
|
+
compile_query = "helios_serve.tools:compile_query"
|
|
50
|
+
run_query = "helios_serve.tools:run_query"
|
|
51
|
+
explain_lineage = "helios_serve.tools:explain_lineage"
|
|
52
|
+
|
|
53
|
+
# helios eval: run an evaluation suite through the tools.
|
|
54
|
+
[project.entry-points."helios.commands"]
|
|
55
|
+
eval = "helios_serve.commands:EvalCommand"
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.wheel]
|
|
58
|
+
packages = ["src/helios_serve"]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Helios tools: what an agent or an application asks of published semantic models
|
|
2
|
+
(burndown Phase 6).
|
|
3
|
+
|
|
4
|
+
The seven structured tools (list and describe models, search their semantics, compile
|
|
5
|
+
and run queries, explain lineage) are plain functions ``(caller, stores, **arguments)
|
|
6
|
+
-> dict``, registered under the ``helios.tools`` entry point; ``load_registry()`` lists
|
|
7
|
+
every installed tool with its description, input schema and effect. helios-serve
|
|
8
|
+
has no MCP dependency and no HTTP server: Daedalus serves the tools to shared
|
|
9
|
+
deployments and helios-mcp to one developer's local agent.
|
|
10
|
+
|
|
11
|
+
helios-serve depends on helios-cortex alone; engines and catalogs come from plugins.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
_EXPORTS = {
|
|
16
|
+
"Stores": "stores", "ModelStore": "stores", "ModelNotAvailable": "stores", "model_connection": "stores",
|
|
17
|
+
"single_user_policy": "stores",
|
|
18
|
+
**{name: "tools" for name in ("list_models", "describe_model", "search_semantics", "describe",
|
|
19
|
+
"compile_query", "run_query", "query_values", "explain_lineage",
|
|
20
|
+
"QueryFilter")},
|
|
21
|
+
**{name: "evaluation" for name in ("run_evaluation", "answer_question", "list_suites", "load_suite", "read_suite", "save_suite",
|
|
22
|
+
"EvaluationReport", "EvaluationError")},
|
|
23
|
+
"health": "checks", "HealthComponent": "checks", "aggregate_status": "checks",
|
|
24
|
+
**{name: "registry" for name in ("Effect", "Registry", "Tool", "tool", "load_registry", "input_schema")},
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
__all__ = sorted(_EXPORTS)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def __getattr__(name: str):
|
|
31
|
+
# Exports are imported on first use, so importing helios_serve loads no engine or
|
|
32
|
+
# store code; __version__ is read from the installed metadata.
|
|
33
|
+
if name in _EXPORTS:
|
|
34
|
+
from importlib import import_module
|
|
35
|
+
|
|
36
|
+
return getattr(import_module(f"helios_serve.{_EXPORTS[name]}"), name)
|
|
37
|
+
if name == "__version__":
|
|
38
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
return version("helios-serve")
|
|
42
|
+
except PackageNotFoundError: # running from a source path without an install
|
|
43
|
+
return "0.0.0+unknown"
|
|
44
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""Whether a deployment can answer: ``health(stores) -> dict`` (exported as ``helios_serve.health``).
|
|
2
|
+
|
|
3
|
+
health(stores) the registry and the published models
|
|
4
|
+
health(stores, deep=True) also each configured warehouse connection and the catalog
|
|
5
|
+
|
|
6
|
+
A host serves the result wherever it reports health (an HTTP ``/healthz``, a Daedalus
|
|
7
|
+
probe, a CLI). Each check runs on its own, so one failed dependency does not hide the
|
|
8
|
+
rest, and a check's description is a fixed sentence: an exception's text (which can
|
|
9
|
+
carry a host name, a URL or a token) never reaches the result or the log.
|
|
10
|
+
|
|
11
|
+
The result::
|
|
12
|
+
|
|
13
|
+
{"status": "healthy" | "degraded" | "unavailable",
|
|
14
|
+
"version": "<helios-serve version>",
|
|
15
|
+
"model_count": 3, # published models; None when unreadable
|
|
16
|
+
"components": [{"id", "label", "status", "description"}, ...]}
|
|
17
|
+
|
|
18
|
+
A component is ``healthy``, ``degraded`` (reachable but not ready, such as a registry
|
|
19
|
+
schema that needs an upgrade), ``unavailable`` or ``unknown`` (not checked: nothing
|
|
20
|
+
configured). The deployment is ``unavailable`` when the registry or the models are,
|
|
21
|
+
since no tool can answer then; ``degraded`` when any checked component is not healthy;
|
|
22
|
+
``healthy`` otherwise. ``unknown`` components do not count.
|
|
23
|
+
"""
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import logging
|
|
27
|
+
from collections.abc import Callable
|
|
28
|
+
from functools import partial
|
|
29
|
+
from dataclasses import asdict, dataclass
|
|
30
|
+
from typing import Any, Literal
|
|
31
|
+
|
|
32
|
+
from helios_serve.stores import Stores
|
|
33
|
+
|
|
34
|
+
LOGGER = logging.getLogger(__name__)
|
|
35
|
+
|
|
36
|
+
HealthState = Literal["healthy", "degraded", "unavailable", "unknown"]
|
|
37
|
+
ESSENTIAL = frozenset({"registry", "models"}) # without these no tool can answer
|
|
38
|
+
_PROBE = "__helios_health__" # a data-source id no deployment uses
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(frozen=True)
|
|
42
|
+
class HealthComponent:
|
|
43
|
+
id: str
|
|
44
|
+
label: str
|
|
45
|
+
status: HealthState
|
|
46
|
+
description: str
|
|
47
|
+
|
|
48
|
+
def to_dict(self) -> dict[str, str]:
|
|
49
|
+
return asdict(self)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def aggregate_status(components: list[HealthComponent]) -> HealthState:
|
|
53
|
+
"""``unavailable`` when an essential component is; ``degraded`` when any checked
|
|
54
|
+
component is not healthy; ``healthy`` otherwise (``unknown`` ones are skipped)."""
|
|
55
|
+
if any(c.id in ESSENTIAL and c.status == "unavailable" for c in components):
|
|
56
|
+
return "unavailable"
|
|
57
|
+
checked = [c for c in components if c.status != "unknown"]
|
|
58
|
+
if not checked:
|
|
59
|
+
return "unavailable"
|
|
60
|
+
return "healthy" if all(c.status == "healthy" for c in checked) else "degraded"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _failed(component_id: str, exc: BaseException) -> None:
|
|
64
|
+
# The type only: the message may name a host or carry a credential.
|
|
65
|
+
LOGGER.warning("health check %s failed: %s", component_id, type(exc).__name__)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _registry(stores: Stores) -> HealthComponent:
|
|
69
|
+
from helios_cortex.registry import RegistryError
|
|
70
|
+
|
|
71
|
+
label = "Model registry"
|
|
72
|
+
try:
|
|
73
|
+
stores.registry.data_source(_PROBE) # one read, on any registry backend
|
|
74
|
+
except RegistryError as exc: # RegistryNotReady: reachable, schema not current
|
|
75
|
+
_failed("registry", exc)
|
|
76
|
+
return HealthComponent("registry", label, "degraded",
|
|
77
|
+
"The model registry is reachable but its schema is not current; "
|
|
78
|
+
"run `helios registry upgrade`.")
|
|
79
|
+
except Exception as exc:
|
|
80
|
+
_failed("registry", exc)
|
|
81
|
+
return HealthComponent("registry", label, "unavailable", "The model registry could not be read.")
|
|
82
|
+
return HealthComponent("registry", label, "healthy", "The model registry is readable.")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _models(stores: Stores) -> tuple[HealthComponent, int | None]:
|
|
86
|
+
label = "Published models"
|
|
87
|
+
try:
|
|
88
|
+
count = len(stores.models.sources())
|
|
89
|
+
except Exception as exc:
|
|
90
|
+
_failed("models", exc)
|
|
91
|
+
return HealthComponent("models", label, "unavailable", "The published models could not be listed."), None
|
|
92
|
+
if count == 0:
|
|
93
|
+
return HealthComponent("models", label, "degraded", "No model is published yet."), 0
|
|
94
|
+
return HealthComponent("models", label, "healthy",
|
|
95
|
+
f"{count} published model{'s' if count != 1 else ''}."), count
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _probe(component_id: str, label: str, build: Callable[[], Any], what: str) -> HealthComponent:
|
|
99
|
+
try:
|
|
100
|
+
target = build()
|
|
101
|
+
if target is None:
|
|
102
|
+
return HealthComponent(component_id, label, "unknown", f"{what} is not configured.")
|
|
103
|
+
if target.ping():
|
|
104
|
+
return HealthComponent(component_id, label, "healthy", f"{what} responded.")
|
|
105
|
+
except Exception as exc:
|
|
106
|
+
_failed(component_id, exc)
|
|
107
|
+
return HealthComponent(component_id, label, "unavailable", f"{what} did not respond.")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _connections(stores: Stores) -> list[HealthComponent]:
|
|
111
|
+
return [_probe(f"connection:{name}", f"Warehouse connection {name}",
|
|
112
|
+
partial(stores.engines, name), f"The {name} warehouse connection")
|
|
113
|
+
for name in sorted(stores.settings.connections)]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _catalog(stores: Stores) -> HealthComponent:
|
|
117
|
+
label = "Data catalog"
|
|
118
|
+
try:
|
|
119
|
+
catalog = stores.catalogs()
|
|
120
|
+
except Exception as exc: # a missing plugin, bad options
|
|
121
|
+
_failed("catalog", exc)
|
|
122
|
+
return HealthComponent("catalog", label, "unavailable", "The data catalog could not be built.")
|
|
123
|
+
if catalog is not None and not callable(getattr(catalog, "ping", None)):
|
|
124
|
+
return HealthComponent("catalog", label, "unknown", "The data catalog has no health check.")
|
|
125
|
+
return _probe("catalog", label, lambda: catalog, "The data catalog")
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def health(stores: Stores, *, deep: bool = False) -> dict[str, Any]:
|
|
129
|
+
"""The deployment's health: the registry and the published models, and with ``deep``
|
|
130
|
+
each configured warehouse connection and the catalog (each pinged with the service's
|
|
131
|
+
own credentials, so a deep check costs a round trip per connection)."""
|
|
132
|
+
import helios_serve
|
|
133
|
+
|
|
134
|
+
components = [_registry(stores)]
|
|
135
|
+
models, count = _models(stores)
|
|
136
|
+
components.append(models)
|
|
137
|
+
if deep:
|
|
138
|
+
components += _connections(stores)
|
|
139
|
+
components.append(_catalog(stores))
|
|
140
|
+
return {"status": aggregate_status(components), "version": helios_serve.__version__, "model_count": count,
|
|
141
|
+
"components": [c.to_dict() for c in components]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""``helios eval``: run an evaluation suite against the configured LLM (helios.commands)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from helios_cortex.cli import CommandError, add_caller_argument
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from helios_cortex.cli import CommandContext
|
|
12
|
+
|
|
13
|
+
SUMMARY = (("answer_accuracy", "accuracy", "{:.0%}"), ("completion_rate", "completed", "{:.0%}"),
|
|
14
|
+
("tool_calls", "tool calls", "{:g}"), ("invalid_call_rate", "invalid", "{:.0%}"),
|
|
15
|
+
("redundant_call_rate", "redundant", "{:.0%}"), ("grounding_rate", "grounded", "{:.0%}"),
|
|
16
|
+
("tokens_per_correct_answer", "tokens/correct", "{:,.0f}"))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class EvalCommand:
|
|
20
|
+
help = "ask an evaluation suite's questions of the LLM through the Helios tools and score the answers"
|
|
21
|
+
|
|
22
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
23
|
+
parser.add_argument("suite", nargs="?",
|
|
24
|
+
help="a suite file (.json), or the id of a suite saved in <data_dir>/state/eval-suites")
|
|
25
|
+
parser.add_argument("--version", dest="suite_version", metavar="VERSION",
|
|
26
|
+
help="the suite version (default: the latest)")
|
|
27
|
+
parser.add_argument("--suite-file", metavar="FILE", help="read the suite from FILE instead")
|
|
28
|
+
parser.add_argument("--list", action="store_true", help="list the available suites and exit")
|
|
29
|
+
parser.add_argument("--model", metavar="ID", help="the published model to answer from (default: the suite's)")
|
|
30
|
+
parser.add_argument("--candidate-model", metavar="NAME",
|
|
31
|
+
help="also run the configured LLM provider with model NAME and compare the two")
|
|
32
|
+
parser.add_argument("--repetitions", type=int, default=1, metavar="N", help="ask each question N times")
|
|
33
|
+
parser.add_argument("--max-tool-rounds", type=int, default=6, metavar="N",
|
|
34
|
+
help="the most LLM rounds per answer (default 6)")
|
|
35
|
+
parser.add_argument("--question", action="append", metavar="ID", help="only this question (repeat for more)")
|
|
36
|
+
parser.add_argument("--json", action="store_true", help="write the full report as JSON")
|
|
37
|
+
add_caller_argument(parser, "answer and run the reference queries")
|
|
38
|
+
|
|
39
|
+
def run(self, args: argparse.Namespace, context: CommandContext) -> int:
|
|
40
|
+
from helios_serve import evaluation
|
|
41
|
+
from helios_serve.stores import Stores, single_user_policy
|
|
42
|
+
|
|
43
|
+
settings = context.settings
|
|
44
|
+
directory = evaluation.suite_directory(settings)
|
|
45
|
+
if args.list:
|
|
46
|
+
for suite in evaluation.list_suites(directory):
|
|
47
|
+
context.echo(f"{suite['id']} {suite['version']} {len(suite['questions'])} questions"
|
|
48
|
+
+ (f" (model {suite['model_id']})" if suite.get("model_id") else ""))
|
|
49
|
+
return 0
|
|
50
|
+
if not (args.suite or args.suite_file):
|
|
51
|
+
raise CommandError("name a suite: a suite file, or the id of a saved one (helios eval --list); "
|
|
52
|
+
"helios init --sample writes sample-suite.json")
|
|
53
|
+
try:
|
|
54
|
+
if args.suite_file or args.suite.endswith(".json"):
|
|
55
|
+
suite = evaluation.read_suite(args.suite_file or args.suite)
|
|
56
|
+
else:
|
|
57
|
+
suite = evaluation.load_suite(args.suite, args.suite_version, directory=directory)
|
|
58
|
+
except (LookupError, evaluation.EvaluationError) as exc:
|
|
59
|
+
raise CommandError(str(exc.args[0]) if exc.args else str(exc)) from exc
|
|
60
|
+
if args.question:
|
|
61
|
+
wanted = set(args.question)
|
|
62
|
+
suite = {**suite, "questions": [q for q in suite["questions"] if q["id"] in wanted]}
|
|
63
|
+
missing = wanted - {q["id"] for q in suite["questions"]}
|
|
64
|
+
if missing:
|
|
65
|
+
raise CommandError(f"no question {', '.join(sorted(missing))} in suite {suite['id']}")
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
from helios_cortex.llm import llm_from_settings
|
|
69
|
+
except ModuleNotFoundError as exc:
|
|
70
|
+
raise CommandError("helios eval needs an LLM client: pip install 'helios-serve[eval]'") from exc
|
|
71
|
+
llm = llm_from_settings(settings.llm)
|
|
72
|
+
if llm is None:
|
|
73
|
+
raise CommandError("no LLM is configured; set [llm] provider and its key in helios.toml")
|
|
74
|
+
variants = {"baseline": llm}
|
|
75
|
+
if args.candidate_model:
|
|
76
|
+
candidate = llm_from_settings(settings.llm.model_copy(update={"model": args.candidate_model}))
|
|
77
|
+
if candidate is None:
|
|
78
|
+
raise CommandError(f"no LLM client for the candidate model {args.candidate_model!r}")
|
|
79
|
+
variants["candidate"] = candidate
|
|
80
|
+
|
|
81
|
+
caller = context.caller(args.caller)
|
|
82
|
+
# Without --as the command's own user runs it with the configured credentials (as
|
|
83
|
+
# `helios harvest` does); with --as the warehouse enforces that user's access.
|
|
84
|
+
stores = Stores.from_settings(settings, **({} if caller else {"data_policy": single_user_policy()}))
|
|
85
|
+
try:
|
|
86
|
+
report = evaluation.run_evaluation(
|
|
87
|
+
suite, stores, variants, caller=caller,
|
|
88
|
+
model=args.model, repetitions=args.repetitions, max_tool_rounds=args.max_tool_rounds)
|
|
89
|
+
except evaluation.EvaluationError as exc:
|
|
90
|
+
raise CommandError(str(exc)) from exc
|
|
91
|
+
|
|
92
|
+
if args.json:
|
|
93
|
+
context.echo(json.dumps(report.as_dict(), indent=2, default=str))
|
|
94
|
+
return 0
|
|
95
|
+
context.echo(f"suite {report.suite_id} {report.suite_version}, model {report.model or '(first published)'}"
|
|
96
|
+
+ (" (cancelled)" if report.cancelled else ""))
|
|
97
|
+
for result in report.results:
|
|
98
|
+
mark = "ok " if result.accurate else "MISS"
|
|
99
|
+
context.echo(f" {mark} {result.question_id} {result.variant} #{result.repetition}: "
|
|
100
|
+
f"{result.answer.termination}, {result.metrics['tool_calls']} tool calls")
|
|
101
|
+
for variant, metrics in report.metrics.items():
|
|
102
|
+
name = f"{variant} ({variants[variant].model})"
|
|
103
|
+
context.echo(f"{name}: " + ", ".join(f"{label} {fmt.format(metrics[key])}" for key, label, fmt in SUMMARY))
|
|
104
|
+
return 0
|