Facet
All docs

Ontology Mapping Decision Guide

How to map your own objects/calls to Trace, Activity, Artifact, Resource and Lineage — read this first if your framework doesn't already structure that for you.

Ontology Mapping Decision Guide

Why this exists

Every adapter this platform ships (LangGraph, LangChain, Semantic Kernel) already decides, once, how one framework's runtime concepts map onto the five-entity ontology (Trace, Activity, Artifact, Resource, Lineage). A customer using one of those adapters never has to make that decision themselves; it has already been made for them.

But not every customer has a framework we have an adapter for. Some have no framework at all — raw calls to an LLM API, a hand-rolled retrieval step, a bespoke business-rule check, a call to an internal service. For those customers, the generic manual-instrumentation primitives already exist and are already documented mechanically:

  • adg.adapters.direct_llm.instrument_client(...) — wraps an OpenAI-shaped client, auto-instruments every chat.completions.create/ embeddings.create call.
  • .observe(run) — groups several calls into one Trace.
  • .record_step(name, artifact_name=, payload=, artifact_type=, resource_name=, ...) — the fully generic primitive: records one Activity (and, optionally, one Artifact and/or one Resource) for any piece of customer-owned work that isn't itself an LLM call.

What is not documented anywhere else is how a customer's dev team should decide, for their own arbitrary code, which of their own function calls, steps, or objects become a Trace, an Activity, an Artifact, or a Resource in the first place. That decision is semantic, not mechanical — the SDK cannot make it for you, because it would require assuming something about your code's meaning (exactly what architecture Part 1 forbids). This guide is that missing decision aid.

It is written for a customer's developer doing first-time manual instrumentation of their own code — not for someone building a new framework adapter (that is a separate, lower-level exercise, not covered here).


The five entities, restated as questions

Instead of memorizing the abstract definitions, ask these concrete questions about the piece of code in front of you:

Entity Ask yourself...
Trace "Where does one complete, independently-meaningful execution start and end?"
Activity "What is one discrete unit of work inside that execution, worth seeing on its own on a timeline?"
Artifact "Did this unit of work produce some piece of information someone downstream might read, evaluate, or govern?"
Resource "Did this unit of work consume something external — a model, a tool, an API, a database, a vector store?"
Lineage "Does anything here depend on, derive from, or need to be traced back to something else already observed?"

If you can answer all five for a piece of code, you already know how to instrument it. The rest of this guide is about answering them reliably and consistently, without guessing.


Decision tree

