@prefix :       <https://linkeddata.uriburner.com/DAV/demos/daas/ai-agent-memory-context-engineering-claude_sonnet_4_6-1.ttl#> .
@prefix schema: <http://schema.org/> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:    <http://www.w3.org/2002/07/owl#> .
@prefix foaf:   <http://xmlns.com/foaf/0.1/> .
@prefix prov:   <http://www.w3.org/ns/prov#> .
@prefix dcterms:<http://purl.org/dc/terms/> .
@prefix dbr:    <http://dbpedia.org/resource/> .
@prefix skos:   <http://www.w3.org/2004/02/skos/core#> .

# ── Self-describing document entity ──────────────────────────────────────────

<https://linkeddata.uriburner.com/DAV/demos/daas/ai-agent-memory-context-engineering-claude_sonnet_4_6-1.ttl>
    a schema:CreativeWork ;
    schema:name "AI Agent Memory: Better Handled via Context Engineering"@en ;
    schema:description "A knowledge graph synthesising ByteByteGo's analysis of AI agent memory management with the agent-rdf-memory reference implementation — arguing that RDF-based context engineering provides a superior, queryable, semantically-precise substrate for persistent agent memory compared to plain-text or vector-store approaches."@en ;
    schema:about :ContextEngineering ;
    schema:dateCreated "2026-06-29T00:00:00Z"^^xsd:dateTime ;
    schema:dateModified "2026-06-29T00:00:00Z"^^xsd:dateTime ;
    schema:author <https://www.linkedin.com/in/kidehen#this> ;
    schema:license <https://creativecommons.org/licenses/by/4.0/> ;
    schema:keywords "context engineering, AI agent memory, RDF, Turtle, agent-rdf-memory, working memory, episodic memory, semantic memory, procedural memory, context window, LLM statelessness, SessionStart hook, behavioral contract, knowledge graph"@en ;
    schema:inLanguage "en" ;
    prov:wasGeneratedBy <https://github.com/OpenLinkSoftware/ai-agent-skills/tree/main/kg-generator#this> ;
    schema:hasPart :GlossaryTermSet ,
                   :howtoContextEngineering ,
                   :AgentMemoryFAQ ,
                   :ComparativeAnalysis .

# ── Lightweight Ontology ──────────────────────────────────────────────────────

:AgentMemoryOntology a owl:Ontology ;
    schema:name "Agent Memory Context Engineering Ontology"@en ;
    schema:description "A lightweight ontology defining custom classes and properties for describing AI agent memory management through context engineering, with explicit modeling of memory types, storage tiers, context injection mechanisms, and RDF-based behavioral contracts."@en ;
    rdfs:label "Agent Memory Ontology"@en ;
    rdfs:comment "Custom vocabulary for the AI Agent Memory Context Engineering knowledge graph."@en ;
    owl:versionInfo "1.0"@en ;
    schema:dateCreated "2026-06-29"^^xsd:date .

:MemoryType a rdfs:Class ;
    rdfs:label "Memory Type"@en ;
    rdfs:comment "A functional category of agent memory distinguished by its cognitive role: working (immediate), episodic (time-anchored events), semantic (context-independent facts), or procedural (learned behavioral patterns)."@en ;
    rdfs:subClassOf schema:DefinedTerm ;
    rdfs:isDefinedBy :AgentMemoryOntology ;
    rdfs:seeAlso dbr:Memory ,
                 <http://dbpedia.org/resource/Cognitive_science> .

:MemoryTier a rdfs:Class ;
    rdfs:label "Memory Tier"@en ;
    rdfs:comment "A storage layer in the agent memory hierarchy, analogous to RAM versus disk in operating systems — ranging from the hot context window to cold compliance archives."@en ;
    rdfs:subClassOf schema:DefinedTerm ;
    rdfs:isDefinedBy :AgentMemoryOntology ;
    rdfs:seeAlso <http://dbpedia.org/resource/Memory_hierarchy> .

:ContextEngineeringPattern a rdfs:Class ;
    rdfs:label "Context Engineering Pattern"@en ;
    rdfs:comment "A design pattern for strategically assembling and injecting information into a stateless LLM's context window to produce coherent, memory-aware behavior across API calls."@en ;
    rdfs:subClassOf schema:DefinedTerm ;
    rdfs:isDefinedBy :AgentMemoryOntology ;
    rdfs:seeAlso dbr:Software_design_pattern .

:AgentMemorySystem a rdfs:Class ;
    rdfs:label "Agent Memory System"@en ;
    rdfs:comment "A software system that implements persistent memory for a stateless LLM agent through structured storage, retrieval, and context injection mechanisms."@en ;
    rdfs:subClassOf schema:SoftwareApplication ;
    rdfs:isDefinedBy :AgentMemoryOntology ;
    rdfs:seeAlso <http://dbpedia.org/resource/Artificial_intelligence> .

# ── Custom Properties ─────────────────────────────────────────────────────────

:addressesChallenge a rdf:Property ;
    rdfs:label "addresses challenge"@en ;
    rdfs:comment "Relates a solution or pattern to the memory management challenge it solves."@en ;
    rdfs:domain schema:Thing ;
    rdfs:range schema:DefinedTerm ;
    rdfs:isDefinedBy :AgentMemoryOntology .

:storesIn a rdf:Property ;
    rdfs:label "stores in"@en ;
    rdfs:comment "Relates a memory type to the storage tier or file in which it is persisted."@en ;
    rdfs:domain :MemoryType ;
    rdfs:range schema:Thing ;
    rdfs:isDefinedBy :AgentMemoryOntology .

:injectsInto a rdf:Property ;
    rdfs:label "injects into"@en ;
    rdfs:comment "Relates a context engineering mechanism to the context window it populates."@en ;
    rdfs:domain :ContextEngineeringPattern ;
    rdfs:range :MemoryTier ;
    rdfs:isDefinedBy :AgentMemoryOntology .

