
# Dependencies & Ordering

Source nodes can depend on other source nodes. The resolver uses these dependencies to determine **hydration order** — ensuring upstream data is available before downstream sources execute.

## Declaring dependencies

Use `depends_on` in the source frontmatter:

```yaml
source:
  transport: mcp
  server: jira
  tools: [jira_get_sprint_issues]
  depends_on:
    - contextnest://sources/project-config
```

## Topological ordering

The resolver sorts source nodes in topological order based on their dependency graph:

```
project-config → current-sprint-tickets → sprint-risk-analysis
```

At each step, the agent has the upstream results available in its session context when it reads the downstream source's instructions.

## Cycle detection

Circular dependencies are forbidden. If the dependency graph contains a cycle, validation fails with a Rule 15 error:

```
Circular dependency detected: A → B → C → A
```

## Body-level references

Dependencies can also be expressed in the markdown body:

```markdown
Before fetching sprint tickets, ensure you have the project
configuration from [Project Config](contextnest://sources/project-config).
```

Both the frontmatter `depends_on` and body references should point to the same targets. If they diverge, validation flags the inconsistency.
