Skip to content

API Reference parrot.knowledge.contracts.graph_loader

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.knowledge.contracts.graph_loader

View source

Full-catalog contracts graph publication (FEAT-539 M5).

:class:ContractGraphLoader projects the authoritative catalog into the ArangoDB contracts ontology. Three rules drive its design, all of them corrections the spec makes to the naive "publish one card" idea:

  1. Publication is always a complete, prevalidated snapshot. The generic refresh diff soft-deletes anything absent from an extraction, so a partial snapshot would retract the rest of the catalog. :meth:ContractGraphLoader.publish therefore delegates to :meth:ContractGraphLoader.publish_all under the tenant lock.
  2. Edges are reconciled, not just created. create_edges inserts or skips by endpoints and never updates properties or removes obsolete edges, so an owner/parent/party/standard/signatory change must remove the old edge before writing the new one. Every written edge carries _from/_to plus source_id/target_id/kind so the generic removal helpers can address it.
  3. Success is verified, never assumed. An empty errors list is not evidence: the loader reads back the intended node and edge sets before it reports a revision as published, and any shortfall keeps the work retryable.

Attribute CONTRACTS_DOMAIN

Class ContractGraphLoader

Publish the contracts catalog into the tenant's ontology graph.

Parameter Type Default Description
catalog ContractCatalogStore The tenant-bound authoritative catalog.
graph_store Any An ArangoOntologyGraphStore-shaped object.
tenant_manager Any None A dedicated TenantOntologyManager configured with the contracts ontology directory. The generic manager caches by tenant only (not by tenant+domain), so sharing one across domains would hand back another domain's ontology.
datasource Optional[ContractCardDataSource] None Optional pre-built :class:ContractCardDataSource.
ontology_dir Optional[str | Path] None Overrides the manager's ontology directory.
domain str CONTRACTS_DOMAIN Ontology domain name (contracts).

Method ContractGraphLoader.context

Resolve (and cache) the tenant context for the contracts domain.

context() -> Any

Returns: Any

Raises:

  • ContractsDomainNotLoaded — When the resolved ontology does not carry the contracts vocabulary — a misconfigured ontology_dir or a manager shared with another domain.

Method ContractGraphLoader.startup_check

Fail fast at startup when the contracts domain is not loaded.

startup_check() -> None

Method ContractGraphLoader.desired_edges

Derive every deterministic edge from a complete snapshot.

Runs in Python over the prevalidated snapshot so relations to later-loaded targets exist on the first publish — the generic discovery pass would otherwise miss a target that had not been synchronised yet.

desired_edges(snapshot: dict[str, list[dict[str, Any]]]) -> list[EdgeSpec]

Parameter Type Default Description
snapshot dict[str, list[dict[str, Any]]] The datasource snapshot (all five entities).

Returns: list[EdgeSpec] — Deterministically ordered edge specifications.

Method ContractGraphLoader.publish_all

Reconcile the whole catalog into the graph, then verify it.

publish_all() -> GraphPublicationReport

Returns: GraphPublicationReport — class:GraphPublicationReport; published is True only after the intended nodes and edges were read back.

Method ContractGraphLoader.publish

Publish one card.

v1 delegates to :meth:publish_all: the generic diff has no per-card filter and soft-deletes everything absent from the extraction it is given, so feeding it a single-card snapshot would retract the rest of the catalog.

publish(card: ContractCard) -> GraphPublicationReport

Parameter Type Default Description
card ContractCard The card that triggered publication (used for logging).

Returns: GraphPublicationReport — The full-catalog publication report.

Method ContractGraphLoader.retract

Retract one contract from the graph.

Marks the contract and its obligations inactive, removes the edges incident to them inside feature-owned collections only, and queues temporal tombstones. Shared parties and people that other contracts still reference are left untouched, as is catalog history, evidence and the answer audit.

retract(contract_id: str) -> GraphPublicationReport

Parameter Type Default Description
contract_id str The contract to retract.

Returns: GraphPublicationReport — A report listing what was deactivated and removed.

Class ContractsDomainNotLoaded

The resolved tenant ontology does not contain the contracts domain.

Class EdgeSpec

One deterministic edge the projection intends to exist.

Fields:

Field Type Default Description
collection str
source_collection str
source_key str
target_collection str
target_key str
properties dict[str, Any]

Attributes:

Attribute Type Description
source_id str Full collection/key id of the tail.
target_id str Full collection/key id of the head.
triple tuple[str, str, str, str] The (collection, source, target, kind) identity of this edge.

Method EdgeSpec.document

Render the edge document written to ArangoDB.

Carries the generic source_id/target_id/kind triple in addition to _from/_to so edges_incident and remove_edge_by_triple can address it later.

document() -> dict[str, Any]

Returns: dict[str, Any]

Attribute FEATURE_EDGE_COLLECTIONS

Type: tuple[str, ...]

Attribute FEATURE_VERTEX_COLLECTIONS

Type: tuple[str, ...]

Class GraphPublicationReport

What one publication attempt actually achieved.

published is only ever True after a successful read-back of the intended node and edge sets.

Fields:

Field Type Default Description
published bool False
contracts int 0
nodes_upserted dict[str, int]
edges_created dict[str, int]
edges_removed dict[str, int]
deactivated dict[str, list[str]]
retracted list[str]
errors list[str]
missing_nodes list[str]
missing_edges list[str]
unavailable_targets list[str]

Attributes:

Attribute Type Description
complete bool True when nothing was missing and no error was recorded.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally