Circular safe tool registry loading

From ychampion/cskill-agents · View interactive version

Circular safe tool registry loading is an AI agent skill from the GitHub repository ychampion/cskill-agents. Safely assemble the tool registry when optional tools have circular dependencies or heavy side effects.

How to use this skill

Skill file

SKILL: Circular-Safe Tool Registry Loading

Domain: Tool Orchestration

Trigger: Use when optional tools depend on the main registry or on each other, and eager imports would create cycles or unnecessary startup work.

Source Pattern: Distilled from reviewed tool execution, streaming, persistence, and output-budget implementations.

Core Method

Keep registry assembly as a simple ordered list, but place any cyclic or expensive tool behind a tiny lazy loader. That loader imports and constructs the tool only when the registry is being composed and the relevant feature is enabled. The loader returns either one tool or nothing, and the registry flattens those results in a stable order. This breaks circular dependency chains, keeps disabled features cold, and preserves one authoritative registry surface.

Key Rules

Example Application

If a collaborative workspace tool depends on the same registry module that is trying to list it, move that tool behind a lazy loader and call the loader only when the collaboration feature is enabled. The registry still exposes the full surface, but startup no longer hits a circular import.

Anti-Patterns (What NOT to do)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.