Skip to content
SemDAG

SemDAG

SemDAG is the Semantic Directed Acyclic Graph that connects Modules by dependency.

Prerequisites for an invitation ModuleAccount depends on Identity. Membership depends on Account and Identity. Invitations depends on Account and Membership. Arrows point toward prerequisites.IdentityAccountMembershipInvitations

Arrows point to prerequisites. Choose a target Module to see its reading order.

Reading order for Invitations: Identity → Account → Membership → Invitations. Each Module appears once.
Works with
ChatGPT
Claude
Claude Code
Codex
Cursor
GitHub Copilot

Origins and design rationale

SemDAG grew out of Socra’s work with coding agents. As agents produced more code, reviewing their changes became a bottleneck. They lacked the specific knowledge behind the system: the architectural decisions and the reasons for making them. Mike Morton described the underlying problem: “A lot of that organizational know-how was locked in my head.”

Context has dependencies

Repository instructions helped with the subject each file described. That subject often required other things to be understood first, and those things had their own prerequisites. The agent could learn a rule without understanding the context needed to apply it. As more repositories and agents used the instructions, someone still had to explain how the subjects connected.

Apply modularity to knowledge

After experimenting with several prototypes, Socra applied the structure of software dependencies to context. A library depends on packages that must be available for it to work. Knowledge can follow the same structure. As Morton explains: “So you can break the knowledge into little discrete pieces and connect them together, just like you would modularize code.”

Each Module owns one subject and declares the Modules needed to understand it. Dependencies must be acyclic so that prerequisites can be read before the subjects that depend on them.

Assemble the prerequisites before work begins

To assemble context for a target Module, follow its dependencies recursively. Collect the required Modules, remove duplicates, and sort them so that prerequisites come first. The result is a single bundle that can be loaded into the agent’s context window before it starts the task. Cortex implements this operation as a flash.

Based on Mike Morton’s SemDAG: A Dependency Graph for Knowledge and Agent Context Needs an Import Statement.

Markdown and knowledge dependencies

Markdown provides a format for recording knowledge. A file can describe a design decision and link to related explanations. Those links still need a rule for determining which explanations are required, how to follow their prerequisites, and when to load them.

SemDAG records those relationships as dependencies. Each Module owns a subject and declares the other Modules needed to understand it. Requesting a Module collects its declared prerequisites, including those reached through other Modules.

The content can remain Markdown. The architectural change is the explicit graph and the process that assembles it. A system built around files can use the same approach by adding dependency declarations, cycle detection, and ordered assembly.

SemDAG compared with AGENTS.md and CLAUDE.md

For knowledge shared across tasks and projects, SemDAG provides a smaller unit of reuse than a broad instruction file. An agent can request the Module for its task and receive that subject with its prerequisites. Knowledge outside that dependency graph stays out of the bundle.

Reduce unrelated input tokens

When a whole instruction file is included in a request, every included section consumes context space. An invitation task may need membership rules while the same file also contains deployment procedures. Loading both introduces material that does not help explain the task.

With focused Modules, the invitation task loads its declared dependencies. A separate deployment Module is included only if the selected graph requires it. Deduplication also prevents a shared prerequisite from appearing more than once in the assembled bundle.

This can reduce input-token usage compared with loading a broad file. The saving depends on the selected Module and the size of its dependency graph. Caching and model pricing affect the resulting cost. The graph itself does not establish a measured saving.

Maintain shared instructions once

A decision copied into several repository files must be kept current in each copy. In Cortex, the decision can live in one Module. Agents that flash dependent Modules receive its current content on their next flash. Repository instructions can then direct agents to the relevant knowledge without containing a separate copy of every shared rule.

Modularity and composition

A Module owns one subject, including the decisions and reasons needed to understand it. Dependencies connect that subject to its prerequisites. This separates responsibility for maintaining knowledge from the places where it is used.

Consider an illustrative design Module that depends on accessibility principles. Several product Modules can depend on that design Module while maintaining their own product requirements. Each product receives the shared design knowledge and its prerequisites when its context is assembled.

Changing the shared subject does not require editing its dependents to repeat the new text. Its updated content is included on the next flash. This reuse depends on clear ownership: if two Modules contain copies of the same rule, graph deduplication cannot reconcile them. The rule needs one owning Module.

Shared knowledge across teams

Repository instructions are maintained within a development project. The decisions they need can originate elsewhere, including design and product work. When those decisions remain in separate documents, someone must carry them into the instructions that agents read.

