Modularity and Reusability

Lesson 4 · Agentic Skills Best Practices · ~10 minutes

By the end of this lesson, you'll design skills as composable building blocks — using shared libraries, dependency injection, and include directives to eliminate duplication across your skill portfolio.

Win

After this lesson, you'll be able to extract common patterns (auth, error handling, validation) into reusable skill libraries instead of copying them between skills.

Skills as Composable Units

AutoGen demonstrated that modular agent designs reduce coding effort by 4x and manual interactions by 3–10x. The same principle applies at the skill level: skills designed for composition outperform monoliths.

Four patterns enable composition:

1. Include Directives

Share templates and utilities across skills without duplication:

# skill-a/prompts/system.md
You are an expert data analyst. Follow these guidelines:
1. Always cite data sources
2. Express uncertainty as confidence ranges
3. Recommend follow-up questions

# skill-b can include the same base prompt:
includes:
  - "../shared/prompts/analytical-base.md"
  - "../shared/error-handling.yaml"

2. Skill Libraries

Extract recurring patterns into shared modules:

# shared/auth.py — reused by 12 skills
class AuthProvider:
    def get_token(self, service: str) -> str:
        """Retrieve token from secrets manager."""
        ...

# shared/validation.py
def validate_input(schema: dict, data: dict) -> ValidationResult:
    """Validate against JSON Schema with clear error messages."""
    ...

# shared/retry.py
async def with_retry(fn, max_attempts=3, backoff_base=2):
    """Exponential backoff with jitter."""
    ...

3. Dependency Injection

Skills shouldn't hardcode which services they use. Inject them:

class SkillAgent:
    def __init__(self, skill_config):
        self.capabilities = load_capabilities(skill_config)
        self.tools = initialize_tools(skill_config.tools)

    def execute(self, task):
        # Modular execution with clear interfaces
        return self.capabilities.process(task, self.tools)

The skill doesn't know which file reader or statistics engine it gets — it just knows the interface. This makes testing trivial (inject mocks) and deployment flexible (swap implementations per environment).

4. Composition Patterns

Skills should work independently but integrate seamlessly:

┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ extract │────▶│ transform │────▶│ report │ │ skill │ │ skill │ │ skill │ └─────────────┘ └─────────────┘ └─────────────┘ │ │ │ └────────────────────┴────────────────────┘ shared/validation shared/error-handling shared/auth

The Enterprise Registry

The governance guide describes agent registries that "support discovery, reuse, and governance while preventing unnecessary duplication." When your skills are modular:

Key Insight

The governance guide recommends "libraries of tested and compliant agent templates, tool integrations, and prompt patterns as building blocks." This is exactly the skill library pattern — pre-approved components that citizen developers compose from.

When NOT to Extract

Don't abstract prematurely. Extract a shared module when:

One copy is fine. Two copies is a coincidence. Three copies is a pattern worth extracting.

Verify Your Understanding

You have auth token retrieval duplicated in 4 skills. What's the right approach?

You notice two skills both parse dates. One parses ISO-8601, the other natural language. Extract or keep separate?

Apply It

Scan your ~/.kiro/skills/ directory. Look for duplicated patterns — error handling, auth, validation, output formatting. If you find 3+ occurrences, extract it into a shared utility and use include directives.

Primary Source

Read the AutoGen paper (Wu et al., 2023) — Section 3 on "Customizable and Conversable Agents" demonstrates how modular, composable agent designs deliver the 4x effort reduction.

🤖 Ask your teacher: Not sure what qualifies as a reusable pattern vs. a coincidental similarity? Show me the duplicated code and I'll help you decide.