:encodesAs a rdf:Property ;
    rdfs:label "encodes as"@en ;
    rdfs:comment "Relates a memory content category to the RDF serialization format used to persist it."@en ;
    rdfs:domain :MemoryType ;
    rdfs:range schema:DefinedTerm ;
    rdfs:isDefinedBy :AgentMemoryOntology .

:supersedes a rdf:Property ;
    rdfs:label "supersedes"@en ;
    rdfs:comment "Relates a more capable or precise approach to the less adequate approach it replaces."@en ;
    rdfs:domain schema:Thing ;
    rdfs:range schema:Thing ;
    rdfs:isDefinedBy :AgentMemoryOntology .

# ── Primary Sources ───────────────────────────────────────────────────────────

:ByteByteGoArticle a schema:Article ;
    schema:name "How AI Agents Manage Memory (And Avoid the Traps)"@en ;
    schema:description "A technical analysis of AI agent memory management covering the four memory types, four storage tiers, retrieval challenges, the lost-in-the-middle effect, and critical tradeoffs in production memory systems."@en ;
    schema:url <https://blog.bytebytego.com/p/how-ai-agents-manage-memory-and-avoid> ;
    schema:publisher :ByteByteGo ;
    schema:about :LLMStatelessness , :ContextEngineering , :MemoryHierarchy ;
    schema:datePublished "2026"^^xsd:gYear ;
    schema:inLanguage "en" .

:AgentRdfMemoryRepo a schema:SoftwareSourceCode ;
    schema:name "agent-rdf-memory Reference Implementation"@en ;
    schema:description "A Turtle-based RDF memory system for LLM agents that implements context engineering through structured files (core.ttl, preferences.ttl, index.ttl, sessions/, howto/) and a SessionStart hook that automatically injects compiled memory into every new agent session."@en ;
    schema:url <https://github.com/OpenLinkSoftware/ai-agent-skills/tree/main/agent-rdf-memory> ;
    schema:codeRepository <https://github.com/OpenLinkSoftware/ai-agent-skills> ;
    schema:author <https://www.linkedin.com/in/kidehen#this> ;
    schema:maintainer :OpenLinkSoftware ;
    :addressesChallenge :LLMStatelessness ;
    :supersedes :PlainTextMarkdownMemory .

# ── Organizations ─────────────────────────────────────────────────────────────

:ByteByteGo a schema:Organization ;
    schema:name "ByteByteGo"@en ;
    schema:description "A software engineering education platform known for system design content, newsletters, and technical deep-dives on distributed systems, AI infrastructure, and backend architecture."@en ;
    schema:url <https://bytebytego.com> .

:OpenLinkSoftware owl:sameAs <http://dbpedia.org/resource/OpenLink_Software> ;
    a schema:Organization ;
    schema:name "OpenLink Software"@en ;
    schema:description "Creator of Virtuoso Universal Server, the SPARQL endpoint powering URIBurner, and developer of the agent-rdf-memory context engineering pattern for LLM agents."@en ;
    schema:url <https://www.openlinksw.com> .

# ── People ────────────────────────────────────────────────────────────────────

<https://www.linkedin.com/in/kidehen#this>
    a schema:Person ;
    schema:name "Kingsley Uyi Idehen"@en ;
    schema:jobTitle "Founder & CEO"@en ;
    schema:worksFor :OpenLinkSoftware ;
    schema:description "Creator of the agent-rdf-memory context engineering system and principal operator of the AI agent skills repository. Advocate for using semantic web standards (RDF, Linked Data, WebID) as the substrate for agent memory and identity."@en .

# ── Core Concepts ─────────────────────────────────────────────────────────────

:LLMStatelessness a schema:DefinedTerm ;
    schema:name "LLM Statelessness"@en ;
    schema:description "The fundamental property of large language models whereby each API call begins from a completely fresh slate with no memory of prior interactions. The illusion of continuity in conversational AI systems is entirely produced by platform engineering that strategically reinserts context into each call."@en ;
    schema:termCode "llm-statelessness"@en ;
    skos:related dbr:Large_language_model ,
                 dbr:Stateless_protocol .

:ContextEngineering a schema:DefinedTerm ;
    schema:name "Context Engineering"@en ;
    schema:description "The discipline of strategically assembling, compressing, and injecting the right information into a stateless LLM's context window to produce coherent, memory-aware behavior across sessions. Context engineering is the actual mechanism behind 'agent memory' — not the LLM itself holding state, but the platform engineering that reconstitutes relevant context before each model call."@en ;
    schema:termCode "context-engineering"@en ;
    :addressesChallenge :LLMStatelessness ;
    skos:related dbr:Prompt_engineering .

:MemoryHierarchy a schema:DefinedTerm ;
    schema:name "Memory Hierarchy"@en ;
    schema:description "A four-tier architecture for organizing agent memory — working memory (active context window), session memory (recent activity awaiting summarization), long-term storage (persistent facts and embeddings across sessions), and cold archive (rarely accessed material retained for compliance) — mirroring how operating systems manage RAM versus disk storage."@en ;
    schema:termCode "memory-hierarchy"@en ;
    skos:related <http://dbpedia.org/resource/Memory_hierarchy> .

:ContextWindow a schema:DefinedTerm ;
    schema:name "Context Window"@en ;
    schema:description "The bounded region of text that a language model can read during a single API call. Every agent interaction is constrained by this window's token limit. While larger windows reduce some pressure, three critical constraints persist: linear cost accumulation, processing delays, and the lost-in-the-middle effect."@en ;
    schema:termCode "context-window"@en ;
    skos:related dbr:Large_language_model .

:LostInTheMiddleEffect a schema:DefinedTerm ;
    schema:name "Lost-in-the-Middle Effect"@en ;
    schema:description "An empirically observed degradation in LLM recall for information positioned centrally in long prompts. Content at the beginning and end of the context window receives more reliable attention than content in the middle, making naive 'stuff everything in context' approaches unreliable for memory-intensive agent tasks."@en ;
    schema:termCode "lost-in-the-middle"@en .

