Skip to content

dependency

diapason.skills.dependency

Dependency graph: cycle detection, topological sort, capability union.

DependencyCycleError

Bases: Exception

Raised when a cycle is detected in the skill dependency graph.

DepthExceededError

Bases: Exception

Raised when the dependency depth exceeds the configured maximum.

build_dependency_graph(skills)

Build a directed graph of skill dependencies.

Each key maps to the set of skill names it directly depends on, drawn from both the depends field and any skill_name references in steps. Only edges pointing to skills that are present in the skills dict are included (unknown refs are silently dropped so that the graph stays clean for topological analysis).

Parameters:

Name Type Description Default
skills Dict[str, 'SkillManifest']

Mapping of skill name → SkillManifest.

required

Returns:

Type Description
Dict[str, Set[str]]

Dict mapping each skill name to the set of its direct dependencies.

compute_capability_union(skill_name, skills)

Compute the union of all required_capabilities transitively needed by a skill.

Performs a DFS over the dependency graph, collecting required_capabilities from the skill itself and all of its transitive dependencies. Duplicates are removed while preserving a deterministic order (first-seen wins).

Parameters:

Name Type Description Default
skill_name str

Name of the root skill to start from.

required
skills Dict[str, 'SkillManifest']

Mapping of skill name → SkillManifest.

required

Returns:

Type Description
List[str]

Deduplicated list of capability strings. Returns an empty list if the

List[str]

skill is not found.

validate_dependencies(skills, *, max_depth=5)

Validate the skill dependency graph and return a topological ordering.

Uses Kahn's algorithm for topological sort and cycle detection. After a valid ordering is found, a DFS checks that no skill's transitive dependency chain exceeds max_depth. Dependencies that reference unknown skills are silently skipped.

Parameters:

Name Type Description Default
skills Dict[str, 'SkillManifest']

Mapping of skill name → SkillManifest.

required
max_depth int

Maximum allowed dependency chain depth (default 5).

5

Returns:

Type Description
List[str]

List of skill names in valid topological order (dependencies first).

Raises:

Type Description
DependencyCycleError

If the graph contains a cycle.

DepthExceededError

If any skill's dependency chain depth exceeds max_depth.