Skip to content
Konstera
Docs · Context Service
Konstera documentation.

Getting started, SDK quickstart, manifest reference, kernel MCP services, deploy guide and FAQ — everything you need to build and run agents on Konstera.

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:

1. Identity strategies

How to look it up — primary + fallbacks.

2. Key attributes

Enum values, numeric ranges, datetime windows.

3. Relationships

Foreign-key-like edges to other entities.

That's it. No class hierarchy, no inference rules.

Entity shape#

Returned from ctx.semantic.ontology_lookup():

Python
@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:

JSON
{
  "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.

ArchitectureOne capability name in your code, a different vendor behind it per region Interactive — click a block
Your agentcalls the canonical capabilitycustomers.lookup_by_emailOpen page
EU bindingShopify
UK bindingZendesk
US bindingcustom Postgres connection

Pattern: read the identity strategy, try the primary identifier, then each fallback in order.

FlowWhat resolve_customer does Interactive — click a block
  1. Look up the entity
    Python
    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"]
    
  2. Try the primary identifier
    Python
        # 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
    
  3. Try the fallbacks in order
    Python
        # 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:

KindShapeUse 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:

Validate attribute values

Does the vendor's response's tier field match the ontology's vip_tier enum?

Ground LLM prompts

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:

JSON
"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:

FromVerbToCardinality
customerplacedorder1:n
customeropenedticket1:n
customermember_ofhouseholdn: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):

Flow Interactive — click a block
1Readontology_lookup() — current active versionOpen page
2Record the idversion-pinned UUID, at output time
3Replayontology_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.

Flow Interactive — click a block

Proposal types:

TypeSourceRule
Entity proposals (ADR-048 piece 7a)One per candidate table from the SQL Assistant scanDeduped against existing + pending
Relationship proposals (ADR-048 piece 7b)One per FK walkEdges 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#

Do
  • Use ContextEntities.CUSTOMER when customer is in the Standard Context Pack — build-time typo detection.
  • Use the .get(key, default) pattern everywhere on properties. Tenant-authored or pack entities may omit relationships or have an empty key_attributes dict.
Avoid
  • Hardcode entity names when the pack exists — don't use the string literal.
  • Assume properties keys exist.
  • Rely on source: "starter_template" for pack entities. The pack ships entities with source: "starter_template", but a tenant may override by re-authoring; the override keeps the same canonical_name but changes source: "authored". Don't branch on source for behaviour.

See also#