:PlainTextMarkdownMemory a schema:DefinedTerm ;
    schema:name "Plain-Text / Markdown Memory"@en ;
    schema:description "A naive approach to agent memory that stores behavioral rules, preferences, and session history as unstructured or lightly structured markdown or plain-text files. These are not queryable, not semantically typed, and cannot be reasoned over — making them inferior to RDF-based approaches for complex multi-rule behavioral contracts."@en ;
    schema:termCode "plain-text-memory"@en .

:RDFBasedAgentMemory a schema:DefinedTerm ;
    schema:name "RDF-Based Agent Memory"@en ;
    schema:description "An approach to agent memory that persists behavioral rules, session history, and identity in RDF Turtle files using well-typed schema.org and custom ontology terms. RDF memory is queryable via SPARQL, dereferenceable via HTTP, semantically typed, and structured to support the sparse-index pattern — compact manifests in always-loaded files, full detail in on-demand howto files."@en ;
    schema:termCode "rdf-based-memory"@en ;
    :supersedes :PlainTextMarkdownMemory ;
    skos:related dbr:Resource_Description_Framework ,
                 dbr:Semantic_Web .

:BehavioralContract a schema:DefinedTerm ;
    schema:name "Behavioral Contract"@en ;
    schema:description "A set of standing instructions encoded as schema:HowToStep entities in RDF, establishing rules the agent must follow in every session. Being structured as RDF, behavioral contracts are queryable, composable, and harder to overlook than flat prose instructions — each step carries a trigger condition, a one-sentence rule, and a pointer to a companion howto file with full detail."@en ;
    schema:termCode "behavioral-contract"@en .

:SparseIndexPattern a schema:DefinedTerm ;
    schema:name "Sparse Index Pattern"@en ;
    schema:description "A two-tier memory organisation where the always-loaded index file (preferences.ttl) contains only step names, one-sentence rules, trigger conditions, and rdfs:seeAlso pointers — never full prose. Verbose rationale, code examples, and verification gates live in on-demand companion howto/*.ttl files. This minimises the token cost of loading the behavioral contract at every session start."@en ;
    schema:termCode "sparse-index-pattern"@en .

:SessionStartHook a schema:DefinedTerm ;
    schema:name "SessionStart Hook"@en ;
    schema:description "A Python script (load_memory.py) configured as a harness hook that fires at the beginning of every agent session. It reads core.ttl, preferences.ttl, index.ttl, and the most recent session file, then injects their compiled content as additionalContext into the model before the first user turn — implementing context engineering structurally rather than relying on the agent to remember to load memory."@en ;
    schema:termCode "session-start-hook"@en .

:MemoryProtocolValidationGate a schema:DefinedTerm ;
    schema:name "Memory Protocol Validation Gate"@en ;
    schema:description "A post-session audit script (validate-memory-protocol.py) that parses Claude Code session transcripts and verifies that all five steps of the Agent RDF Memory Protocol were executed before the agent responded. Catches failures the SessionStart hook could not prevent and drives iterative improvement of the hook injection."@en ;
    schema:termCode "memory-protocol-gate"@en .

:RetrievalAsChallenge a schema:DefinedTerm ;
    schema:name "Retrieval as the Central Challenge"@en ;
    schema:description "The observation that memory failures in production AI agent systems are typically retrieval failures in disguise — not a lack of stored information, but a failure to surface the right stored information at the right moment. Systems address this through keyword search, semantic similarity matching, and recency signals to assemble contextual relevance."@en ;
    schema:termCode "retrieval-challenge"@en .

# ── Memory Types ──────────────────────────────────────────────────────────────

:WorkingMemoryType a :MemoryType ;
    schema:name "Working Memory"@en ;
    schema:description "Live context for immediate tasks — the information currently active inside the context window for the current model call. In agent-rdf-memory this corresponds to the content injected by the SessionStart hook plus the accumulated conversation for the current session."@en ;
    schema:termCode "working-memory"@en ;
    :storesIn :WorkingMemoryTier ;
    :encodesAs :TurtleRDF .

:EpisodicMemoryType a :MemoryType ;
    schema:name "Episodic Memory"@en ;
    schema:description "Time-anchored records of specific past interactions and events. In agent-rdf-memory this is persisted as dated session files (sessions/YYYY-MM-DD-{llm-id}-{agent-env}.ttl) using opal:ChatSession, opal:ChatMessage, and prov:Activity terms — making events queryable by date, model, and task type."@en ;
    schema:termCode "episodic-memory"@en ;
    :storesIn :SessionMemoryTier ;
    :encodesAs :TurtleRDF .

:SemanticMemoryType a :MemoryType ;
    schema:name "Semantic Memory"@en ;
    schema:description "Context-independent facts that remain true across sessions — user identity, output path routing, organizational affiliations, and canonical IRIs. In agent-rdf-memory this is stored in core.ttl as schema:Person, schema:PropertyValue, and owl:sameAs triples, queryable from any subsequent session."@en ;
    schema:termCode "semantic-memory"@en ;
    :storesIn :LongTermStorageTier ;
    :encodesAs :TurtleRDF .

:ProceduralMemoryType a :MemoryType ;
    schema:name "Procedural Memory"@en ;
    schema:description "Learned patterns and behavioral rules that govern how the agent executes tasks. In agent-rdf-memory this is encoded as schema:HowToStep entities in preferences.ttl (sparse index) and companion howto/*.ttl files (full detail) — covering 103 standing instructions across identity verification, artifact routing, RDF authoring, skill invocation, and UI/UX patterns."@en ;
    schema:termCode "procedural-memory"@en ;
    :storesIn :LongTermStorageTier ;
    :encodesAs :TurtleRDF .

# ── Memory Tiers ──────────────────────────────────────────────────────────────

