schema_reference
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| Conformance aclientp.schema_reference ``conformance.toml``: renames and known differences of a pinned reference. |
||
| EnumDef aclientp.schema_reference A string enum of the upstream schema. |
||
| FieldInfo aclientp.schema_reference How a model field behaves on the wire. |
||
| Finding aclientp.schema_reference One difference between the models and the reference. |
||
| OurSchema aclientp.schema_reference Models and module-level aliases (unions, ``Literal`` enums) of a model package. |
||
| Reference aclientp.schema_reference A pinned upstream schema release. |
||
| ReferenceChanges aclientp.schema_reference What changed in a reference implementation since its pinned commit. |
||
| ReferenceImplementation aclientp.schema_reference An upstream implementation pinned by commit (``schema/references.toml``). |
||
| Report aclientp.schema_reference Findings of a check, split against the known differences. |
||
| Shape aclientp.schema_reference An object shape of the upstream schema: a named definition or a union variant. |
||
| UpstreamCommit aclientp.schema_reference A commit of a reference implementation. |
||
| UpstreamSchema aclientp.schema_reference The parts of an upstream schema the checks compare. |
🛈 DocStrings¶
Pinned upstream ACP schema references: syncing and conformance checks.
The hand-written models in :mod:aclientp.schema follow the upstream ACP JSON schema
(agentclientprotocol/agent-client-protocol). Instead of generating code, the
repository pins one upstream schema release per protocol version and checks the
models against it:
schema/v{N}/VERSION: upstream git tag, e.g.schema-v1.33.0schema/v{N}/schema.unstable.jsonandmeta.unstable.json: the vendored upstream files of that tag (the unstable schema is a superset of the stable one)schema/v{N}/conformance.toml: renames and known, documented differences
Commands (uv run python -m aclientp.schema_reference <command>):
latest: show the pinned and the newest upstream tagsync [--tag TAG] [--dry-run]: download a tag (default: newest), print the schema changelog against the pinned one, and update the pincheck: compare the models with the pinned schemarefs [--update NAME [--commit SHA]]: show what changed in the pinned reference implementations (schema/references.toml) since their pinned commit, or move a pin
CONSTRAINT_KEYS
module-attribute
¶
CONSTRAINT_KEYS = {
"minimum": "ge",
"maximum": "le",
"exclusiveMinimum": "gt",
"exclusiveMaximum": "lt",
"minLength": "min_length",
"maxLength": "max_length",
"minItems": "min_length",
"maxItems": "max_length",
}
JSON schema keywords and the pydantic constraints they correspond to.
METHOD_GROUPS
module-attribute
¶
METHOD_GROUPS = {
"agentMethods": "AgentMethod",
"clientMethods": "ClientMethod",
"protocolMethods": "ProtocolMethod",
"proxyMethods": "ProxyMethod",
}
meta.unstable.json method groups and the Literal aliases mirroring them.
MISSING_KINDS
module-attribute
¶
Finding kinds that allow_missing accepts.
MODEL_PACKAGES
module-attribute
¶
Package holding the hand-written models of each protocol version.
Conformance
dataclass
¶
conformance.toml: renames and known differences of a pinned reference.
Source code in src/aclientp/schema_reference.py
allow_missing
class-attribute
instance-attribute
¶
Accept upstream shapes, enums and methods without a counterpart yet, while a model package is being written. Fields of the shapes that exist are still checked.
check_constraints
class-attribute
instance-attribute
¶
Compare numeric and length constraints (minimum, minItems, ...).
check_nullability
class-attribute
instance-attribute
¶
Compare which fields accept null. For model packages that send None as
null and leave out MISSING fields (v2), not for exclude_none ones (v1).
check_parse_nullability
class-attribute
instance-attribute
¶
Report fields where upstream allows null but the model rejects None
(valid messages fail to parse). Implied by check_nullability; for packages
that never send null (v1).
known
class-attribute
instance-attribute
¶
Finding id to the reason the difference is accepted.
renames
class-attribute
instance-attribute
¶
Upstream definition name to our model name.
load
classmethod
¶
load(path: UPath) -> Conformance
Read conformance.toml; a missing file means no renames or differences.
Source code in src/aclientp/schema_reference.py
EnumDef
dataclass
¶
A string enum of the upstream schema.
Source code in src/aclientp/schema_reference.py
FieldInfo
dataclass
¶
How a model field behaves on the wire.
Source code in src/aclientp/schema_reference.py
Finding
dataclass
¶
One difference between the models and the reference.
Source code in src/aclientp/schema_reference.py
id
instance-attribute
¶
Stable id, e.g. missing-field:ToolCallUpdate.name; key in conformance.toml.
OurSchema
dataclass
¶
Models and module-level aliases (unions, Literal enums) of a model package.
Source code in src/aclientp/schema_reference.py
literal_values
¶
Values of the Literal alias name, and whether it also allows str.
Source code in src/aclientp/schema_reference.py
load
classmethod
¶
load(package_name: str) -> OurSchema
Collect models and aliases from the direct modules of package_name.
Source code in src/aclientp/schema_reference.py
union_members
¶
Models of the union alias name (empty if there is none).
Reference
dataclass
¶
A pinned upstream schema release.
Source code in src/aclientp/schema_reference.py
load
classmethod
¶
load(protocol_version: int, root: UPath = REFERENCE_ROOT) -> Reference
Load the pinned reference of protocol_version.
Source code in src/aclientp/schema_reference.py
ReferenceChanges
dataclass
¶
What changed in a reference implementation since its pinned commit.
Source code in src/aclientp/schema_reference.py
commits
instance-attribute
¶
commits: list[UpstreamCommit]
Commits since the pin that touched the reference's paths, newest first.
files
instance-attribute
¶
Files under the reference's paths that differ between the pin and the head.
ReferenceImplementation
dataclass
¶
An upstream implementation pinned by commit (schema/references.toml).
Source code in src/aclientp/schema_reference.py
paths
instance-attribute
¶
Paths in the repository whose changes are of interest.
Report
dataclass
¶
Findings of a check, split against the known differences.
Source code in src/aclientp/schema_reference.py
Shape
dataclass
¶
An object shape of the upstream schema: a named definition or a union variant.
Source code in src/aclientp/schema_reference.py
bases
class-attribute
instance-attribute
¶
Definitions this shape inherits via allOf.
branch_of
class-attribute
instance-attribute
¶
For a variant made from a tagged branch inside an object definition: that definition. Our side models such an object either as one model of the same name, or as a union of the same name whose members are the branches.
constraints
class-attribute
instance-attribute
¶
Numeric and length constraints per property, as pydantic names (ge, ...).
discriminator
class-attribute
instance-attribute
¶
(property, value) that selects a variant.
key
instance-attribute
¶
Name for a definition, Union[prop=value] for a tagged union variant.
nullable
class-attribute
instance-attribute
¶
Wire names of properties that accept null.
properties
instance-attribute
¶
Wire names of all properties, including inherited (allOf) ones.
union
class-attribute
instance-attribute
¶
Name of the union a variant belongs to.
UpstreamCommit
dataclass
¶
UpstreamSchema
dataclass
¶
The parts of an upstream schema the checks compare.
Source code in src/aclientp/schema_reference.py
inlined_bases
property
¶
Definitions that only serve as allOf bases of union variants.
methods
instance-attribute
¶
meta.unstable.json method group to method names.
union_members
instance-attribute
¶
Union name to the keys of its members (variants and referenced definitions).
parse
classmethod
¶
parse(schema: JSON, meta: JSON) -> UpstreamSchema
Extract shapes, enums, unions and methods from the upstream files.
Source code in src/aclientp/schema_reference.py
changelog
¶
changelog(old: UpstreamSchema, new: UpstreamSchema) -> list[str]
Human-readable changes between two upstream schemas.
Source code in src/aclientp/schema_reference.py
check
¶
check(
upstream: UpstreamSchema,
ours: OurSchema,
renames: Mapping[str, str],
*,
check_nullability: bool = False,
check_parse_nullability: bool = False,
check_constraints: bool = False,
) -> list[Finding]
Compare the models with the upstream schema.
renames maps upstream definition names (shapes, unions, enums) to ours.
Source code in src/aclientp/schema_reference.py
download
¶
Download the reference files of tag, verbatim.
Source code in src/aclientp/schema_reference.py
load_references
¶
load_references(path: UPath = REFERENCES_FILE) -> list[ReferenceImplementation]
Read the pinned reference implementations.
Source code in src/aclientp/schema_reference.py
main
¶
Entry point of python -m aclientp.schema_reference.
Source code in src/aclientp/schema_reference.py
parse_files
¶
parse_files(files: Mapping[str, str]) -> UpstreamSchema
Parse downloaded reference files.
reference_changes
¶
reference_changes(reference: ReferenceImplementation) -> ReferenceChanges
Fetch the changes of reference since its pinned commit.
Source code in src/aclientp/schema_reference.py
run_check
¶
run_check(protocol_version: int, root: UPath = REFERENCE_ROOT) -> Report
Check the models of protocol_version against its pinned reference.
Source code in src/aclientp/schema_reference.py
split_known
¶
Split findings into undocumented ones, and find stale known differences.
Source code in src/aclientp/schema_reference.py
tag_sort_key
¶
Sort key of an upstream schema tag such as schema-v2.0.0-alpha.17.
A release sorts after its pre-releases (2.0.0-alpha.17 < 2.0.0).
Source code in src/aclientp/schema_reference.py
update_reference
¶
Move the pin of reference name to commit, keeping the file's layout.
Source code in src/aclientp/schema_reference.py
upstream_tags
¶
wire_fields
¶
wire_fields(model: type[BaseModel]) -> dict[str, FieldInfo]
Wire name and behaviour of each serialized field of model.
Source code in src/aclientp/schema_reference.py
write_reference
¶
Store downloaded reference files, unchanged, as the pin of protocol_version.
Keeping upstream's bytes means a git diff between pins is upstream's diff.