Ontology deep-dive
Konstera's ontology is a tenant-authored (or catalog-ingested) model of the business entities an agent reasons about. This page covers the shape of ontology entities in depth — the thin-semantic model (migration 115) that landed with ADR-037 Step 3.5 B.3.
For the agent-side read API, see Context Service for agent authors. For how ontology data is populated, see Data catalogs.
Why thin-semantic#
Traditional ontologies (RDF, OWL) go deep on taxonomy, inheritance, and inference. Konstera's ontology deliberately stays thin — enough to let an agent resolve a customer across vendor bindings, but not so much that authoring an entity requires a philosopher.
An entity carries:
How to look it up — primary + fallbacks.
Enum values, numeric ranges, datetime windows.
Foreign-key-like edges to other entities.
That's it. No class hierarchy, no inference rules.
Entity shape#
Returned from ctx.semantic.ontology_lookup():
@dataclass
class OntologyEntity:
id: str # UUID
canonical_name: str # 'customer', 'order', 'sku'
entity_type: str # 'person', 'object', 'event'
synonyms: list[str] # ['account', 'buyer']
description: str | None
repository_id: str
repository_name: str
properties: dict # The semantically-interesting part — see below
source: str # 'starter_template' | 'authored' | 'external_catalog'
status: str # 'active' | 'archived'
updated_at: str
The properties dict is the semantically-interesting part. Shape for a
customer under the thin-semantic model:
{
"identity": {
"primary": {
"field": "email",
"capability": "customers.lookup_by_email"
},
"fallbacks": [
{
"field": "loyalty_id",
"capability": "customers.lookup_by_loyalty_id"
},
{
"field": "phone",
"capability": "customers.lookup_by_phone"
}
]
},
"key_attributes": {
"vip_tier": {
"type": "enum",
"values": ["bronze", "silver", "gold"]
},
"lifetime_value_usd": {
"type": "number",
"min": 0
},
"signup_date": {
"type": "datetime",
"window": "lifetime"
}
},
"relationships": [
{ "to": "order", "verb": "placed", "cardinality": "1:n" },
{ "to": "household", "verb": "member_of", "cardinality": "n:1" }
]
}
Identity strategy — the agent's main lever#
The reason an ontology exists for agents at all: resolve the same business entity across heterogeneous vendor bindings.
Problem: a tenant may bind customers.lookup_by_email to Shopify in
EU, Zendesk in UK, and a custom Postgres connection in US. The agent code
should work on any of them without conditional branches per tenant.
customers.lookup_by_emailOpen page Pattern: read the identity strategy, try the primary identifier, then each fallback in order.
- Look up the entityPython
async def resolve_customer(inbound_ticket, ctx: AgentContext): entity = await ctx.semantic.ontology_lookup("customer") if not entity: # No ontology (tenant hasn't authored it or Context Service disabled) # — fall back to a hardcoded assumption return await ctx.capability.call( "customers.lookup_by_email", email=inbound_ticket.email ) identity = entity.properties["identity"] - Try the primary identifierPython
# Try primary first primary = identity["primary"] value = getattr(inbound_ticket, primary["field"], None) if value and await ctx.capability.available(primary["capability"]): customer = await ctx.capability.call( primary["capability"], **{primary["field"]: value} ) if customer: return customer - Try the fallbacks in orderPython
# Primary didn't resolve — try fallbacks in order for fallback in identity["fallbacks"]: value = getattr(inbound_ticket, fallback["field"], None) if value and await ctx.capability.available(fallback["capability"]): customer = await ctx.capability.call( fallback["capability"], **{fallback["field"]: value} ) if customer: return customer return None
Key attributes#
The key_attributes dict tells the agent what fields matter + their shape.
Three kinds:
| Kind | Shape | Use for |
|---|---|---|
| enum | {type: "enum", values: [...]} | Constrained categorical fields (tier, status, category) |
| number | {type: "number", min?, max?} | Amounts, counts, thresholds |
| datetime | {type: "datetime", window?: "lifetime" | "30d" | "90d" | ...} | Time-bounded fields |
Agents use these two ways:
Does the vendor's response's tier field match the ontology's vip_tier enum?
Telling the model vip_tier is one of bronze / silver / gold prevents hallucinated values.
Relationships#
relationships[] holds edges to other entities with a verb and cardinality:
"relationships": [
{ "to": "order", "verb": "placed", "cardinality": "1:n" },
{ "to": "ticket", "verb": "opened", "cardinality": "1:n" }
]
Read together with the customer example above, the edges look like this:
| From | Verb | To | Cardinality |
|---|---|---|---|
customer | placed | order | 1:n |
customer | opened | ticket | 1:n |
customer | member_of | household | n:1 |
Supported cardinalities: 1:1, 1:n, n:1, n:n.
Verbs come from an enum (has, has_many, placed, member_of,
booked_with, assigned_to, completed_at, canonical_for, …) with the
LLM-inferred verb from SQL Assistant scans falling back to a deterministic
has_<entity> for _id-suffixed FKs.
Versioning + reproducibility#
Each entity write produces a new version. Agents reading
ontology_lookup() get the current active version. For
reproducibility (replaying an invocation months later):
ontology_lookup() — current active versionOpen page ontology_lookup_by_id(id)- Record the entity's
id(version-pinned UUID) at output time - On replay, call
ontology_lookup_by_id(id)— same shape regardless of whether a newer active version now exists
Mirrors the pattern for ctx.rule.get() /ctx.rule.get_by_id() — see
Semver + breaking-change policy.
Ontology proposals queue#
When a catalog ingestion (SQL Assistant, dbt) produces entity + relationship candidates, they land in the ontology proposals queue. The admin reviews + accepts in the portal. Agents only see accepted entities and edges.
Proposal types:
| Type | Source | Rule |
|---|---|---|
| Entity proposals (ADR-048 piece 7a) | One per candidate table from the SQL Assistant scan | Deduped against existing + pending |
| Relationship proposals (ADR-048 piece 7b) | One per FK walk | Edges only emitted where both endpoints are proposed entities |
Portal workflow: scan completes → proposals land → admin bulk-accepts (piece 7c lets them accept "everything from this scan" in one click, with entity-before-edge sorting so FKs resolve).
Pitfalls#
- Use
ContextEntities.CUSTOMERwhencustomeris in the Standard Context Pack — build-time typo detection. - Use the
.get(key, default)pattern everywhere onproperties. Tenant-authored or pack entities may omitrelationshipsor have an emptykey_attributesdict.
- Hardcode entity names when the pack exists — don't use the string literal.
- Assume
propertieskeys exist. - Rely on
source: "starter_template"for pack entities. The pack ships entities withsource: "starter_template", but a tenant may override by re-authoring; the override keeps the samecanonical_namebut changessource: "authored". Don't branch onsourcefor behaviour.