:WorkingMemoryTier a :MemoryTier ;
    schema:name "Working Memory Tier"@en ;
    schema:description "The active context window for the current model call. Hot, expensive, and bounded by the model's token limit. Populated by the SessionStart hook from the RDF memory files."@en ;
    schema:termCode "tier-working"@en .

:SessionMemoryTier a :MemoryTier ;
    schema:name "Session Memory Tier"@en ;
    schema:description "Recent interaction history awaiting summarization or archival. In agent-rdf-memory represented by the current day's session TTL file, which accumulates tasks, prompts, and outcomes until session end triggers a final write."@en ;
    schema:termCode "tier-session"@en .

:LongTermStorageTier a :MemoryTier ;
    schema:name "Long-Term Storage Tier"@en ;
    schema:description "Persistent facts and behavioral rules that survive across sessions. In agent-rdf-memory this corresponds to core.ttl (semantic facts), preferences.ttl (procedural rules), and the sessions/ archive (episodic history). Queryable via SPARQL against the local RDF file system."@en ;
    schema:termCode "tier-long-term"@en .

:ColdArchiveTier a :MemoryTier ;
    schema:name "Cold Archive Tier"@en ;
    schema:description "Rarely accessed historical session files retained for compliance, audit, and pattern analysis. In agent-rdf-memory this is the full sessions/ directory — every past session TTL is queryable even if not injected at startup."@en ;
    schema:termCode "tier-cold-archive"@en .

# ── RDF Turtle as memory substrate ───────────────────────────────────────────

:TurtleRDF a schema:DefinedTerm ;
    schema:name "RDF Turtle"@en ;
    schema:description "The serialisation format used throughout agent-rdf-memory. Turtle is human-readable, diff-friendly, supports named graphs, and is parseable by SPARQL engines — making it superior to JSON or markdown for structured agent memory."@en ;
    schema:termCode "turtle-rdf"@en ;
    skos:related <http://dbpedia.org/resource/Turtle_(syntax)> ,
                 dbr:Resource_Description_Framework .

# ── The agent-rdf-memory System Components ───────────────────────────────────

:PreferencesTtl a schema:SoftwareSourceCode ;
    schema:name "preferences.ttl"@en ;
    schema:description "The always-loaded behavioral contract file — 103 schema:HowToStep entries, each with a one-sentence rule, trigger conditions (onto:hasTrigger), and a pointer (rdfs:seeAlso) to a companion howto file. Follows the sparse-index pattern to minimise per-session token cost."@en ;
    schema:encodingFormat "text/turtle"@en ;
    schema:isPartOf :AgentRdfMemoryRepo ;
    :encodesAs :BehavioralContract .

:CoreTtl a schema:SoftwareSourceCode ;
    schema:name "core.ttl"@en ;
    schema:description "Persistent semantic memory — user identity (schema:Person), LLM output path routing (schema:PropertyValue per model), and organizational affiliations. Loaded at every session start by the SessionStart hook."@en ;
    schema:encodingFormat "text/turtle"@en ;
    schema:isPartOf :AgentRdfMemoryRepo ;
    :encodesAs :SemanticMemoryType .

:HowtoFiles a schema:SoftwareSourceCode ;
    schema:name "howto/*.ttl files"@en ;
    schema:description "Companion files to preferences.ttl containing full procedural detail for each behavioral rule — rationale, code examples, incident notes, verification gates, and edge cases. Loaded on demand via rdfs:seeAlso references. Currently 44 companion files covering session governance, artifact routing, skill invocation, KG explorer patterns, identity verification, and more."@en ;
    schema:encodingFormat "text/turtle"@en ;
    schema:isPartOf :AgentRdfMemoryRepo ;
    :encodesAs :ProceduralMemoryType .

:SessionFiles a schema:SoftwareSourceCode ;
    schema:name "sessions/YYYY-MM-DD-{llm-id}-{agent-env}.ttl"@en ;
    schema:description "Per-session episodic memory files using the OPAL Analytics Ontology vocabulary (opal:ChatSession, opal:ChatMessage, opal:ChatModel) alongside prov:Activity and schema.org terms. Each session file records: tasks completed, skills invoked, artifacts generated, preferences updated, verbatim user prompts, inferred preferences, and behavior gaps identified."@en ;
    schema:encodingFormat "text/turtle"@en ;
    schema:isPartOf :AgentRdfMemoryRepo ;
    :encodesAs :EpisodicMemoryType .

:AgentRdfMemoryRepo
    schema:hasPart :PreferencesTtl ,
                   :CoreTtl ,
                   :HowtoFiles ,
                   :SessionFiles ,
                   :SessionStartHook .

:AgentRdfMemoryRepo :addressesChallenge :LLMStatelessness ,
                                          :LostInTheMiddleEffect ,
                                          :RetrievalAsChallenge .
:AgentRdfMemoryRepo :supersedes :PlainTextMarkdownMemory .

# ── Key Relations for KG Explorer ─────────────────────────────────────────────

:ContextEngineering :addressesChallenge :LLMStatelessness .
:RDFBasedAgentMemory :addressesChallenge :RetrievalAsChallenge .
:RDFBasedAgentMemory :supersedes :PlainTextMarkdownMemory .
:SessionStartHook :injectsInto :WorkingMemoryTier .
:PreferencesTtl :encodesAs :BehavioralContract .
:BehavioralContract :addressesChallenge :LLMStatelessness .
:SparseIndexPattern :addressesChallenge :LostInTheMiddleEffect .

# ── Comparative Analysis ────────────────────────────────────────────────────

:ComparativeAnalysis a schema:CreativeWork ;
    schema:name "Comparative Analysis: Generic Framework vs. Concrete Implementation"@en ;
    schema:description "Side-by-side comparison contrasting the ByteByteGo article's vendor-neutral memory framework against the agent-rdf-memory repository's concrete RDF-based implementation choices."@en ;
    schema:about :ByteByteGoArticle , :AgentRdfMemoryRepo ;
    schema:hasPart :cmpAbstraction , :cmpSubstrate , :cmpRetrieval , :cmpInjection ,
        :cmpCompression , :cmpVerifiability , :cmpQueryability , :cmpFailureMode , :cmpAudience .