START: I have a piece of my own code I want ADG to observe.
│
├─ Q1. Is this the outermost boundary of one complete, independently
│      meaningful execution (a request, a conversation turn, a batch
│      job run, a scheduled job invocation)?
│      │
│      ├─ YES ─> This is a TRACE boundary.
│      │         Open it with instrument_client(...).observe(run) (or
│      │         let a per-call auto-Trace open implicitly — see
│      │         "Direct LLM API's Trace-boundary default" below).
│      │         Everything inside `run(...)` is now "inside this Trace".
│      │
│      └─ NO ──> Do not open a new Trace here. Either:
│                (a) it belongs inside a Trace someone above you already
│                    opened (the common case — keep reading), or
│                (b) it is genuinely unrelated background work with no
│                    execution of interest to attach to (e.g. a health
│                    check, a cron no-op) — do not instrument it at all.
│
├─ Q2. Inside an open Trace, is this one discrete step worth seeing on
│      its own on a timeline (an LLM call, a retrieval call, a guardrail
│      check, a tool/MCP call, a business-rule evaluation)?
│      │
│      ├─ YES ─> This is an ACTIVITY.
│      │         An LLM/embeddings call through instrument_client() gets
│      │         one automatically. Anything else: one record_step(name,
│      │         ...) call per step.
│      │
│      └─ NO ──> Too fine-grained to be its own Activity (e.g. a single
│                string-formatting line, a logging statement, an internal
│                helper function with no independent meaning to anyone
│                reviewing this Trace later). Do not instrument it. See
│                "Common pitfall: over-granularity" below.
│
├─ Q3. Did that Activity produce a piece of information someone
│      downstream (Governance, Analytics, Quality, a human reviewer)
│      might need to read, evaluate, or govern?
│      │
│      ├─ YES ─> Attach an ARTIFACT: record_step(..., artifact_name=,
│      │         payload=, artifact_type=). `payload` is whatever shape
│      │         your own code already produced — never reshape or
│      │         rename it to fit an assumed vocabulary (see the Field
│      │         Mapping guide for how that gap is bridged later,
│      │         separately, without you fabricating fields now).
│      │
│      └─ NO ──> No Artifact for this step. Not every Activity produces
│                one (a tool call that only has a side effect and
│                returns nothing meaningful is a valid Activity with no
│                Artifact).
│
├─ Q4. Did that Activity consume something external to your own business
│      logic — an LLM, a vector store, a database, a third-party API, an
│      MCP tool?
│      │
│      ├─ YES ─> Attach a RESOURCE: record_step(..., resource_name=,
│      │         resource_type=, resource_metadata=). This is what makes
│      │         the Activity visible to FinOps/cost-allocation and to
│      │         Agent Intelligence's resource-usage views.
│      │
│      └─ NO ──> No Resource for this step (e.g. a pure in-process
│                business-rule check over data you already have reads no
│                external Resource).
│
└─ Q5. Does this Artifact or Resource depend on, derive from, or need to
       be traced back to something else you already recorded (this
       Trace's own earlier Artifact, another Trace entirely)?
       │
       ├─ YES ─> You may need an explicit LineageLink. In the common
       │         case — everything nested under one Trace/Activity via
       │         record_step()/instrument_client() — Lineage is already
       │         implicit in the trace_id/activity_id nesting; you do not
       │         need to construct anything extra. Explicit Lineage only
       │         matters for cross-Trace relationships (e.g. one Trace's
       │         output Artifact becomes a later, separate Trace's input)
       │         — a rarer, advanced case; see `adg.contracts.LineageLink`
       │         and ask before building this by hand.
       │
       └─ NO ──> Nothing further to do.

Worked example: applying the decision tree to a made-up customer app

Say a customer has a bespoke support-ticket triage script with no framework at all:

def triage_ticket(ticket_text: str) -> dict:
    pii_result = scan_for_pii(ticket_text)          # their own check
    category = classify_with_llm(ticket_text)        # calls an LLM
    priority = score_priority(category, pii_result)  # their own logic
    return {"category": category, "priority": priority}

Walking the tree:

  1. Q1 (Trace?) — triage_ticket(...) is one complete, independently meaningful execution (one ticket, start to finish). This is the Trace boundary. Wrap it: await observed.observe(lambda o: run_triage(o, ticket_text)).
  2. Q2 (Activity?) for each of the three inner calls:
    • scan_for_pii(...) — yes, a discrete, independently meaningful step (a guardrail check). Activity.
    • classify_with_llm(...) — yes, and it is an LLM call, so if routed through observed.chat.completions.create(...) it gets its Activity automatically.
    • score_priority(...) — a judgment call: is this worth seeing on its own, or is it a trivial one-line combination of values already captured elsewhere? If it is simple arithmetic/rule logic with no independent review value, it is reasonable to not instrument it separately, and instead fold its result into the Trace's final state (TraceFinalStateCaptured, set automatically when observe(run)'s callback returns). If the scoring logic is itself something Governance/Quality might want to audit (e.g. it is the actual decision-making step), treat it as its own Activity + Artifact (artifact_type="DECISION") instead.
  3. Q3 (Artifact?):
    • scan_for_pii(...)'s result — yes, attach it as a POLICY_EVALUATION Artifact (identical pattern to the PII guardrail worked example in our own internal test applications).
    • classify_with_llm(...)'s completion — yes, automatic via instrument_client().
  4. Q4 (Resource?):
    • scan_for_pii(...) — only if it calls an external PII-scanning service/API; if it is a pure local regex/library call with nothing external, no Resource.
    • classify_with_llm(...) — yes, the LLM itself, automatic via instrument_client().
  5. Q5 (Lineage?) — nothing here needs an explicit LineageLink; the PII Artifact and the classification Artifact are both already implicitly linked by sharing the same trace_id.

This is exactly the shape our own internal test applications already demonstrate end to end for a framework-free client.


Common pitfalls

  • Over-granularity. Not every line of code is an Activity. If you would not want to see it as its own row on a Trace's timeline when reviewing what happened, it is not an Activity. A good rule of thumb: Activities should answer "what happened" at the same level of granularity a human operator would narrate the execution out loud ("it scanned for PII, then classified the ticket, then scored it") — not at the level of every function call in the implementation.
  • Treating a Resource as an Artifact (or vice versa). A Resource is something consumed (the LLM itself, the vector store, the external API). An Artifact is something produced (the completion, the retrieval result, the decision). The same step commonly has both — an LLM call both consumes the model (Resource) and produces the completion (Artifact) — but they are never the same observation.
  • Inventing a new top-level entity. If something you are instrumenting does not cleanly fit Trace/Activity/Artifact/Resource, it is a strong signal you are modeling it at the wrong level, not that the ontology is missing a sixth entity (architecture Part 2: "the ontology must remain stable"). Re-ask Q1-Q4 at a different granularity before concluding otherwise.
  • Fabricating payload fields to match a vocabulary you assume exists. payload= should be exactly the shape your own code already produced. If a projection's canonical vocabulary (e.g. Governance's DECISION fields: outcome, confidence, decision_type) does not have an equivalent concept in your data, leave it unmapped rather than invent a value — see the Field Mapping guide's field-mapping safety checklist, which governs this same principle at the payload-field level once you already have an Artifact.
  • Forgetting the Trace-boundary default for the Direct LLM API. A bare observed.chat.completions.create(...) call with no enclosing observe(...) auto-opens its own single-call Trace — convenient for the simplest case, but it means record_step() (which requires an already-open Trace) cannot attach anything to that auto-opened Trace after the fact. If you have more than one step to record (a guardrail check plus an LLM call, for instance), wrap them together in one explicit observe(run) block from the start.

Checklist

For each new piece of customer code you want to instrument:

  • Identified the Trace boundary (Q1) — one complete, independently meaningful execution.
  • Listed every step inside it worth its own Activity (Q2) — neither one giant unstructured blob nor every line of code.
  • For each Activity, decided whether it produced an Artifact (Q3) and what artifact_type (if any) it maps to.
  • For each Activity, decided whether it consumed a Resource (Q4) and what resource_type (if any) it maps to.
  • Confirmed no cross-Trace Lineage is needed, or built an explicit LineageLink if it genuinely is (Q5 — rare).
  • Did not invent new top-level entities, fabricate payload fields, or rename your own data to fit an assumed vocabulary.

Where to go next

  • The Artifact Type Mapping guide — once you know an Activity produces an Artifact, this is how its artifact_type gets classified.
  • The formal five-entity ontology definitions this guide's decision tree is built on.