For example, a designer may define a rule that every form field has a visible label. If engineering agents receive no record of that rule, they cannot reliably apply the team’s decision. Copying it into each repository creates several places to maintain as the design system changes.

In Cortex, the rule and its reason can belong to a shared design Module. Product Modules declare a dependency on that knowledge. Their next flash includes the approved rule, so a decision maintained by one team can guide agents working on another team’s implementation.

This makes the knowledge available across projects and tools. Owners must still review changes, and agents must request the relevant context. Updating a Module does not change the context already loaded in an existing conversation.

Prerequisites and reading order

A subject can use terms whose meaning depends on earlier knowledge. Mike Morton illustrates this with calculus, which requires algebra, which in turn requires arithmetic. Teaching the prerequisites first establishes the concepts used by the later subject.

The same relationship applies to an organization’s specific knowledge. A membership rule may refer to an Account boundary that differs from an agent’s general understanding of an account. Loading the organization’s definition first gives the rule its intended context.

SemDAG expresses that requirement as a directed dependency. If Membership depends on Account, Account must appear first in the assembled bundle. Independent Modules may have more than one valid relative order, provided every declared prerequisite precedes its dependent.

Graph structure

A SemDAG represents knowledge as Modules connected by directed edges. An edge from one Module to another means the first requires the second to be understood.

The graph is semantic because its relationships describe prerequisites for understanding a subject. It is directed because that requirement has a direction. Several Modules can depend on the same foundation, and one Module can require several prerequisites.

The graph must be acyclic. If A requires B and B leads back to A, neither can be placed before all of its prerequisites. Rejecting cycles preserves a valid order for assembling the knowledge.

Context assembly

Assembly begins with the Module selected for the task. Follow each dependency recursively until every reachable prerequisite has been collected. This set is the target’s dependency closure.

Include each Module once, then place the Modules in topological order. Every prerequisite appears before the subject that depends on it. A shared foundation remains a single entry even when several paths reach it.

Cortex calls the operation a flash. The returned bundle can be loaded into an agent’s context before it begins work. The declared graph determines which knowledge is included; an omitted dependency will not be supplied by this traversal.

Worked example: invitation rules

Consider a fictional project with four Modules. Identity defines a stable person identifier. Account depends on Identity and defines an organization boundary. Membership depends on Account and Identity and describes who belongs to an organization. Invitations depends on Account and Membership and defines how a person joins.

A flash of Invitations collects all four Modules. Their prerequisite order is Identity, Account, Membership, then Invitations. Identity is reached through several paths but appears once in the bundle.

A separate Billing Module would remain outside this bundle unless one of the collected Modules declared it as a dependency. The example shows how explicit relationships determine both inclusion and reading order. It illustrates the algorithm without claiming a measured effect on agent performance.

The assembly walkthrough provides the graph and an example implementation with cycle detection.

Cortex implementation

Cortex is Socra’s implementation of SemDAG. People maintain Modules and their dependencies. Agents request a Module and receive its assembled knowledge through a flash.

This allows the same maintained subject to support work across repositories and agent sessions. When an owner changes a foundational Module, later flashes that depend on it include the updated content. Agents still need to inspect the implementation and verify that their work follows the supplied requirements.

The Cortex documentation describes how to use the product. Mike Morton’s Agent Context Needs an Import Statement explains the architecture and its relation to software modularity.

Scope and limitations

Knowledge quality

A valid dependency graph establishes an order for the declared knowledge. It cannot prove that the content is accurate or that every necessary dependency has been declared. Owners need to maintain the Modules, and agents must verify their work against current evidence.

Context size

Deduplication removes repeated occurrences of the same Module. A large dependency closure can still exceed a model’s context budget. Focused subjects and necessary dependencies determine whether the assembled bundle remains useful for the task.

Relationship to retrieval

Search can help an agent identify a starting Module. Dependency traversal then follows the explicit relationships from that target. The completeness of the result depends on what the graph declares.

Name disambiguation

Socra’s SemDAG describes a Semantic Directed Acyclic Graph for agent context. The separately developed SEMdag method in SEMgraph, published by Mario Grassi and Barbara Tarantino in 2025, learns directed acyclic graphs for structural equation models.

Apply SemDAG to your project

Define a Module for a subject your agents need to understand. Record the decisions and their reasons, declare the prerequisites, and inspect the assembled context before using it for a task.