:cmpAbstraction a schema:DefinedTerm ;
    schema:name "Level of abstraction"@en ;
    schema:description "ByteByteGo: vendor-neutral taxonomy applicable to any agent stack. agent-rdf-memory: a single, opinionated reference implementation."@en .

:cmpSubstrate a schema:DefinedTerm ;
    schema:name "Memory substrate"@en ;
    schema:description "ByteByteGo: unspecified — vector DB, SQL, key-value, or files. agent-rdf-memory: RDF Turtle exclusively, a typed named-IRI graph."@en .

:cmpRetrieval a schema:DefinedTerm ;
    schema:name "Retrieval mechanism"@en ;
    schema:description "ByteByteGo: generic retrieval, typically semantic/vector similarity search. agent-rdf-memory: structural injection via SessionStart hook plus on-demand rdfs:seeAlso traversal, no embeddings."@en .

:cmpInjection a schema:DefinedTerm ;
    schema:name "Injection trigger"@en ;
    schema:description "ByteByteGo: not prescribed, left to the implementer. agent-rdf-memory: hard-coded hook (load_memory.py) fires before every session."@en .

:cmpCompression a schema:DefinedTerm ;
    schema:name "Compression strategy"@en ;
    schema:description "ByteByteGo: summarisation, which is lossy. agent-rdf-memory: sparse-index pattern, a lossless pointer-based deferral to howto/*.ttl files."@en .

:cmpVerifiability a schema:DefinedTerm ;
    schema:name "Verifiability"@en ;
    schema:description "ByteByteGo: not addressed, no audit mechanism described. agent-rdf-memory: validate-memory-protocol.py post-session transcript audit plus a schema:text length gate."@en .

:cmpQueryability a schema:DefinedTerm ;
    schema:name "Queryability"@en ;
    schema:description "ByteByteGo: implementation-dependent. agent-rdf-memory: native SPARQL queryability across the memory store."@en .

:cmpFailureMode a schema:DefinedTerm ;
    schema:name "Primary failure mode named"@en ;
    schema:description "Both name the lost-in-the-middle effect and retrieval failure; agent-rdf-memory mitigates these structurally rather than algorithmically."@en .

:cmpAudience a schema:DefinedTerm ;
    schema:name "Audience and purpose"@en ;
    schema:description "ByteByteGo: industry-wide conceptual reference. agent-rdf-memory: a production behavioral contract for one agent operating in one repository."@en .

# ── FAQ ───────────────────────────────────────────────────────────────────────

:faq1q a schema:Question ;
    schema:name "Why are LLMs described as stateless, and what does that actually mean for agent memory?"@en ;
    schema:acceptedAnswer :faq1a .

:faq1a a schema:Answer ;
    schema:text "Every LLM API call begins from a completely fresh slate — the model has no access to prior calls even one millisecond earlier. There is no built-in memory; the illusion of continuity is produced entirely by platform engineering that strategically reinserts relevant context (prior messages, facts, rules) into each new call. This means 'agent memory' is not a property of the model — it is a property of the infrastructure wrapping it."@en .

:faq2q a schema:Question ;
    schema:name "What is context engineering, and how does it differ from prompt engineering?"@en ;
    schema:acceptedAnswer :faq2a .

:faq2a a schema:Answer ;
    schema:text "Prompt engineering focuses on crafting individual instructions to steer model behavior in a single call. Context engineering is the broader discipline of deciding what information to include, exclude, compress, or retrieve across the entire context window — managing memory tiers, retrieval signals, summarisation fidelity, and injection timing so the model has the right information at each turn. Context engineering is the architectural layer; prompt engineering is one tool within it."@en .

:faq3q a schema:Question ;
    schema:name "What are the four memory types in AI agent systems, and how does agent-rdf-memory implement each?"@en ;
    schema:acceptedAnswer :faq3a .

:faq3a a schema:Answer ;
    schema:text "Working memory (active context window — populated by the SessionStart hook from RDF files), Episodic memory (time-anchored interaction records — sessions/YYYY-MM-DD-{llm-id}-{agent-env}.ttl using OPAL Analytics Ontology), Semantic memory (context-independent facts — core.ttl with schema:Person, schema:PropertyValue triples), Procedural memory (behavioral rules — preferences.ttl sparse index + 44 companion howto/*.ttl files encoding 103 standing instructions)."@en .

:faq4q a schema:Question ;
    schema:name "What is the 'lost-in-the-middle effect' and how does agent-rdf-memory mitigate it?"@en ;
    schema:acceptedAnswer :faq4a .

:faq4a a schema:Answer ;
    schema:text "The lost-in-the-middle effect is the empirically observed phenomenon where LLMs recall information at the beginning and end of a context window more reliably than information in the middle. agent-rdf-memory mitigates this through the sparse-index pattern: preferences.ttl (always injected first) contains only step names and one-sentence rules — keeping it compact enough that all content falls in the high-attention zone. Full detail is in howto/*.ttl files loaded on demand."@en .

:faq5q a schema:Question ;
    schema:name "Why is RDF Turtle superior to plain markdown for agent behavioral contracts?"@en ;
    schema:acceptedAnswer :faq5a .

:faq5a a schema:Answer ;
    schema:text "RDF Turtle gives behavioral rules four properties markdown cannot provide: (1) queryability — rules are addressable via SPARQL by trigger condition, position, or topic; (2) semantic typing — each rule is a schema:HowToStep with explicit rdf:type, trigger, and rdfs:seeAlso; (3) resolvability — entity IRIs are dereferenceable URLs, not opaque strings; (4) composability — rules can cross-reference each other via rdfs:seeAlso and skos:related, forming a connected graph rather than a flat list."@en .

:faq6q a schema:Question ;
    schema:name "How does the SessionStart hook implement context engineering structurally?"@en ;
    schema:acceptedAnswer :faq6a .

