fieldworks-core 1.0.1__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.
- fieldworks_core-1.0.1/LICENSE +201 -0
- fieldworks_core-1.0.1/PKG-INFO +70 -0
- fieldworks_core-1.0.1/README.md +35 -0
- fieldworks_core-1.0.1/fieldworks/__init__.py +3 -0
- fieldworks_core-1.0.1/fieldworks/adapters/__init__.py +3 -0
- fieldworks_core-1.0.1/fieldworks/adapters/conformance.py +286 -0
- fieldworks_core-1.0.1/fieldworks/agents/__init__.py +26 -0
- fieldworks_core-1.0.1/fieldworks/agents/caching.py +51 -0
- fieldworks_core-1.0.1/fieldworks/agents/deadband.py +146 -0
- fieldworks_core-1.0.1/fieldworks/agents/specialist.py +171 -0
- fieldworks_core-1.0.1/fieldworks/aggregator/__init__.py +3 -0
- fieldworks_core-1.0.1/fieldworks/aggregator/config.py +53 -0
- fieldworks_core-1.0.1/fieldworks/cli.py +196 -0
- fieldworks_core-1.0.1/fieldworks/memory/__init__.py +19 -0
- fieldworks_core-1.0.1/fieldworks/memory/analytical.py +155 -0
- fieldworks_core-1.0.1/fieldworks/memory/client.py +51 -0
- fieldworks_core-1.0.1/fieldworks/memory/graph.py +603 -0
- fieldworks_core-1.0.1/fieldworks/memory/schema.cypher +142 -0
- fieldworks_core-1.0.1/fieldworks/memory/specialist.py +34 -0
- fieldworks_core-1.0.1/fieldworks/topology/__init__.py +31 -0
- fieldworks_core-1.0.1/fieldworks/topology/loader.py +28 -0
- fieldworks_core-1.0.1/fieldworks/topology/schema.py +241 -0
- fieldworks_core-1.0.1/fieldworks/topology/seeder.py +255 -0
- fieldworks_core-1.0.1/fieldworks/topology/validator.py +71 -0
- fieldworks_core-1.0.1/fieldworks/topology_builder/__init__.py +9 -0
- fieldworks_core-1.0.1/fieldworks/topology_builder/discovery.py +118 -0
- fieldworks_core-1.0.1/fieldworks/topology_builder/inference.py +178 -0
- fieldworks_core-1.0.1/fieldworks/trust/__init__.py +40 -0
- fieldworks_core-1.0.1/fieldworks/trust/audit.py +183 -0
- fieldworks_core-1.0.1/fieldworks/trust/events.py +107 -0
- fieldworks_core-1.0.1/fieldworks/trust/intercept.py +159 -0
- fieldworks_core-1.0.1/fieldworks_core.egg-info/PKG-INFO +70 -0
- fieldworks_core-1.0.1/fieldworks_core.egg-info/SOURCES.txt +57 -0
- fieldworks_core-1.0.1/fieldworks_core.egg-info/dependency_links.txt +1 -0
- fieldworks_core-1.0.1/fieldworks_core.egg-info/entry_points.txt +2 -0
- fieldworks_core-1.0.1/fieldworks_core.egg-info/requires.txt +17 -0
- fieldworks_core-1.0.1/fieldworks_core.egg-info/top_level.txt +1 -0
- fieldworks_core-1.0.1/pyproject.toml +62 -0
- fieldworks_core-1.0.1/setup.cfg +4 -0
- fieldworks_core-1.0.1/tests/test_aggregator.py +79 -0
- fieldworks_core-1.0.1/tests/test_attribute_data_type.py +244 -0
- fieldworks_core-1.0.1/tests/test_caching.py +62 -0
- fieldworks_core-1.0.1/tests/test_cli.py +65 -0
- fieldworks_core-1.0.1/tests/test_conformance.py +74 -0
- fieldworks_core-1.0.1/tests/test_deadband.py +107 -0
- fieldworks_core-1.0.1/tests/test_memory_analytical.py +73 -0
- fieldworks_core-1.0.1/tests/test_memory_client.py +49 -0
- fieldworks_core-1.0.1/tests/test_memory_graph.py +162 -0
- fieldworks_core-1.0.1/tests/test_memory_specialist.py +58 -0
- fieldworks_core-1.0.1/tests/test_seeder.py +59 -0
- fieldworks_core-1.0.1/tests/test_severity_lookup.py +151 -0
- fieldworks_core-1.0.1/tests/test_specialist.py +258 -0
- fieldworks_core-1.0.1/tests/test_topology_builder_discovery.py +112 -0
- fieldworks_core-1.0.1/tests/test_topology_builder_inference.py +253 -0
- fieldworks_core-1.0.1/tests/test_topology_loader.py +217 -0
- fieldworks_core-1.0.1/tests/test_topology_validator.py +169 -0
- fieldworks_core-1.0.1/tests/test_trust_audit.py +110 -0
- fieldworks_core-1.0.1/tests/test_trust_events.py +107 -0
- fieldworks_core-1.0.1/tests/test_trust_intercept.py +90 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fieldworks-core
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Fieldworks industrial AI framework — core components
|
|
5
|
+
Author-email: Sean Slavin <slavin.sean@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/fieldworks-build/fieldworks-core
|
|
8
|
+
Project-URL: Repository, https://github.com/fieldworks-build/fieldworks-core
|
|
9
|
+
Project-URL: Issues, https://github.com/fieldworks-build/fieldworks-core/issues
|
|
10
|
+
Keywords: industrial,ai,agents,mcp,scada,iot
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: pydantic>=2.0
|
|
22
|
+
Requires-Dist: pyyaml>=6.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
25
|
+
Provides-Extra: memory
|
|
26
|
+
Requires-Dist: ladybug; extra == "memory"
|
|
27
|
+
Requires-Dist: duckdb; extra == "memory"
|
|
28
|
+
Requires-Dist: influxdb-client; extra == "memory"
|
|
29
|
+
Requires-Dist: pytz; extra == "memory"
|
|
30
|
+
Provides-Extra: adapters
|
|
31
|
+
Requires-Dist: mcp>=1.0; extra == "adapters"
|
|
32
|
+
Provides-Extra: trust
|
|
33
|
+
Requires-Dist: cryptography>=41.0; extra == "trust"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# fieldworks-core
|
|
37
|
+
|
|
38
|
+
Core components for the Fieldworks industrial AI framework.
|
|
39
|
+
|
|
40
|
+
- `fieldworks.topology` — load and validate `topology.yaml` (plant model schema, Part II)
|
|
41
|
+
- `fieldworks.agents` — `build_specialist_prompt()`, `build_specialists()`, `build_orchestrator_system()`
|
|
42
|
+
- `fieldworks.aggregator` — load and validate `aggregator.json` (connection model, Part II)
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install fieldworks-core
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from fieldworks.topology import load, validate
|
|
54
|
+
from fieldworks.agents import build_specialist_prompt, build_specialists
|
|
55
|
+
|
|
56
|
+
topology = load("topology.yaml")
|
|
57
|
+
result = validate(topology)
|
|
58
|
+
if result.warnings:
|
|
59
|
+
for w in result.warnings:
|
|
60
|
+
print(f"warning: {w}")
|
|
61
|
+
|
|
62
|
+
specialists = build_specialists(topology)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## CLI
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
fieldworks validate topology.yaml
|
|
69
|
+
fieldworks validate topology.yaml --aggregator aggregator.json
|
|
70
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# fieldworks-core
|
|
2
|
+
|
|
3
|
+
Core components for the Fieldworks industrial AI framework.
|
|
4
|
+
|
|
5
|
+
- `fieldworks.topology` — load and validate `topology.yaml` (plant model schema, Part II)
|
|
6
|
+
- `fieldworks.agents` — `build_specialist_prompt()`, `build_specialists()`, `build_orchestrator_system()`
|
|
7
|
+
- `fieldworks.aggregator` — load and validate `aggregator.json` (connection model, Part II)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install fieldworks-core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from fieldworks.topology import load, validate
|
|
19
|
+
from fieldworks.agents import build_specialist_prompt, build_specialists
|
|
20
|
+
|
|
21
|
+
topology = load("topology.yaml")
|
|
22
|
+
result = validate(topology)
|
|
23
|
+
if result.warnings:
|
|
24
|
+
for w in result.warnings:
|
|
25
|
+
print(f"warning: {w}")
|
|
26
|
+
|
|
27
|
+
specialists = build_specialists(topology)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## CLI
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
fieldworks validate topology.yaml
|
|
34
|
+
fieldworks validate topology.yaml --aggregator aggregator.json
|
|
35
|
+
```
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"""Runtime conformance testing against the FieldworksAdapter nine-tool contract.
|
|
2
|
+
|
|
3
|
+
The contract is defined in fieldworks-adapters/fieldworks-adapter-core/src/lib.rs
|
|
4
|
+
and fieldworks-adapters/CLAUDE.md. FieldworksAdapter there is a specification
|
|
5
|
+
document, not compiler-enforced — rmcp's tool macros don't compose with a
|
|
6
|
+
hand-written trait impl, so nothing else checks these guarantees at runtime.
|
|
7
|
+
This module does, by spawning the adapter binary as an MCP stdio subprocess
|
|
8
|
+
and probing it directly.
|
|
9
|
+
|
|
10
|
+
Checks are split into two tiers:
|
|
11
|
+
- Static checks (tool discovery, get_server_info shape) need no live
|
|
12
|
+
connection — both adapters answer these while disconnected.
|
|
13
|
+
- Connection checks (error-code mapping on read_tag/write_tag/
|
|
14
|
+
read_tag_history) require an active connect() to a real broker/server.
|
|
15
|
+
Skipped, not failed, when no host is given — most local runs won't have
|
|
16
|
+
a broker up; CI wires that in separately.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import json
|
|
22
|
+
from dataclasses import dataclass, field
|
|
23
|
+
|
|
24
|
+
from mcp import ClientSession
|
|
25
|
+
from mcp.client.stdio import StdioServerParameters, stdio_client
|
|
26
|
+
|
|
27
|
+
REQUIRED_TOOLS = {
|
|
28
|
+
"connect",
|
|
29
|
+
"disconnect",
|
|
30
|
+
"discover_tags",
|
|
31
|
+
"read_tag",
|
|
32
|
+
"read_tag_history",
|
|
33
|
+
"write_tag",
|
|
34
|
+
"get_server_info",
|
|
35
|
+
}
|
|
36
|
+
SCAN_TOOL_ALTERNATIVES = {"scan", "browse"}
|
|
37
|
+
TREE_TOOL_ALTERNATIVES = {"get_topic_tree", "get_node_tree"}
|
|
38
|
+
|
|
39
|
+
_NONEXISTENT_TAG_ID = "__fieldworks_conformance_nonexistent_tag__"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass
|
|
43
|
+
class CheckResult:
|
|
44
|
+
name: str
|
|
45
|
+
passed: bool
|
|
46
|
+
message: str = ""
|
|
47
|
+
skipped: bool = False
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class ConformanceReport:
|
|
52
|
+
checks: list[CheckResult] = field(default_factory=list)
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def passed(self) -> bool:
|
|
56
|
+
return all(c.passed for c in self.checks if not c.skipped)
|
|
57
|
+
|
|
58
|
+
def add(self, name: str, passed: bool, message: str = "") -> None:
|
|
59
|
+
self.checks.append(CheckResult(name, passed, message))
|
|
60
|
+
|
|
61
|
+
def skip(self, name: str, message: str) -> None:
|
|
62
|
+
self.checks.append(
|
|
63
|
+
CheckResult(name, passed=True, message=message, skipped=True)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _payload(result) -> dict:
|
|
68
|
+
"""Extract the JSON payload from a CallToolResult, preferring structuredContent."""
|
|
69
|
+
if result.structuredContent is not None:
|
|
70
|
+
return result.structuredContent
|
|
71
|
+
if result.content:
|
|
72
|
+
first = result.content[0]
|
|
73
|
+
text = getattr(first, "text", None)
|
|
74
|
+
if text:
|
|
75
|
+
try:
|
|
76
|
+
return json.loads(text)
|
|
77
|
+
except json.JSONDecodeError:
|
|
78
|
+
return {}
|
|
79
|
+
return {}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
async def run_conformance(
|
|
83
|
+
command: str,
|
|
84
|
+
args: list[str] | None = None,
|
|
85
|
+
*,
|
|
86
|
+
connect_host: str | None = None,
|
|
87
|
+
connect_port: int | None = None,
|
|
88
|
+
) -> ConformanceReport:
|
|
89
|
+
"""Run the conformance suite against an adapter launched via stdio.
|
|
90
|
+
|
|
91
|
+
connect_host/connect_port enable the connection-dependent checks
|
|
92
|
+
(error-code mapping). Without them, those checks are skipped.
|
|
93
|
+
"""
|
|
94
|
+
report = ConformanceReport()
|
|
95
|
+
params = StdioServerParameters(command=command, args=args or [])
|
|
96
|
+
|
|
97
|
+
async with stdio_client(params) as (read, write):
|
|
98
|
+
async with ClientSession(read, write) as session:
|
|
99
|
+
await session.initialize()
|
|
100
|
+
|
|
101
|
+
tools_result = await session.list_tools()
|
|
102
|
+
tool_names = {t.name for t in tools_result.tools}
|
|
103
|
+
|
|
104
|
+
_check_tool_discovery(report, tool_names)
|
|
105
|
+
await _check_server_info(report, session, tool_names)
|
|
106
|
+
|
|
107
|
+
if connect_host is None:
|
|
108
|
+
report.skip(
|
|
109
|
+
"connect: establishes a connection",
|
|
110
|
+
"skipped (no connect_host given)",
|
|
111
|
+
)
|
|
112
|
+
report.skip(
|
|
113
|
+
"read_tag: unknown tag_id maps to TAG_NOT_FOUND",
|
|
114
|
+
"skipped (no connect_host given)",
|
|
115
|
+
)
|
|
116
|
+
report.skip(
|
|
117
|
+
"write_tag: rejected write maps to an error code",
|
|
118
|
+
"skipped (no connect_host given)",
|
|
119
|
+
)
|
|
120
|
+
report.skip(
|
|
121
|
+
"read_tag_history: returns VQT list or HISTORY_UNAVAILABLE",
|
|
122
|
+
"skipped (no connect_host given)",
|
|
123
|
+
)
|
|
124
|
+
else:
|
|
125
|
+
connected = await _check_connect(
|
|
126
|
+
report, session, connect_host, connect_port
|
|
127
|
+
)
|
|
128
|
+
if connected:
|
|
129
|
+
await _check_read_tag_not_found(report, session)
|
|
130
|
+
await _check_write_tag_rejected(report, session)
|
|
131
|
+
await _check_read_tag_history(report, session)
|
|
132
|
+
|
|
133
|
+
return report
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _check_tool_discovery(report: ConformanceReport, tool_names: set[str]) -> None:
|
|
137
|
+
missing = REQUIRED_TOOLS - tool_names
|
|
138
|
+
report.add(
|
|
139
|
+
"tool discovery: required tools present",
|
|
140
|
+
not missing,
|
|
141
|
+
"all present" if not missing else f"missing: {sorted(missing)}",
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
scan_found = tool_names & SCAN_TOOL_ALTERNATIVES
|
|
145
|
+
report.add(
|
|
146
|
+
"tool discovery: scan/browse slot filled",
|
|
147
|
+
len(scan_found) >= 1,
|
|
148
|
+
(
|
|
149
|
+
f"found: {sorted(scan_found)}"
|
|
150
|
+
if scan_found
|
|
151
|
+
else "neither 'scan' nor 'browse' present"
|
|
152
|
+
),
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
tree_found = tool_names & TREE_TOOL_ALTERNATIVES
|
|
156
|
+
report.add(
|
|
157
|
+
"tool discovery: get_topic_tree/get_node_tree slot filled",
|
|
158
|
+
len(tree_found) >= 1,
|
|
159
|
+
(
|
|
160
|
+
f"found: {sorted(tree_found)}"
|
|
161
|
+
if tree_found
|
|
162
|
+
else "neither 'get_topic_tree' nor 'get_node_tree' present"
|
|
163
|
+
),
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
async def _check_server_info(
|
|
168
|
+
report: ConformanceReport, session: ClientSession, tool_names: set[str]
|
|
169
|
+
) -> None:
|
|
170
|
+
result = await session.call_tool("get_server_info", {})
|
|
171
|
+
info = _payload(result)
|
|
172
|
+
|
|
173
|
+
required_keys = {
|
|
174
|
+
"server_name",
|
|
175
|
+
"protocol",
|
|
176
|
+
"protocol_version",
|
|
177
|
+
"connected",
|
|
178
|
+
"connection_state",
|
|
179
|
+
"capabilities",
|
|
180
|
+
"uptime_seconds",
|
|
181
|
+
}
|
|
182
|
+
missing_keys = required_keys - info.keys()
|
|
183
|
+
report.add(
|
|
184
|
+
"get_server_info: response shape",
|
|
185
|
+
not result.isError and not missing_keys,
|
|
186
|
+
"ok" if not missing_keys else f"missing keys: {sorted(missing_keys)}",
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
capabilities = set(info.get("capabilities", []))
|
|
190
|
+
missing_caps = tool_names - capabilities
|
|
191
|
+
report.add(
|
|
192
|
+
"get_server_info: capabilities lists discovered tools",
|
|
193
|
+
not missing_caps,
|
|
194
|
+
(
|
|
195
|
+
"ok"
|
|
196
|
+
if not missing_caps
|
|
197
|
+
else f"not listed in capabilities: {sorted(missing_caps)}"
|
|
198
|
+
),
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
async def _check_connect(
|
|
203
|
+
report: ConformanceReport,
|
|
204
|
+
session: ClientSession,
|
|
205
|
+
host: str,
|
|
206
|
+
port: int | None,
|
|
207
|
+
) -> bool:
|
|
208
|
+
args = {"host": host}
|
|
209
|
+
if port is not None:
|
|
210
|
+
args["port"] = port
|
|
211
|
+
result = await session.call_tool("connect", args)
|
|
212
|
+
payload = _payload(result)
|
|
213
|
+
ok = not result.isError and payload.get("connected") is True
|
|
214
|
+
report.add(
|
|
215
|
+
"connect: establishes a connection",
|
|
216
|
+
ok,
|
|
217
|
+
"ok" if ok else f"unexpected response: {payload}",
|
|
218
|
+
)
|
|
219
|
+
return ok
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
async def _check_read_tag_not_found(
|
|
223
|
+
report: ConformanceReport, session: ClientSession
|
|
224
|
+
) -> None:
|
|
225
|
+
result = await session.call_tool("read_tag", {"tag_id": _NONEXISTENT_TAG_ID})
|
|
226
|
+
payload = _payload(result)
|
|
227
|
+
code = payload.get("error", {}).get("code")
|
|
228
|
+
ok = result.isError and code == "TAG_NOT_FOUND"
|
|
229
|
+
report.add(
|
|
230
|
+
"read_tag: unknown tag_id maps to TAG_NOT_FOUND",
|
|
231
|
+
ok,
|
|
232
|
+
"ok" if ok else f"expected error code TAG_NOT_FOUND, got: {payload}",
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
async def _check_write_tag_rejected(
|
|
237
|
+
report: ConformanceReport, session: ClientSession
|
|
238
|
+
) -> None:
|
|
239
|
+
result = await session.call_tool(
|
|
240
|
+
"write_tag",
|
|
241
|
+
{
|
|
242
|
+
"tag_id": _NONEXISTENT_TAG_ID,
|
|
243
|
+
"value": 0.0,
|
|
244
|
+
"units": "",
|
|
245
|
+
"operator_id": "fieldworks-conformance",
|
|
246
|
+
"reason": "conformance check",
|
|
247
|
+
},
|
|
248
|
+
)
|
|
249
|
+
payload = _payload(result)
|
|
250
|
+
code = payload.get("error", {}).get("code")
|
|
251
|
+
ok = result.isError and code in {
|
|
252
|
+
"TAG_NOT_WRITABLE",
|
|
253
|
+
"TAG_NOT_FOUND",
|
|
254
|
+
"PERMISSION_DENIED",
|
|
255
|
+
}
|
|
256
|
+
report.add(
|
|
257
|
+
"write_tag: rejected write maps to an error code",
|
|
258
|
+
ok,
|
|
259
|
+
"ok" if ok else f"expected a rejection error code, got: {payload}",
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
async def _check_read_tag_history(
|
|
264
|
+
report: ConformanceReport, session: ClientSession
|
|
265
|
+
) -> None:
|
|
266
|
+
result = await session.call_tool(
|
|
267
|
+
"read_tag_history",
|
|
268
|
+
{
|
|
269
|
+
"tag_id": _NONEXISTENT_TAG_ID,
|
|
270
|
+
"start_time": "2020-01-01T00:00:00.000Z",
|
|
271
|
+
"end_time": "2020-01-01T01:00:00.000Z",
|
|
272
|
+
},
|
|
273
|
+
)
|
|
274
|
+
payload = _payload(result)
|
|
275
|
+
if result.isError:
|
|
276
|
+
code = payload.get("error", {}).get("code")
|
|
277
|
+
ok = code in {"HISTORY_UNAVAILABLE", "TAG_NOT_FOUND"}
|
|
278
|
+
message = "ok (unsupported)" if ok else f"unexpected error code: {code}"
|
|
279
|
+
else:
|
|
280
|
+
ok = isinstance(payload, list)
|
|
281
|
+
message = (
|
|
282
|
+
"ok (returned a VQT list)"
|
|
283
|
+
if ok
|
|
284
|
+
else f"unexpected response shape: {payload}"
|
|
285
|
+
)
|
|
286
|
+
report.add("read_tag_history: returns VQT list or HISTORY_UNAVAILABLE", ok, message)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from .caching import cache_system, cache_tools
|
|
2
|
+
from .deadband import (
|
|
3
|
+
DEADBAND_TOOLS,
|
|
4
|
+
SEVERITY_TIERS,
|
|
5
|
+
build_deadband_system,
|
|
6
|
+
check_confidence_threshold,
|
|
7
|
+
parse_decision,
|
|
8
|
+
)
|
|
9
|
+
from .specialist import (
|
|
10
|
+
build_specialist_prompt,
|
|
11
|
+
build_specialists,
|
|
12
|
+
build_orchestrator_system,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"build_specialist_prompt",
|
|
17
|
+
"build_specialists",
|
|
18
|
+
"build_orchestrator_system",
|
|
19
|
+
"cache_system",
|
|
20
|
+
"cache_tools",
|
|
21
|
+
"DEADBAND_TOOLS",
|
|
22
|
+
"SEVERITY_TIERS",
|
|
23
|
+
"build_deadband_system",
|
|
24
|
+
"check_confidence_threshold",
|
|
25
|
+
"parse_decision",
|
|
26
|
+
]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""Deterministic prompt-cache injection for Anthropic API calls.
|
|
2
|
+
|
|
3
|
+
Wraps the `cache_control: {"type": "ephemeral"}` pattern validated in
|
|
4
|
+
waterworks-ai's multi_agent_loop.py so any Fieldworks agent gets cache
|
|
5
|
+
hits without hand-rolling the breakpoint placement per call site.
|
|
6
|
+
|
|
7
|
+
Tools are sorted by name before caching — the aggregator's `list_tools()`
|
|
8
|
+
order is not guaranteed stable across restarts, and an unstable tool list
|
|
9
|
+
before the cache breakpoint silently invalidates every cache read.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
CACHE_CONTROL_EPHEMERAL = {"type": "ephemeral"}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def cache_tools(tools: list[dict]) -> list[dict]:
|
|
18
|
+
"""Return tools sorted by name, in Anthropic tool-param shape, with
|
|
19
|
+
cache_control on the last element.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
tools: Dicts with at least "name", "description", "inputSchema"
|
|
23
|
+
(the shape returned by MCP's list_tools()).
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
Dicts with "name", "description", "input_schema", ready to pass
|
|
27
|
+
as the `tools=` kwarg. Empty input returns an empty list.
|
|
28
|
+
"""
|
|
29
|
+
ordered = sorted(tools, key=lambda t: t["name"])
|
|
30
|
+
api_tools = [
|
|
31
|
+
{
|
|
32
|
+
"name": t["name"],
|
|
33
|
+
"description": t["description"],
|
|
34
|
+
"input_schema": t["inputSchema"],
|
|
35
|
+
}
|
|
36
|
+
for t in ordered
|
|
37
|
+
]
|
|
38
|
+
if api_tools:
|
|
39
|
+
api_tools[-1]["cache_control"] = CACHE_CONTROL_EPHEMERAL
|
|
40
|
+
return api_tools
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def cache_system(text: str) -> list[dict]:
|
|
44
|
+
"""Return a `system=` block list with cache_control on the (only) block."""
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
"type": "text",
|
|
48
|
+
"text": text,
|
|
49
|
+
"cache_control": CACHE_CONTROL_EPHEMERAL,
|
|
50
|
+
}
|
|
51
|
+
]
|