Skip to content

Knowledge representation — JSON-LD, Postgres graph, promotion ladder

Company OS keeps operational truth in Postgres. JSON-LD is the portable, human-editable view agents and external tools (Fluree, SPARQL pipelines, doc generators) can share without replacing the ledger.

Canonical context document: hsm-ii-context-v1.jsonld
Published IRI: https://permute.ai/hsm-ii/context/v1 (same terms as the file above).

Related: world-model-and-intelligence.md, self-operating-software-loop.md.


Why JSON-LD here

NeedMarkdown alonePostgres aloneJSON-LD
Human editGoodPoor (SQL)Good (JSON)
Stable IDsWeakStrong (UUID)Strong (@id / URN)
RelationsManual linksmemory_edgesfromMemory / toMemory
Agent + graph toolingWeakAPI-specificRDF-ready

Rule: Postgres is system of record; JSON-LD is export / interchange / intent envelope. Promote into Postgres first, then export JSON-LD for federation or archival.


Same spirit as world-model-and-intelligence.md—made explicit for docs, agents, and JSON-LD. Do not collapse layers (e.g. pasting constitution into every prompt, or treating chat as operational truth).

LayerWhatWho writesWho readsFormat
ConstitutionVision, principles, rarely changing company narrativeHumans (operators, DRIs)All agents via companies.context_markdown + docs/company-os/*Markdown
Operational factsDecisions, policies, KPIs, playbooks, durable company knowledgeAgents + humans; verified promote into memorycompany_memory_search, GET …/tasks/:id/llm-context, scoped toolsPostgres (company_memory_entries, memory_edges) + optional export-jsonld
ProcedureSOPs, eval packs, harness contracts, capability wiringEngineersHarness + eval runners + capability_refs on tasksYAML / JSON (+ shared @context for interchange)
EvidenceTraces, runs, governance rows, promotion ledgersAutomation (runs, verifiers, gates)Verifiers, auto-revert, audits, DRI inboxJSONL artifacts + governance_events + file ledgers

Layer ↔ JSON-LD types (v1)

LayerPrimary storeJSON-LD @type (when exported)
Constitutioncontext_markdown, git docs(markdown; no required @type today)
Operationalcompany_memory_entries, memory_edgesMemoryEntry, MemoryEdge
Procedureeval pack files, harness *.filled.json, gate_contractHarnessPromotion (ledger); pack schema is JSON Schema
Evidencegovernance_events, agent_runs, improvement_runs, turns_*.jsonlGovernanceEvent, ImprovementRun (export TBD); ledger uses HarnessPromotion

Write path: Evidence → Verify → Promote → Operational (memory row + supersedes edge). Constitution and Procedure change on human/engineer review, not on a single successful agent turn.


DRI, verifier, and ledger

RoleResponsibilityWhere it lives
DRIOwns outcome; resolves conflicts with constitution; may override when stakes demanddri_assignments, task ownership, requires_human escalation
VerifierDistinct persona/process from the subject that produced the changeseparate_verifier.rs, eval-pack disagree/override, harness approved_by / verified_by
LedgerAppend-only record that promotion happened with provenancePostgres governance_events, harness promotion_*.json (@id, source_trace_id / source_run_id), improvement_runs

Promotion without a ledger row (or without trace/run id when gates are strict) is integration debt, not shipped intelligence. See intelligence-layer-dri-alignment.md.


Agent context, review, and compaction

Engineers should spend more time on specs and gates, less on re-typing context for each agent.

ConcernPolicyImplementation hooks
Context managementCompose from llm-context + scoped search (context_key, artifact_type)—not bigger static promptsGET …/tasks/:id/llm-context; company_memory_search query params
ReviewSeparate verifier personas; eval-pack disagree / override; human inbox via requires_humanseparate_verifier.rs, eval-pack review API, company_task_requires_human
CompactionDefault retrieval L0/L1 summaries; full body only when neededsurface=l0_l1 (default env HSM_MEMORY_RETRIEVAL_SURFACE=l0_l1); surface=full or path=deep for exhaustive hybrid

Anti-patterns: stuffing constitution + all memory bodies into system prompt; one agent both proposes and approves promotion; promoting on metric regression without allow_regression and explicit operator id.


@context (v1)

Terms live under https://permute.ai/hsm-ii/vocab/. Core types:

JSON-LD @typeMeaning
MemoryEntryRow in company_memory_entries
MemoryEdgeRow in memory_edges
HarnessPromotionFile ledger under candidate/promotions/promotion_*.json
GovernanceEventRow in governance_events (export TBD)
ImprovementRunRow in improvement_runs (export TBD)

URN pattern (stable, offline-friendly):

Entity@id pattern
Companyurn:hsm:company:{uuid}
Memoryurn:hsm:memory:{uuid}
Memory edgeurn:hsm:memory-edge:{uuid}
Company agenturn:hsm:company-agent:{uuid}
Harness promotionurn:hsm:harness-promotion:{candidate_id}:{timestamp}

Postgres tables → JSON-LD types

PostgresJSON-LD typeKey properties
company_memory_entriesMemoryEntrytitle, summaryL0, summaryL1, body, scope, contextKey, artifactType, kind, version, isLatest, supersedes
memory_edgesMemoryEdgerelationType, fromMemory, toMemory, confidence
memory_artifacts / memory_chunks(nested in inspect API; optional future Artifact type)provenance for ingest
governance_eventsGovernanceEventaction, actor, subject, payload
improvement_runsImprovementRunbaseline/candidate/metrics meta
tasks(future Task type)spec, capability_refs, context_notes

artifact_type taxonomy (memory)

Distinct from kind (general | broadcast):

general · playbook · kpi · policy_snippet · briefing · runbook

Set via column, tag artifact:playbook, or ingest metadata.

context_key (partition)

Business context slice (e.g. sales, finance). Filter retrieval with ?context_key= or tag ctx:sales on append.

memory_edges.relation_type

DB valuePromotion ladder role
supersedesPromote — new fact replaces old (is_latest)
supportsVerify — evidence for a candidate
contradictsBlock — triggers human / DRI review
derivesObserve — trace-derived link
extendsBind — same topic, more detail
updatesExpose — revision without full supersession
relatedWeak association

Promotion ladder ↔ graph ↔ gates

From world-model-and-intelligence.md:

text
Observe → Bind → Expose → Verify → Promote
StepPostgres / artifactsGraph edgeEnforcement (promotion_gates.rs)
Observeagent_runs, traces, run_failure_eventsderives
Bindtask_id, capability_refs, entity_typeextends / relatedtyped ship meta on overlay
Exposellm-context, memory L0/L1 searchGET …/export-jsonld
Verifycompany_eval_reviews, replay, separate verifiersupportsrequire_distinct_verifier
Promoteimprovement_runs, harness promotion_*.json, memory is_latestsupersedesmetrics + retest_passed + trace id

Do not promote on prose-only overlay text: harness apply requires artifact_kind, schema_version, and source_trace_id or source_run_id in meta (server) and in promotion ledger JSON (CLI).


HTTP APIs

EndpointRole
GET /api/company/companies/{company_id}/memory/{memory_id}/export-jsonldCanonical JSON-LD for one memory + incident memory_edges
GET …/memory/{memory_id}/inspectFull inspector; includes jsonld_export_path hint
GET …/memory/{memory_id}/edgesRaw edge list (JSON)

Example:

bash
curl -s -H "Authorization: Bearer $HSM_COMPANY_API_BEARER" \
  "$HSM_CONSOLE_URL/api/company/companies/$CID/memory/$MID/export-jsonld" | jq .

Response shape:

json
{
  "@context": "https://permute.ai/hsm-ii/context/v1",
  "@id": "urn:hsm:memory:…",
  "@type": "MemoryEntry",
  "@graph": [
    { "@id": "urn:hsm:memory:…", "@type": "MemoryEntry", "title": "…", "summaryL1": "…" },
    { "@id": "urn:hsm:memory-edge:…", "@type": "MemoryEdge", "relationType": "supports",  }
  ]
}

Harness promotion ledger (file)

Written by scripts/meta-harness/company_os_promote_delta.py to
{candidate_dir}/promotions/promotion_{timestamp}.json.

Required fields (non-dry-run):

FieldPurpose
@idStable promotion URN (auto-generated if omitted)
source_trace_id or source_run_idProvenance (from filled delta or CLI flags)
approved_byDistinct verifier (human/operator id)
before_metrics / after_metricsMetric gate (e.g. finalize_rate)

Optional JSON-LD aliases: promotion_id (= @id), trace_id (= source_trace_id).

Aligns with server promotion_gates::validate_ship_artifact_meta and improvement-run require_promotion_evidence.


Maintenance checklist

  1. Constitution — edit context_markdown / docs; do not duplicate into every agent prompt.
  2. Operational — promote to memory; add edges; export-jsonld after promote if federating.
  3. Procedure — version eval packs and harness contracts in git; wire capability_refs on tasks.
  4. Evidence — every promote leaves trace/run id + governance or file ledger; verifiers are distinct from subjects.

Anti-patterns: authoritative state only in chat; promote without trace; ship overlay without typed meta; two competing ledgers without sync; retrieval surface=full as the default for all queries.


Fluree (optional downstream)

If you adopt Fluree or another RDF store:

  • Sync direction: Postgres → JSON-LD export → Fluree ingest (on promote or schedule).
  • Keep Company OS SQL APIs for console, spend, tasks, and llm-context.
  • Use SPARQL for cross-company analytics; use hybrid memory search for agent retrieval.

No Fluree dependency is required to use JSON-LD export today.

HSM-II documentation built with VitePress