:faq6a a schema:Answer ;
    schema:text "The SessionStart hook (load_memory.py) fires before the agent generates any response. It reads core.ttl, preferences.ttl, index.ttl, and the most recent session file, then returns their compiled content as additionalContext to the harness, which injects it into the model's context window. This makes memory loading structural — enforced by the runtime, not reliant on the agent remembering to invoke a tool. A GATE instruction in the injected content additionally reminds the agent to execute the full five-step memory protocol."@en .

:faq7q a schema:Question ;
    schema:name "What is the sparse-index pattern and why does preferences.ttl follow it?"@en ;
    schema:acceptedAnswer :faq7a .

:faq7a a schema:Answer ;
    schema:text "The sparse-index pattern splits behavioral memory into two tiers: a compact always-loaded index (preferences.ttl) containing only step names, one-sentence rules, trigger conditions, and rdfs:seeAlso pointers; and verbose on-demand companion files (howto/*.ttl) with full rationale, code examples, and gates. preferences.ttl is read at every session start — its token cost is paid unconditionally. Verbose content would inflate that cost by the factor of its length every single session. The sparse index keeps session-start cost near-constant even as the number of rules grows."@en .

:faq8q a schema:Question ;
    schema:name "What are the critical tradeoffs every agent memory architect must navigate?"@en ;
    schema:acceptedAnswer :faq8a .

:faq8a a schema:Answer ;
    schema:text "Four key tradeoffs: (1) Recency vs. relevance — balancing between the most recent and the most semantically similar information; (2) Summarisation fidelity — compression reduces cost but loses precise details; (3) Staleness — outdated facts can persist with unwarranted confidence; (4) Security exposure — persistent memory creates long-term attack surfaces for prompt injection. agent-rdf-memory addresses staleness via dated session files and explicit dateModified tracking, and injection risk via the behavioural rule against incorporating unverified external content."@en .

:faq9q a schema:Question ;
    schema:name "How does the memory protocol validation gate enforce compliance?"@en ;
    schema:acceptedAnswer :faq9a .

:faq9a a schema:Answer ;
    schema:text "validate-memory-protocol.py parses Claude Code JSONL session transcripts and checks for five mandatory tool calls in order: (1) ls agent-rdf-memory/, (2) Read core.ttl, (3) Read preferences.ttl, (4) Read index.ttl, (5) at least one additional file under howto/ or sessions/. The script returns exit code 0 (PASS) or 1 (FAIL) and in --strict mode additionally verifies that all reads occurred before the first substantive assistant response — catching 'read-after-respond' violations where the agent answered from stale context then retroactively loaded memory."@en .

:faq10q a schema:Question ;
    schema:name "How does agent-rdf-memory's context engineering compare to retrieval-augmented generation (RAG)?"@en ;
    schema:acceptedAnswer :faq10a .

:faq10a a schema:Answer ;
    schema:text "RAG retrieves relevant chunks from a vector store at query time and injects them into the prompt. agent-rdf-memory uses a complementary but distinct approach: it injects structured RDF memory in full at session start (not query time), ensuring behavioral rules are always present. Retrieval in agent-rdf-memory is reserved for querying the local RDF file system during KG question-answering workflows (data-twingler skill), not for loading the behavioral contract. The two approaches can coexist — RDF context engineering for behavioral rules, RAG for knowledge retrieval."@en .

:faq11q a schema:Question ;
    schema:name "What naming convention does agent-rdf-memory use for session files, and why?"@en ;
    schema:acceptedAnswer :faq11a .

:faq11a a schema:Answer ;
    schema:text "Session files follow the pattern YYYY-MM-DD-{llm-id}-{agent-env}.ttl — for example, 2026-06-29-claude_sonnet_4_6-claude_code.ttl. The three-component key (date, model, environment) enables unambiguous cross-session provenance: the same day can produce multiple files for different models or environments, and the model component is always sourced from the system-prompt model identifier — never inferred from conversation context. This naming convention feeds directly into the memory protocol validation gate and the output routing rules in core.ttl."@en .

:faq12q a schema:Question ;
    schema:name "What does 'memory failures are retrieval failures in disguise' mean for system design?"@en ;
    schema:acceptedAnswer :faq12a .

:faq12a a schema:Answer ;
    schema:text "As ByteByteGo observes, production memory failures are almost never caused by information not being stored — they are caused by the right information not being surfaced at the right moment. This shifts the design burden from storage capacity to retrieval precision. In agent-rdf-memory, retrieval is improved structurally: the SessionStart hook pre-loads the most critical memory unconditionally; howto files are loaded on demand via rdfs:seeAlso references when a rule is triggered; and the index.ttl provides a dated inventory of all sessions for retrospective lookup. The SPARQL-queryable structure means any fact can be retrieved by subject, predicate, trigger condition, or date range."@en .

# ── Glossary Container ────────────────────────────────────────────────────────

:GlossaryTermSet a schema:DefinedTermSet ;
    schema:name "Glossary: AI Agent Memory and Context Engineering"@en ;
    schema:description "Key terms from the ByteByteGo analysis and the agent-rdf-memory implementation, covering memory types, storage patterns, and context engineering mechanisms."@en ;
    schema:hasDefinedTerm :glossContextEngineering ,
                          :glossWorkingMemory ,
                          :glossEpisodicMemory ,
                          :glossSemanticMemory ,
                          :glossProceduralMemory ,
                          :glossLostInMiddle ,
                          :glossSparseIndex ,
                          :glossBehavioralContract ,
                          :glossSessionStartHook ,
                          :glossRdfAgentMemory .

# ── FAQ Container ─────────────────────────────────────────────────────────────

