itself 0.2.0__py3-none-any.whl
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.
- itself/__init__.py +282 -0
- itself/_endpoints.py +255 -0
- itself/_filesystem.py +187 -0
- itself/_formats.py +104 -0
- itself/_json.py +223 -0
- itself/_version.py +8 -0
- itself/bundle.py +723 -0
- itself/cli.py +719 -0
- itself/decision_model.py +1283 -0
- itself/evidence_bundle.py +981 -0
- itself/inference.py +1571 -0
- itself/ledger.py +373 -0
- itself/py.typed +0 -0
- itself/receipts.py +621 -0
- itself/records.py +743 -0
- itself/reporting.py +125 -0
- itself/schema_export.py +178 -0
- itself/schemas/v0alpha/evidence-bundle.schema.json +144 -0
- itself/schemas/v0alpha/protocol.schema.json +466 -0
- itself/schemas/v0alpha/reasoning-receipt.schema.json +366 -0
- itself/schemas/v0alpha2/evidence-bundle.schema.json +145 -0
- itself/schemas/v0alpha2/protocol.schema.json +503 -0
- itself/schemas/v0alpha2/reasoning-receipt.schema.json +406 -0
- itself/state.py +178 -0
- itself/types.py +21 -0
- itself/validation.py +185 -0
- itself-0.2.0.dist-info/METADATA +508 -0
- itself-0.2.0.dist-info/RECORD +32 -0
- itself-0.2.0.dist-info/WHEEL +5 -0
- itself-0.2.0.dist-info/entry_points.txt +2 -0
- itself-0.2.0.dist-info/licenses/LICENSE +373 -0
- itself-0.2.0.dist-info/top_level.txt +1 -0
itself/validation.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# Copyright (C) 2026 Greater Expanse LLC
|
|
3
|
+
|
|
4
|
+
"""JSON Schema validation for protocol records."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Iterator, Mapping
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from functools import cache
|
|
11
|
+
from importlib.resources import files
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from types import MappingProxyType
|
|
14
|
+
from typing import Protocol, cast
|
|
15
|
+
|
|
16
|
+
from jsonschema import Draft202012Validator
|
|
17
|
+
from jsonschema.exceptions import ValidationError
|
|
18
|
+
|
|
19
|
+
from ._formats import schema_format_checker
|
|
20
|
+
from ._json import IJsonError, ensure_i_json, strict_json_loads
|
|
21
|
+
from ._json import format_json_path as _format_path
|
|
22
|
+
from .types import JsonObject, JsonValue, StrPath
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _SchemaValidator(Protocol):
|
|
26
|
+
"""Typed surface used from the partially typed jsonschema dependency."""
|
|
27
|
+
|
|
28
|
+
def iter_errors(self, instance: JsonValue) -> Iterator[ValidationError]: ...
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ProtocolValidationError(ValueError):
|
|
32
|
+
"""Raised when a record does not conform to the protocol schema."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _required_kind(branch: JsonValue) -> str | None:
|
|
36
|
+
"""Return the record kind a schema branch pins, following only ``allOf``."""
|
|
37
|
+
|
|
38
|
+
if not isinstance(branch, dict):
|
|
39
|
+
return None
|
|
40
|
+
properties = branch.get("properties")
|
|
41
|
+
if isinstance(properties, dict):
|
|
42
|
+
kind = properties.get("kind")
|
|
43
|
+
if isinstance(kind, dict):
|
|
44
|
+
constant = kind.get("const")
|
|
45
|
+
if isinstance(constant, str):
|
|
46
|
+
return constant
|
|
47
|
+
parts = branch.get("allOf")
|
|
48
|
+
if isinstance(parts, list):
|
|
49
|
+
for part in parts:
|
|
50
|
+
constant = _required_kind(part)
|
|
51
|
+
if constant is not None:
|
|
52
|
+
return constant
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _branches_by_kind(schema: JsonObject) -> dict[str, str]:
|
|
57
|
+
"""Map each record kind to its root ``oneOf`` branch reference.
|
|
58
|
+
|
|
59
|
+
The map is empty unless the root has no reference of its own and every
|
|
60
|
+
branch is a bare local reference that pins a distinct kind. Only then is
|
|
61
|
+
validating a record against the branch for its kind, with the root's other
|
|
62
|
+
keywords, equivalent to validating it against the whole ``oneOf``: a
|
|
63
|
+
branch's sibling keywords, or a root reference that the branch reference
|
|
64
|
+
would replace, fall back to the root validator.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
branches = schema.get("oneOf")
|
|
68
|
+
definitions = schema.get("$defs")
|
|
69
|
+
if (
|
|
70
|
+
not isinstance(branches, list)
|
|
71
|
+
or not isinstance(definitions, dict)
|
|
72
|
+
or "$ref" in schema
|
|
73
|
+
or "$dynamicRef" in schema
|
|
74
|
+
):
|
|
75
|
+
return {}
|
|
76
|
+
references: dict[str, str] = {}
|
|
77
|
+
for branch in branches:
|
|
78
|
+
if not isinstance(branch, dict) or set(branch) != {"$ref"}:
|
|
79
|
+
return {}
|
|
80
|
+
reference = branch["$ref"]
|
|
81
|
+
if not isinstance(reference, str) or not reference.startswith("#/$defs/"):
|
|
82
|
+
return {}
|
|
83
|
+
kind = _required_kind(definitions.get(reference.removeprefix("#/$defs/")))
|
|
84
|
+
if kind is None or kind in references:
|
|
85
|
+
return {}
|
|
86
|
+
references[kind] = reference
|
|
87
|
+
return references
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@dataclass(frozen=True, slots=True)
|
|
91
|
+
class _CompiledSchema:
|
|
92
|
+
root: _SchemaValidator
|
|
93
|
+
branches: Mapping[str, _SchemaValidator]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _compiled(schema_value: JsonValue) -> _CompiledSchema:
|
|
97
|
+
if not isinstance(schema_value, dict):
|
|
98
|
+
raise TypeError("protocol schema must contain one JSON object")
|
|
99
|
+
schema = schema_value
|
|
100
|
+
Draft202012Validator.check_schema(schema)
|
|
101
|
+
format_checker = schema_format_checker()
|
|
102
|
+
root_fields = {key: value for key, value in schema.items() if key != "oneOf"}
|
|
103
|
+
return _CompiledSchema(
|
|
104
|
+
root=cast(
|
|
105
|
+
_SchemaValidator,
|
|
106
|
+
Draft202012Validator(schema, format_checker=format_checker),
|
|
107
|
+
),
|
|
108
|
+
branches=MappingProxyType(
|
|
109
|
+
{
|
|
110
|
+
kind: cast(
|
|
111
|
+
_SchemaValidator,
|
|
112
|
+
Draft202012Validator(
|
|
113
|
+
{**root_fields, "$ref": reference},
|
|
114
|
+
format_checker=format_checker,
|
|
115
|
+
),
|
|
116
|
+
)
|
|
117
|
+
for kind, reference in _branches_by_kind(schema).items()
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@cache
|
|
124
|
+
def _default_schema() -> _CompiledSchema:
|
|
125
|
+
schema_resource = files("itself").joinpath(
|
|
126
|
+
"schemas", "v0alpha2", "protocol.schema.json"
|
|
127
|
+
)
|
|
128
|
+
return _compiled(strict_json_loads(schema_resource.read_text(encoding="utf-8")))
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class ProtocolValidator:
|
|
132
|
+
"""Validate provider-neutral protocol records against the canonical schema.
|
|
133
|
+
|
|
134
|
+
A record whose ``kind`` names a schema branch is validated against that
|
|
135
|
+
branch alone, which accepts exactly the records the root ``oneOf`` accepts
|
|
136
|
+
and reports the branch's own errors. A schema shaped so that this would
|
|
137
|
+
not be equivalent is applied whole. Records must also be I-JSON nested at
|
|
138
|
+
most 128 levels deep, so every accepted record can be read back. The
|
|
139
|
+
packaged schema is compiled once per process.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
def __init__(self, schema_path: StrPath | None = None) -> None:
|
|
143
|
+
self._schema = (
|
|
144
|
+
_default_schema()
|
|
145
|
+
if schema_path is None
|
|
146
|
+
else _compiled(
|
|
147
|
+
strict_json_loads(Path(schema_path).read_text(encoding="utf-8"))
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def errors(self, record: JsonValue) -> list[str]:
|
|
152
|
+
"""Return stable, human-readable validation errors."""
|
|
153
|
+
|
|
154
|
+
try:
|
|
155
|
+
ensure_i_json(record)
|
|
156
|
+
except IJsonError as error:
|
|
157
|
+
return [f"$: {error}"]
|
|
158
|
+
validator = self._schema.root
|
|
159
|
+
if isinstance(record, dict):
|
|
160
|
+
kind = record.get("kind")
|
|
161
|
+
if isinstance(kind, str):
|
|
162
|
+
validator = self._schema.branches.get(kind, validator)
|
|
163
|
+
issues = sorted(
|
|
164
|
+
validator.iter_errors(record),
|
|
165
|
+
key=lambda error: tuple(str(item) for item in error.absolute_path),
|
|
166
|
+
)
|
|
167
|
+
return [f"{_format_path(issue.path)}: {issue.message}" for issue in issues]
|
|
168
|
+
|
|
169
|
+
def validate(self, record: JsonValue) -> None:
|
|
170
|
+
"""Validate a record or raise ProtocolValidationError."""
|
|
171
|
+
|
|
172
|
+
issues = self.errors(record)
|
|
173
|
+
if issues:
|
|
174
|
+
raise ProtocolValidationError("\n".join(issues))
|
|
175
|
+
|
|
176
|
+
def is_valid(self, record: JsonValue) -> bool:
|
|
177
|
+
"""Return whether a record conforms to the canonical schema."""
|
|
178
|
+
|
|
179
|
+
return not self.errors(record)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def explain_jsonschema_error(error: ValidationError) -> str:
|
|
183
|
+
"""Format a raw jsonschema error for integrations that use the validator directly."""
|
|
184
|
+
|
|
185
|
+
return f"{_format_path(error.path)}: {error.message}"
|
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: itself
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Assurance SDK for AI agents with external checks and replayable decisions
|
|
5
|
+
Author: Greater Expanse LLC
|
|
6
|
+
License-Expression: MPL-2.0
|
|
7
|
+
Project-URL: Homepage, https://greaterexpanse.com/itself
|
|
8
|
+
Project-URL: Repository, https://github.com/Greater-Expanse/itself.git
|
|
9
|
+
Project-URL: Issues, https://github.com/Greater-Expanse/itself/issues
|
|
10
|
+
Keywords: ai,agents,assurance,ci,code-review,evidence
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: jsonschema[format-nongpl]>=4.10
|
|
24
|
+
Requires-Dist: rfc8785<0.2,>=0.1.4
|
|
25
|
+
Provides-Extra: test
|
|
26
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
27
|
+
Provides-Extra: lint
|
|
28
|
+
Requires-Dist: ruff>=0.15.22; extra == "lint"
|
|
29
|
+
Provides-Extra: typecheck
|
|
30
|
+
Requires-Dist: mypy>=1.15; extra == "typecheck"
|
|
31
|
+
Requires-Dist: pyright>=1.1.390; extra == "typecheck"
|
|
32
|
+
Requires-Dist: types-jsonschema>=4.23; extra == "typecheck"
|
|
33
|
+
Provides-Extra: release
|
|
34
|
+
Requires-Dist: check-manifest>=0.51; extra == "release"
|
|
35
|
+
Requires-Dist: twine>=6.2; extra == "release"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# Itself SDK
|
|
39
|
+
|
|
40
|
+
*Knowledge itself is the question.*
|
|
41
|
+
|
|
42
|
+
**Make model assertions testable before software acts on them.**
|
|
43
|
+
|
|
44
|
+
Itself is an open-source, provider-neutral assurance SDK for AI agents and
|
|
45
|
+
AI-driven workflows. It makes model assertions independently testable before
|
|
46
|
+
an application acts on them.
|
|
47
|
+
|
|
48
|
+
Use Itself when an agent reviews code, diagnoses a failed build, opens a pull or
|
|
49
|
+
merge request, recommends a remediation, or participates in an automated
|
|
50
|
+
release. The model's own confidence should not be enough for the system to
|
|
51
|
+
proceed.
|
|
52
|
+
|
|
53
|
+
> Itself does not make a model know when it is right. It makes model assertions
|
|
54
|
+
> testable, prevents the model from certifying its own assertions, and records
|
|
55
|
+
> how external evidence produced—or failed to produce—a decision.
|
|
56
|
+
|
|
57
|
+
AI agents can produce fluent diagnoses, recommendations, and explanations
|
|
58
|
+
without knowing whether they are correct
|
|
59
|
+
([Lee et al., 2026, Appendix A.2](https://arxiv.org/abs/2603.28052)). Most
|
|
60
|
+
application logs preserve the conversation, but not the epistemic structure
|
|
61
|
+
behind a consequential decision: what was asserted, what would falsify it,
|
|
62
|
+
which test ran, what evidence resulted, who judged that evidence, and why the
|
|
63
|
+
system acted.
|
|
64
|
+
|
|
65
|
+
Itself gives those objects an explicit, machine-readable lifecycle:
|
|
66
|
+
|
|
67
|
+
<p align="center">
|
|
68
|
+
<img
|
|
69
|
+
src="docs/assets/itself-lifecycle-dark.svg"
|
|
70
|
+
alt="A model assertion or a decision model's probability becomes a testable claim with a declared expected result. An external check produces evidence. Declared evaluation and authority control the resulting action. Every stage remains in a validated evidence ledger and reasoning receipt."
|
|
71
|
+
width="1200"
|
|
72
|
+
>
|
|
73
|
+
</p>
|
|
74
|
+
|
|
75
|
+
Every record in the ledger carries explicit scope and provenance. Evidence,
|
|
76
|
+
verdicts, and state changes also identify the actors and authority responsible
|
|
77
|
+
for them.
|
|
78
|
+
|
|
79
|
+
A model may create an assertion, state a probability, or recommend a test. It
|
|
80
|
+
cannot silently turn its own output into verified evidence. Promotion to a stronger epistemic state
|
|
81
|
+
requires declared evidence, a matching verdict, and an authorized human,
|
|
82
|
+
organization, or policy-enforcing software actor.
|
|
83
|
+
|
|
84
|
+
## What problem does Itself solve?
|
|
85
|
+
|
|
86
|
+
Without an assurance boundary, AI applications commonly collapse several
|
|
87
|
+
different things into one blob of text:
|
|
88
|
+
|
|
89
|
+
- what a model inferred;
|
|
90
|
+
- what a tool actually observed;
|
|
91
|
+
- what an evaluator concluded;
|
|
92
|
+
- what a person approved;
|
|
93
|
+
- what the application ultimately decided to do.
|
|
94
|
+
|
|
95
|
+
That ambiguity is tolerable for casual chat. It becomes dangerous when an agent
|
|
96
|
+
can change code, block a release, close an incident, recommend a consequential
|
|
97
|
+
action, or otherwise influence real work.
|
|
98
|
+
|
|
99
|
+
Itself provides a shared protocol and reference SDK for preserving those
|
|
100
|
+
distinctions. It validates record structure, references, authority, scope, and
|
|
101
|
+
state transitions; replays the resulting evidence history deterministically;
|
|
102
|
+
and produces compact reasoning receipts for inspection or downstream systems.
|
|
103
|
+
|
|
104
|
+
Itself supports automated, human-reviewed, and mixed workflows. It does not
|
|
105
|
+
replace an agent framework, CI runner, code host, incident platform, or human
|
|
106
|
+
reviewer. It gives those systems a shared boundary between an assertion and an
|
|
107
|
+
action.
|
|
108
|
+
|
|
109
|
+
## Where does Itself fit?
|
|
110
|
+
|
|
111
|
+
### Agent-generated changes and pull or merge requests
|
|
112
|
+
|
|
113
|
+
A coding agent can assert that a patch fixes an issue and open a pull or merge
|
|
114
|
+
request. CI supplies test, reproduction, static-analysis, and security results.
|
|
115
|
+
A review policy or accountable person determines whether the change may merge.
|
|
116
|
+
Itself keeps the assertion provisional until the required evidence and
|
|
117
|
+
authority exist, then preserves the basis of the decision.
|
|
118
|
+
|
|
119
|
+
### AI code review
|
|
120
|
+
|
|
121
|
+
An AI reviewer can assert that a change introduces a vulnerability, race
|
|
122
|
+
condition, or regression. A tool or engineer checks the finding. The
|
|
123
|
+
application can show the unverified assertion, block the merge only when its
|
|
124
|
+
declared policy is satisfied, or record why the finding was dismissed.
|
|
125
|
+
|
|
126
|
+
### CI diagnosis and automated repair
|
|
127
|
+
|
|
128
|
+
An agent investigating a failed pipeline can record competing causes, state
|
|
129
|
+
what each cause predicts, and select the next diagnostic check. A CI worker or
|
|
130
|
+
sandbox runs that check. Its observation—not another confident explanation—
|
|
131
|
+
controls which causes the application may treat as supported and whether an
|
|
132
|
+
automated repair may proceed.
|
|
133
|
+
|
|
134
|
+
### Root-cause analysis and incident response
|
|
135
|
+
|
|
136
|
+
An operations agent can connect a failure to a deployment, dependency, or
|
|
137
|
+
configuration change. Telemetry queries, controlled replays, rollbacks, and
|
|
138
|
+
human review can test the proposed cause. Itself records what the agent
|
|
139
|
+
asserted, what each check found, and who authorized the mitigation or continued
|
|
140
|
+
investigation.
|
|
141
|
+
|
|
142
|
+
### Research and analytical workflows
|
|
143
|
+
|
|
144
|
+
A research assistant can connect claims to source artifacts, distinguish direct
|
|
145
|
+
observations from derived judgments, invalidate downstream conclusions when a
|
|
146
|
+
source changes, and preserve the human decisions that shaped a final report.
|
|
147
|
+
|
|
148
|
+
### Knowledge-worker copilots
|
|
149
|
+
|
|
150
|
+
A copilot can separate recommendations from their supporting evidence and show
|
|
151
|
+
which conclusions remain uncertain. Reviewers can approve, reject, or qualify
|
|
152
|
+
specific claims without treating the model's entire response as one indivisible
|
|
153
|
+
answer.
|
|
154
|
+
|
|
155
|
+
### Agent evaluation and workflow regression testing
|
|
156
|
+
|
|
157
|
+
An evaluation harness can test whether an agent declares falsifiable
|
|
158
|
+
predictions, chooses discriminating tests, respects evidence boundaries, and
|
|
159
|
+
avoids unsupported status promotion. CI can reject a workflow that is
|
|
160
|
+
structurally valid but violates its declared evidence or authority policy.
|
|
161
|
+
|
|
162
|
+
## How it works
|
|
163
|
+
|
|
164
|
+
1. **Capture the assertion.** Represent a model output as a scoped `claim` or
|
|
165
|
+
`hypothesis` in an unverified state. Link it to the source artifact without
|
|
166
|
+
requiring private chain-of-thought.
|
|
167
|
+
2. **State what would distinguish competing explanations.** Record the expected
|
|
168
|
+
observations and check plan as protocol predictions and tests before
|
|
169
|
+
execution.
|
|
170
|
+
3. **Run an external check.** A CI worker, sandbox, service, deterministic tool,
|
|
171
|
+
or person performs the check. Its observed result becomes evidence.
|
|
172
|
+
4. **Evaluate under explicit authority.** A declared evaluator relates the
|
|
173
|
+
evidence to the assertion and issues a verdict. A policy actor or accountable
|
|
174
|
+
person authorizes any resulting state transition or application decision.
|
|
175
|
+
5. **Replay and inspect.** The SDK validates the complete history,
|
|
176
|
+
deterministically reconstructs current epistemic state, and can generate a
|
|
177
|
+
minimized reasoning receipt.
|
|
178
|
+
|
|
179
|
+
The protocol is independent of any model provider or agent framework. The SDK
|
|
180
|
+
includes one configurable OpenAI-compatible input adapter, but that wire format
|
|
181
|
+
is not the architecture and a model does not become a verifier merely because
|
|
182
|
+
it returns structured JSON.
|
|
183
|
+
|
|
184
|
+
## Try it locally
|
|
185
|
+
|
|
186
|
+
The repository uses Python 3.11 or later and
|
|
187
|
+
[`uv`](https://docs.astral.sh/uv/). From the repository root:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
uv sync --locked --extra test
|
|
191
|
+
|
|
192
|
+
mkdir -p .itself/quickstart
|
|
193
|
+
|
|
194
|
+
# Verify the complete reference evidence bundle.
|
|
195
|
+
uv run --frozen itself bundle validate examples/cache-key-diagnosis/bundle
|
|
196
|
+
|
|
197
|
+
# Validate one protocol record.
|
|
198
|
+
uv run --frozen itself validate conformance/valid/proposed-claim.json
|
|
199
|
+
|
|
200
|
+
# Build and inspect a local append-only evidence ledger.
|
|
201
|
+
uv run --frozen itself ledger append .itself/quickstart/ledger.jsonl \
|
|
202
|
+
conformance/valid/minimal-claim.json
|
|
203
|
+
uv run --frozen itself ledger replay .itself/quickstart/ledger.jsonl
|
|
204
|
+
uv run --frozen itself ledger summary .itself/quickstart/ledger.jsonl \
|
|
205
|
+
--format json
|
|
206
|
+
|
|
207
|
+
# Generate a deterministic public receipt and verify it against the ledger.
|
|
208
|
+
uv run --frozen itself receipt generate .itself/quickstart/ledger.jsonl \
|
|
209
|
+
--output .itself/quickstart/receipt.json
|
|
210
|
+
uv run --frozen itself receipt validate .itself/quickstart/receipt.json \
|
|
211
|
+
--ledger .itself/quickstart/ledger.jsonl
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
The repository ignores `.itself/` because local inference responses and
|
|
215
|
+
work-in-progress evidence artifacts may contain sensitive data.
|
|
216
|
+
|
|
217
|
+
The canonical JSON Schemas are packaged for offline use and published in a
|
|
218
|
+
[public schema catalog](https://greaterexpanse.com/itself/schemas/). The
|
|
219
|
+
`itself schema export DESTINATION` command materializes the same schemas,
|
|
220
|
+
catalog, and checksum inventory. Validation loads the packaged copies and never
|
|
221
|
+
requires network access. The conformance fixtures are language-neutral. Python
|
|
222
|
+
is the reference implementation, not a requirement for other implementations.
|
|
223
|
+
An [independent JavaScript conformance check](conformance/javascript/README.md)
|
|
224
|
+
compiles the same schema, exercises all 27 record and bundle fixtures, and
|
|
225
|
+
reimplements reference resolution, authorization, and deterministic replay
|
|
226
|
+
without importing or executing the Python package.
|
|
227
|
+
The [reference bundle](examples/cache-key-diagnosis/README.md) is a closed,
|
|
228
|
+
digest-inventoried example containing the original input, a model assertion
|
|
229
|
+
artifact, the complete evidence ledger, and its deterministic reasoning
|
|
230
|
+
receipt.
|
|
231
|
+
|
|
232
|
+
For a compact integration walkthrough, the
|
|
233
|
+
[inference-to-evidence example](examples/inference_to_evidence/README.md) sends
|
|
234
|
+
an incident through the public generic inference boundary, captures the model
|
|
235
|
+
assertion, runs an external deterministic test, and materializes the resulting
|
|
236
|
+
evidence, verdict, authorized transition, decision, and artifacts as a verified
|
|
237
|
+
bundle.
|
|
238
|
+
|
|
239
|
+
## Exercise the SDK
|
|
240
|
+
|
|
241
|
+
Two reproducible, provider-free evaluation suites flex the assembled SDK beyond
|
|
242
|
+
unit tests. One runs a complete lifecycle and mutation campaign; the other
|
|
243
|
+
records an observational capacity curve at increasing ledger sizes:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
mkdir -p .itself/evaluations
|
|
247
|
+
uv run --frozen python -m evaluations.sdk_exercise \
|
|
248
|
+
--output .itself/evaluations/sdk-exercise
|
|
249
|
+
uv run --frozen python -m evaluations.capacity_curve \
|
|
250
|
+
--output .itself/evaluations/capacity-curve
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Each run produces a versioned JSON report, a derived Markdown report, and
|
|
254
|
+
independently verifiable evidence bundles. See
|
|
255
|
+
[the evaluation guide](docs/EVALUATIONS.md) for the checks, result semantics,
|
|
256
|
+
limitations, and CI artifacts.
|
|
257
|
+
|
|
258
|
+
## Create a portable evidence bundle
|
|
259
|
+
|
|
260
|
+
The SDK can materialize any closed ledger as a verified directory containing
|
|
261
|
+
the canonical ledger, its reasoning receipt, declared inputs, and every
|
|
262
|
+
referenced artifact:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
mkdir -p .itself/examples
|
|
266
|
+
|
|
267
|
+
uv run --frozen itself bundle create \
|
|
268
|
+
examples/cache-key-diagnosis/bundle/ledger.jsonl \
|
|
269
|
+
.itself/examples/cache-key-bundle \
|
|
270
|
+
--title "Cache-key diagnosis" \
|
|
271
|
+
--created-at 2026-07-23T12:00:00Z \
|
|
272
|
+
--artifact artifact-diagnostician-output=examples/cache-key-diagnosis/bundle/artifacts/model-assertion.json \
|
|
273
|
+
--input examples/cache-key-diagnosis/bundle/inputs/diagnosis-request.json
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
The destination appears only after its inventory, ledger, receipt, and artifact
|
|
277
|
+
bindings pass independent validation. Verification uses explicit limits for
|
|
278
|
+
file count, byte size, directory traversal, and ledger records, and streams
|
|
279
|
+
digests without loading each artifact into memory. Final publication is an
|
|
280
|
+
atomic no-replace operation, so a destination created concurrently is
|
|
281
|
+
preserved.
|
|
282
|
+
|
|
283
|
+
See the [evidence-bundle guide](docs/EVIDENCE_BUNDLES.md) for the Python API,
|
|
284
|
+
CLI mapping rules, privacy boundary, and verification guarantees.
|
|
285
|
+
|
|
286
|
+
## Integrating Itself into an AI-driven workflow
|
|
287
|
+
|
|
288
|
+
An application places Itself between an agent assertion and a consequential
|
|
289
|
+
action:
|
|
290
|
+
|
|
291
|
+
```text
|
|
292
|
+
AI agent or human
|
|
293
|
+
↓ assertion and expected outcome
|
|
294
|
+
Itself protocol records
|
|
295
|
+
↓ declared external check
|
|
296
|
+
CI worker, sandbox, service, tool, or reviewer
|
|
297
|
+
↓ observed result (evidence)
|
|
298
|
+
evaluator, reviewer, or policy
|
|
299
|
+
↓ authorized outcome
|
|
300
|
+
merge, release, remediation, escalation, or other decision
|
|
301
|
+
↓
|
|
302
|
+
replayable ledger, application state, and reasoning receipt
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
The integration boundary can be local and lightweight: write protocol records
|
|
306
|
+
to a JSON Lines ledger, validate every append, and render the replayed state in
|
|
307
|
+
an existing application. A larger deployment can keep the same protocol while
|
|
308
|
+
replacing the local store, verifier adapters, and policy implementation.
|
|
309
|
+
|
|
310
|
+
Python applications can use typed constructors for every protocol record kind.
|
|
311
|
+
The constructors accept explicit actors, scope, authority, timestamps, and
|
|
312
|
+
protocol enums; return ordinary JSON objects; and validate each result against
|
|
313
|
+
the canonical schema before it reaches a ledger. See
|
|
314
|
+
[the protocol-record guide](docs/PROTOCOL_RECORDS.md) for the complete
|
|
315
|
+
lifecycle API and its deliberate boundaries.
|
|
316
|
+
|
|
317
|
+
## Connect a model endpoint
|
|
318
|
+
|
|
319
|
+
The installable adapter accepts any endpoint implementing the relevant
|
|
320
|
+
OpenAI-compatible Chat Completions fields. Provider choice is runtime
|
|
321
|
+
configuration—not a provider-specific class:
|
|
322
|
+
|
|
323
|
+
```python
|
|
324
|
+
from pathlib import Path
|
|
325
|
+
|
|
326
|
+
from itself import (
|
|
327
|
+
DirectoryArtifactSink,
|
|
328
|
+
EnvironmentCredential,
|
|
329
|
+
OpenAICompatibleEndpoint,
|
|
330
|
+
StructuredInferenceClient,
|
|
331
|
+
StructuredOutputProfile,
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
endpoint = OpenAICompatibleEndpoint(
|
|
335
|
+
actor_id="incident-diagnostician",
|
|
336
|
+
base_url="https://inference.example.com/v1",
|
|
337
|
+
model="organization/model",
|
|
338
|
+
credential=EnvironmentCredential("INFERENCE_API_KEY"),
|
|
339
|
+
)
|
|
340
|
+
profile = StructuredOutputProfile(
|
|
341
|
+
profile_id="diagnosis-v1",
|
|
342
|
+
schema_name="diagnosis",
|
|
343
|
+
system_prompt="Return only a structured causal assertion.",
|
|
344
|
+
user_instruction="Diagnose the supplied incident.",
|
|
345
|
+
input_label="INCIDENT",
|
|
346
|
+
schema={
|
|
347
|
+
"type": "object",
|
|
348
|
+
"additionalProperties": False,
|
|
349
|
+
"required": ["hypothesis", "next_test"],
|
|
350
|
+
"properties": {
|
|
351
|
+
"hypothesis": {"type": "string"},
|
|
352
|
+
"next_test": {"type": "string"},
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
)
|
|
356
|
+
client = StructuredInferenceClient(
|
|
357
|
+
endpoint=endpoint,
|
|
358
|
+
artifact_sink=DirectoryArtifactSink(Path(".itself/responses")),
|
|
359
|
+
)
|
|
360
|
+
result = client.invoke({"failure": "stale report output"}, profile)
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Bearer tokens, arbitrary API-key headers, and unauthenticated local endpoints
|
|
364
|
+
use the same adapter. Resource paths, query parameters, output-token field
|
|
365
|
+
names, accepted finish states, non-secret headers, and request extensions are
|
|
366
|
+
configurable. Bounded OpenAI-compatible event-stream responses are supported
|
|
367
|
+
for models that require streaming; their exact bytes are captured before local
|
|
368
|
+
assembly. Strict JSON Schema, JSON-object, and prompted-JSON capabilities are
|
|
369
|
+
explicit modes; every response is still strictly parsed and locally
|
|
370
|
+
schema-validated. Authenticated endpoints require HTTPS, and the built-in
|
|
371
|
+
transport does not follow redirects. There is no implicit retry, repair, or
|
|
372
|
+
capability fallback.
|
|
373
|
+
|
|
374
|
+
See the [inference guide](docs/INFERENCE.md) for configuration patterns,
|
|
375
|
+
guarantees, and the boundary for native provider protocols.
|
|
376
|
+
|
|
377
|
+
Decision models answer typed questions about a state with probability
|
|
378
|
+
distributions instead of text. `DecisionModelClient` sends `choice`, `noul`,
|
|
379
|
+
and `score` questions to any endpoint implementing the `/v1/systemone`
|
|
380
|
+
decision format:
|
|
381
|
+
|
|
382
|
+
```python
|
|
383
|
+
from pathlib import Path
|
|
384
|
+
|
|
385
|
+
from itself import (
|
|
386
|
+
ChoiceQuestion,
|
|
387
|
+
DecisionModelClient,
|
|
388
|
+
DecisionModelEndpoint,
|
|
389
|
+
DirectoryArtifactSink,
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
client = DecisionModelClient(
|
|
393
|
+
endpoint=DecisionModelEndpoint(
|
|
394
|
+
actor_id="spec-checker",
|
|
395
|
+
base_url="http://127.0.0.1:8000/v1",
|
|
396
|
+
model="local-decider",
|
|
397
|
+
allow_insecure_http=True,
|
|
398
|
+
),
|
|
399
|
+
artifact_sink=DirectoryArtifactSink(Path(".itself/decisions")),
|
|
400
|
+
)
|
|
401
|
+
result = client.decide(
|
|
402
|
+
"Specification: R1. Reject empty input.\n\nCode: return text.split()[0]",
|
|
403
|
+
{
|
|
404
|
+
"r1": ChoiceQuestion(
|
|
405
|
+
"Does the code satisfy rule R1?",
|
|
406
|
+
{"true": "Yes, it satisfies R1.", "false": "No, it violates R1."},
|
|
407
|
+
),
|
|
408
|
+
},
|
|
409
|
+
)
|
|
410
|
+
estimate = result.estimates["r1"]
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
By default each choice and score question is asked twice, with its options as
|
|
414
|
+
declared and reversed, and `estimate.order_gap` and `estimate.order_flip`
|
|
415
|
+
report how far option position moved the answer; a yes-or-no `NoulQuestion`
|
|
416
|
+
is asked once. Every request and response is captured
|
|
417
|
+
before interpretation, and every distribution is validated locally. The
|
|
418
|
+
probability is a prediction to test, never a verdict. See the
|
|
419
|
+
[decision-model guide](docs/DECISION_MODELS.md).
|
|
420
|
+
|
|
421
|
+
The repository also contains a transparent controlled incident investigation.
|
|
422
|
+
A report-generation system advances from source revision `A` to `B`, but keeps
|
|
423
|
+
returning stale revision `A`. An AI assistant sees the repeated failures, three
|
|
424
|
+
plausible root causes, and several checks it could recommend. The experiment
|
|
425
|
+
compares an ordinary answer to “What is causing this?” with a testable
|
|
426
|
+
investigation plan that states what each cause predicts and which check should
|
|
427
|
+
run next.
|
|
428
|
+
|
|
429
|
+
The application then runs the chosen check outside the model. Itself keeps the
|
|
430
|
+
answer provisional, records the resulting evidence, prevents unsupported
|
|
431
|
+
answers from being treated as confirmed, and leaves enough history for another
|
|
432
|
+
developer to reconstruct the decision.
|
|
433
|
+
|
|
434
|
+
The current live-model report shows that completed workflows crossed that
|
|
435
|
+
evidence boundary and that invalid model outputs stopped at an explicit
|
|
436
|
+
contract boundary instead of being silently repaired. It does not show that
|
|
437
|
+
Itself improved diagnosis accuracy: every completed attempt in this first
|
|
438
|
+
transparent case already named the known cause. See the
|
|
439
|
+
[current comparison report](experiments/results/current/2026-07-24-case-001-comparison-v5.md)
|
|
440
|
+
for the observations and their limits.
|
|
441
|
+
|
|
442
|
+
## Documentation
|
|
443
|
+
|
|
444
|
+
The [documentation index](docs/README.md) is the entry point for integration
|
|
445
|
+
guides, protocol and schema references, evidence formats, evaluations, and
|
|
446
|
+
controlled research. It groups the material by what a reader is trying to
|
|
447
|
+
accomplish rather than presenting every document as an equal starting point.
|
|
448
|
+
The [CI integration cookbook](cookbook/README.md) provides executable GitHub
|
|
449
|
+
Actions and GitLab CI recipes for gating an agent change, verifying its
|
|
450
|
+
evidence bundle, and publishing its reasoning receipt.
|
|
451
|
+
|
|
452
|
+
Project changes are recorded in the [changelog](CHANGELOG.md). See
|
|
453
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) to participate and
|
|
454
|
+
[SECURITY.md](SECURITY.md) to report a vulnerability privately.
|
|
455
|
+
|
|
456
|
+
## Research context
|
|
457
|
+
|
|
458
|
+
Itself was inspired in part by
|
|
459
|
+
[*Meta-Harness: End-to-End Optimization of Model Harnesses*](https://arxiv.org/abs/2603.28052),
|
|
460
|
+
especially Appendix A.2. An agentic proposer repeatedly produced plausible
|
|
461
|
+
causal explanations for prior failures, yet its first six resulting
|
|
462
|
+
interventions regressed; an external evaluation loop determined what actually
|
|
463
|
+
worked. We saw an opportunity to generalize that boundary by making model
|
|
464
|
+
assertions, tests, evidence, verdicts, and decisions explicit, interoperable
|
|
465
|
+
records.
|
|
466
|
+
|
|
467
|
+
## What Itself does not claim
|
|
468
|
+
|
|
469
|
+
Itself can establish that records conform to a protocol, references resolve,
|
|
470
|
+
declared authority rules were followed, state replay is deterministic, and a
|
|
471
|
+
reasoning receipt matches a supplied ledger. Those are useful assurance
|
|
472
|
+
properties, but they do not establish that:
|
|
473
|
+
|
|
474
|
+
- a model assertion is factually correct;
|
|
475
|
+
- an evidence source or causal oracle is trustworthy;
|
|
476
|
+
- a selected test is sufficient for every real-world context;
|
|
477
|
+
- a human judgment is unbiased;
|
|
478
|
+
- private reasoning was faithful;
|
|
479
|
+
- one numerical score can summarize truth or trust.
|
|
480
|
+
|
|
481
|
+
Itself is a pre-1.0 SDK. Public formats carry their own versions; Python APIs may
|
|
482
|
+
change before `1.0.0`, with migrations documented when an earlier release is
|
|
483
|
+
affected.
|
|
484
|
+
|
|
485
|
+
## Development
|
|
486
|
+
|
|
487
|
+
Run the complete local quality gates with:
|
|
488
|
+
|
|
489
|
+
```bash
|
|
490
|
+
uv sync --locked --extra test --extra lint --extra typecheck --extra release
|
|
491
|
+
uv run --frozen --extra test pytest
|
|
492
|
+
uv run --frozen --extra lint ruff check .
|
|
493
|
+
uv run --frozen --extra lint ruff format --check .
|
|
494
|
+
uv run --frozen --extra typecheck mypy
|
|
495
|
+
uv run --frozen --extra typecheck pyright
|
|
496
|
+
uv run --frozen --extra typecheck pyright --verifytypes itself --ignoreexternal
|
|
497
|
+
uv run --frozen --extra release check-manifest
|
|
498
|
+
uv build
|
|
499
|
+
uv run --frozen --extra release twine check --strict dist/*
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
The distribution includes a PEP 561 `py.typed` marker. Its public annotations
|
|
503
|
+
are checked in strict mode by both Mypy and Pyright.
|
|
504
|
+
|
|
505
|
+
## License
|
|
506
|
+
|
|
507
|
+
Itself SDK is released under the [Mozilla Public License 2.0](LICENSE).
|
|
508
|
+
Copyright © Greater Expanse LLC.
|