:AgentMemoryFAQ a schema:FAQPage ;
    schema:name "Frequently Asked Questions: AI Agent Memory via Context Engineering"@en ;
    schema:description "Twelve questions and answers covering LLM statelessness, context engineering concepts, memory types, the lost-in-the-middle effect, and the agent-rdf-memory implementation patterns."@en ;
    schema:mainEntity :faq1q , :faq2q , :faq3q , :faq4q , :faq5q , :faq6q ,
                      :faq7q , :faq8q , :faq9q , :faq10q , :faq11q , :faq12q .

# ── Glossary ──────────────────────────────────────────────────────────────────

:glossContextEngineering a schema:DefinedTerm ;
    schema:name "Context Engineering"@en ;
    schema:description "The discipline of strategically assembling, compressing, and injecting relevant information into a stateless LLM's context window — the actual mechanism behind 'agent memory'."@en ;
    schema:termCode "context-engineering"@en ;
    schema:inDefinedTermSet :GlossaryTermSet ;
    skos:exactMatch :ContextEngineering .

:glossWorkingMemory a schema:DefinedTerm ;
    schema:name "Working Memory"@en ;
    schema:description "The live context window for the current agent task — hot, bounded by the model's token limit, and populated by the SessionStart hook from persistent RDF files."@en ;
    schema:termCode "working-memory"@en ;
    schema:inDefinedTermSet :GlossaryTermSet ;
    skos:exactMatch :WorkingMemoryType .

:glossEpisodicMemory a schema:DefinedTerm ;
    schema:name "Episodic Memory"@en ;
    schema:description "Time-anchored records of specific past interactions — stored as dated Turtle files in sessions/ using OPAL Analytics Ontology vocabulary."@en ;
    schema:termCode "episodic-memory"@en ;
    schema:inDefinedTermSet :GlossaryTermSet ;
    skos:exactMatch :EpisodicMemoryType .

:glossSemanticMemory a schema:DefinedTerm ;
    schema:name "Semantic Memory"@en ;
    schema:description "Context-independent facts (user identity, output paths, canonical IRIs) stored in core.ttl and valid across all sessions."@en ;
    schema:termCode "semantic-memory"@en ;
    schema:inDefinedTermSet :GlossaryTermSet ;
    skos:exactMatch :SemanticMemoryType .

:glossProceduralMemory a schema:DefinedTerm ;
    schema:name "Procedural Memory"@en ;
    schema:description "Behavioral rules and learned patterns encoded as schema:HowToStep entities in preferences.ttl and companion howto/*.ttl files — 103 standing instructions governing every agent session."@en ;
    schema:termCode "procedural-memory"@en ;
    schema:inDefinedTermSet :GlossaryTermSet ;
    skos:exactMatch :ProceduralMemoryType .

:glossLostInMiddle a schema:DefinedTerm ;
    schema:name "Lost-in-the-Middle Effect"@en ;
    schema:description "Empirically observed degradation in LLM recall for information positioned centrally in long context windows — motivating the sparse-index pattern and compact session-start injection."@en ;
    schema:termCode "lost-in-the-middle"@en ;
    schema:inDefinedTermSet :GlossaryTermSet ;
    skos:exactMatch :LostInTheMiddleEffect .

:glossSparseIndex a schema:DefinedTerm ;
    schema:name "Sparse Index Pattern"@en ;
    schema:description "A two-tier memory architecture where the always-loaded index file holds only compact pointers and one-sentence rules; verbose detail lives in on-demand companion files."@en ;
    schema:termCode "sparse-index"@en ;
    schema:inDefinedTermSet :GlossaryTermSet ;
    skos:exactMatch :SparseIndexPattern .

:glossBehavioralContract a schema:DefinedTerm ;
    schema:name "Behavioral Contract"@en ;
    schema:description "A set of queryable schema:HowToStep RDF entities encoding standing agent instructions, each with a trigger condition and a pointer to a companion howto file."@en ;
    schema:termCode "behavioral-contract"@en ;
    schema:inDefinedTermSet :GlossaryTermSet ;
    skos:exactMatch :BehavioralContract .

:glossSessionStartHook a schema:DefinedTerm ;
    schema:name "SessionStart Hook"@en ;
    schema:description "A harness-level Python script that reads RDF memory files and injects them as additionalContext before the agent's first turn — enforcing context engineering structurally."@en ;
    schema:termCode "session-start-hook"@en ;
    schema:inDefinedTermSet :GlossaryTermSet ;
    skos:exactMatch :SessionStartHook .

:glossRdfAgentMemory a schema:DefinedTerm ;
    schema:name "RDF-Based Agent Memory"@en ;
    schema:description "Persistent agent memory stored as Turtle RDF — queryable via SPARQL, semantically typed, dereferenceable, and structured for the sparse-index pattern."@en ;
    schema:termCode "rdf-agent-memory"@en ;
    schema:inDefinedTermSet :GlossaryTermSet ;
    skos:exactMatch :RDFBasedAgentMemory .

# ── HowTo: Implementing Context Engineering with RDF ─────────────────────────

:howtoContextEngineering a schema:HowTo ;
    schema:name "How to Implement Agent Memory via Context Engineering and RDF"@en ;
    schema:description "A seven-step guide to designing and deploying an RDF-based context engineering system for LLM agents, following the agent-rdf-memory reference implementation."@en ;
    schema:step :howtoStep1 , :howtoStep2 , :howtoStep3 , :howtoStep4 ,
                :howtoStep5 , :howtoStep6 , :howtoStep7 .

:howtoStep1 a schema:HowToStep ;
    schema:position 1 ;
    schema:name "Classify your memory needs across the four functional types"@en ;
    schema:text "Map each piece of information the agent needs to one of the four memory types: working (immediate task context), episodic (interaction history), semantic (stable facts), or procedural (behavioral rules). This classification determines where each item is stored, how it is injected, and when it expires."@en .

:howtoStep2 a schema:HowToStep ;
    schema:position 2 ;
    schema:name "Design the storage tier mapping: which memory lives where"@en ;
    schema:text "Map memory types to tiers: procedural and semantic memory → long-term storage (always-loaded RDF files); episodic memory → session tier (dated files loaded on demand); working memory → the context window assembled at each call. Define expiry and promotion rules: when does session memory get summarised into long-term? What triggers cold archive?"@en .

:howtoStep3 a schema:HowToStep ;
    schema:position 3 ;
    schema:name "Choose RDF Turtle as the persistent storage format"@en ;
    schema:text "Encode all persistent memory as RDF Turtle with well-typed schema.org and custom ontology terms. Each rule becomes a schema:HowToStep, each session becomes an opal:ChatSession, each fact becomes a schema:PropertyValue or foaf:knows triple. Use the sparse-index pattern: compact manifests in always-loaded files, full prose in companion files."@en .

:howtoStep4 a schema:HowToStep ;
    schema:position 4 ;
    schema:name "Implement structural context injection via a harness hook"@en ;
    schema:text "Do not rely on the agent to load memory via tool calls — enforce it structurally. Configure a SessionStart hook (load_memory.py pattern) that reads the core memory files and injects their content as additionalContext before the first user turn. Add a GATE instruction reminding the agent to execute the full memory protocol even after injection."@en .

:howtoStep5 a schema:HowToStep ;
    schema:position 5 ;
    schema:name "Apply the sparse-index pattern to keep the always-loaded contract compact"@en ;
    schema:text "In the always-loaded behavioral contract file, each rule should contain: schema:name (the rule as a noun phrase), schema:text (one sentence only), onto:hasTrigger (when it fires), and rdfs:seeAlso (pointer to the howto companion). Run a verification script regularly to catch schema:text values exceeding 300 characters — a signal that prose has leaked from the howto file into the index."@en .

:howtoStep6 a schema:HowToStep ;
    schema:position 6 ;
    schema:name "Add a post-session validation gate to audit protocol compliance"@en ;
    schema:text "Implement a transcript audit script (validate-memory-protocol.py pattern) that verifies all mandatory memory-loading steps were executed before the agent's first response. Use it in CI or as a post-session check. Let its failure reports drive iterative improvement of the hook injection — this closes the prevention-audit feedback loop."@en .

:howtoStep7 a schema:HowToStep ;
    schema:position 7 ;
    schema:name "Make memory queryable: enable SPARQL retrieval across the local RDF store"@en ;
    schema:text "The full benefit of RDF memory emerges when it is queryable. Point a local SPARQL engine (or Virtuoso) at the memory directory and build query patterns for: 'what are all rules triggered by artifact generation?', 'which sessions generated output to this path?', 'what was the most recent correction about entity IRIs?'. This turns episodic and procedural memory into a live knowledge graph, not just a log."@en .

# ── SPARQL Queries ────────────────────────────────────────────────────────────

:sparqlQ1 a schema:CreativeWork ;
    schema:name "List all memory types and their storage tiers"@en ;
    schema:encodingFormat "application/sparql-query"@en ;
    schema:text """PREFIX : <https://linkeddata.uriburner.com/DAV/demos/daas/ai-agent-memory-context-engineering-claude_sonnet_4_6-1.ttl#>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?memoryType ?description ?storedIn
FROM <https://linkeddata.uriburner.com/DAV/demos/daas/ai-agent-memory-context-engineering-claude_sonnet_4_6-1.ttl>
WHERE {
  ?m a :MemoryType ;
     schema:name ?memoryType ;
     schema:description ?description .
  OPTIONAL { ?m :storesIn ?tier . ?tier schema:name ?storedIn . }
}
ORDER BY ?memoryType"""@en .

:sparqlQ2 a schema:CreativeWork ;
    schema:name "Retrieve all HowTo steps for implementing context engineering"@en ;
    schema:encodingFormat "application/sparql-query"@en ;
    schema:text """PREFIX : <https://linkeddata.uriburner.com/DAV/demos/daas/ai-agent-memory-context-engineering-claude_sonnet_4_6-1.ttl#>
PREFIX schema: <http://schema.org/>

SELECT ?position ?stepName ?stepText
FROM <https://linkeddata.uriburner.com/DAV/demos/daas/ai-agent-memory-context-engineering-claude_sonnet_4_6-1.ttl>
WHERE {
  :howtoContextEngineering schema:step ?step .
  ?step schema:position ?position ;
        schema:name ?stepName ;
        schema:text ?stepText .
}
ORDER BY xsd:integer(?position)"""@en .

:sparqlQ3 a schema:CreativeWork ;
    schema:name "Find all concepts that address LLM Statelessness"@en ;
    schema:encodingFormat "application/sparql-query"@en ;
    schema:text """PREFIX : <https://linkeddata.uriburner.com/DAV/demos/daas/ai-agent-memory-context-engineering-claude_sonnet_4_6-1.ttl#>
PREFIX schema: <http://schema.org/>

SELECT ?concept ?description
FROM <https://linkeddata.uriburner.com/DAV/demos/daas/ai-agent-memory-context-engineering-claude_sonnet_4_6-1.ttl>
WHERE {
  ?concept :addressesChallenge :LLMStatelessness ;
           schema:name ?name ;
           schema:description ?description .
  BIND(str(?name) AS ?concept)
}"""@en .

:sparqlQ4 a schema:CreativeWork ;
    schema:name "Retrieve FAQ pairs about memory retrieval and protocol compliance"@en ;
    schema:encodingFormat "application/sparql-query"@en ;
    schema:text """PREFIX : <https://linkeddata.uriburner.com/DAV/demos/daas/ai-agent-memory-context-engineering-claude_sonnet_4_6-1.ttl#>
PREFIX schema: <http://schema.org/>

SELECT ?question ?answer
FROM <https://linkeddata.uriburner.com/DAV/demos/daas/ai-agent-memory-context-engineering-claude_sonnet_4_6-1.ttl>
WHERE {
  ?q a schema:Question ;
     schema:name ?question ;
     schema:acceptedAnswer ?ans .
  ?ans schema:text ?answer .
}
ORDER BY ?question"""@en .
