As AI systems evolve from simple question-answering to autonomous task execution, understanding **agents** and **skills** becomes essential. This chapter explores how prompts serve as the fundamental building blocks for AI agents, and how skills package expertise into reusable, comprehensive instruction sets.

<div className="my-8 p-6 bg-muted/20 rounded-xl border">
  <div className="flex flex-col items-center gap-6">
    <div className="text-center">
      <div className="inline-flex items-center justify-center w-20 h-20 rounded-full bg-blue-100 dark:bg-blue-900/50 border-2 border-blue-300 dark:border-blue-700">
        <IconSettings className="w-10 h-10 text-blue-600 dark:text-blue-400" />
      </div>
      <p className="font-semibold mt-2 m-0!">Agent</p>
      <p className="text-xs text-muted-foreground m-0!">Autonomous AI system</p>
    </div>
    <div className="flex items-center gap-2 text-muted-foreground text-sm">
      <span>powered by</span>
      <span>↓</span>
    </div>
    <div className="flex flex-wrap justify-center gap-4">
      <div className="text-center">
        <div className="inline-flex items-center justify-center w-16 h-16 rounded-lg bg-purple-100 dark:bg-purple-900/50 border-2 border-purple-300 dark:border-purple-700">
          <IconStar className="w-8 h-8 text-purple-600 dark:text-purple-400" />
        </div>
        <p className="font-medium text-sm mt-2 m-0!">Skill</p>
        <p className="text-xs text-muted-foreground m-0!">Reusable expertise</p>
      </div>
      <div className="text-center">
        <div className="inline-flex items-center justify-center w-16 h-16 rounded-lg bg-purple-100 dark:bg-purple-900/50 border-2 border-purple-300 dark:border-purple-700">
          <IconStar className="w-8 h-8 text-purple-600 dark:text-purple-400" />
        </div>
        <p className="font-medium text-sm mt-2 m-0!">Skill</p>
        <p className="text-xs text-muted-foreground m-0!">Reusable expertise</p>
      </div>
      <div className="text-center">
        <div className="inline-flex items-center justify-center w-16 h-16 rounded-lg bg-purple-100 dark:bg-purple-900/50 border-2 border-purple-300 dark:border-purple-700">
          <IconStar className="w-8 h-8 text-purple-600 dark:text-purple-400" />
        </div>
        <p className="font-medium text-sm mt-2 m-0!">Skill</p>
        <p className="text-xs text-muted-foreground m-0!">Reusable expertise</p>
      </div>
    </div>
    <div className="flex items-center gap-2 text-muted-foreground text-sm">
      <span>composed of</span>
      <span>↓</span>
    </div>
    <div className="flex flex-wrap justify-center gap-2">
      <div className="px-3 py-2 rounded bg-amber-100 dark:bg-amber-900/50 border border-amber-300 dark:border-amber-700 flex items-center gap-1">
        <IconClipboard className="w-3 h-3 text-amber-600 dark:text-amber-400" />
        <span className="text-xs font-medium">Prompt</span>
      </div>
      <div className="px-3 py-2 rounded bg-amber-100 dark:bg-amber-900/50 border border-amber-300 dark:border-amber-700 flex items-center gap-1">
        <IconClipboard className="w-3 h-3 text-amber-600 dark:text-amber-400" />
        <span className="text-xs font-medium">Prompt</span>
      </div>
      <div className="px-3 py-2 rounded bg-amber-100 dark:bg-amber-900/50 border border-amber-300 dark:border-amber-700 flex items-center gap-1">
        <IconClipboard className="w-3 h-3 text-amber-600 dark:text-amber-400" />
        <span className="text-xs font-medium">Prompt</span>
      </div>
      <div className="px-3 py-2 rounded bg-amber-100 dark:bg-amber-900/50 border border-amber-300 dark:border-amber-700 flex items-center gap-1">
        <IconClipboard className="w-3 h-3 text-amber-600 dark:text-amber-400" />
        <span className="text-xs font-medium">Prompt</span>
      </div>
      <div className="px-3 py-2 rounded bg-amber-100 dark:bg-amber-900/50 border border-amber-300 dark:border-amber-700 flex items-center gap-1">
        <IconClipboard className="w-3 h-3 text-amber-600 dark:text-amber-400" />
        <span className="text-xs font-medium">Prompt</span>
      </div>
    </div>
    <p className="text-xs text-muted-foreground text-center m-0! mt-2">Prompts are atoms → Skills are molecules → Agents are complete structures</p>
  </div>
</div>

## What Are AI Agents?

An **AI agent** is an AI system that can autonomously plan, execute, and iterate on tasks. Unlike simple prompt-response interactions, agents can:

- **Plan** - Break down complex goals into actionable steps
- **Execute** - Use tools and take actions in the real world
- **Observe** - Process feedback from their actions
- **Adapt** - Adjust their approach based on results
- **Persist** - Maintain context and memory across interactions

<div className="my-6 flex items-center justify-center p-6 bg-muted/30 rounded-lg">
  <div className="relative">
    <div className="flex items-center gap-3">
      <div className="px-4 py-3 bg-blue-100 dark:bg-blue-900/50 border border-blue-200 dark:border-blue-800 rounded-lg text-center text-sm">
        <p className="font-medium text-blue-700 dark:text-blue-300 m-0!">Goal</p>
      </div>
      <div className="text-muted-foreground">→</div>
      <div className="flex flex-col items-center gap-2">
        <div className="flex items-center gap-2 px-4 py-3 bg-muted/50 border border-dashed rounded-lg">
          <div className="px-3 py-2 bg-purple-100 dark:bg-purple-900/50 border border-purple-200 dark:border-purple-800 rounded text-center text-sm">
            <p className="font-medium text-purple-700 dark:text-purple-300 m-0!">Plan</p>
          </div>
          <div className="text-muted-foreground">→</div>
          <div className="px-3 py-2 bg-amber-100 dark:bg-amber-900/50 border border-amber-200 dark:border-amber-800 rounded text-center text-sm">
            <p className="font-medium text-amber-700 dark:text-amber-300 m-0!">Execute</p>
          </div>
          <div className="text-muted-foreground">→</div>
          <div className="px-3 py-2 bg-teal-100 dark:bg-teal-900/50 border border-teal-200 dark:border-teal-800 rounded text-center text-sm">
            <p className="font-medium text-teal-700 dark:text-teal-300 m-0!">Observe</p>
          </div>
          <div className="text-muted-foreground">→</div>
          <div className="px-3 py-2 bg-rose-100 dark:bg-rose-900/50 border border-rose-200 dark:border-rose-800 rounded text-center text-sm">
            <p className="font-medium text-rose-700 dark:text-rose-300 m-0!">Adapt</p>
          </div>
        </div>
        <div className="text-xs text-muted-foreground flex items-center gap-1">
          <span>↺</span> Loop until complete
        </div>
      </div>
      <div className="text-muted-foreground">→</div>
      <div className="px-4 py-3 bg-green-100 dark:bg-green-900/50 border border-green-200 dark:border-green-800 rounded-lg text-center text-sm">
        <p className="font-medium text-green-700 dark:text-green-300 m-0!">Done</p>
      </div>
    </div>
  </div>
</div>

## Prompts as Building Blocks

Every agent, no matter how sophisticated, is built from prompts. Just as atoms combine to form molecules, and molecules combine to form complex structures, prompts combine to create intelligent agent behavior.

<div className="my-6 grid md:grid-cols-4 gap-3 text-center text-sm">
  <div className="border rounded-lg p-4 bg-blue-50/50 dark:bg-blue-950/20 border-blue-200 dark:border-blue-900">
    <p className="font-semibold text-blue-700 dark:text-blue-300 m-0!">System Prompts</p>
    <p className="text-xs text-blue-600 dark:text-blue-400 m-0! mt-1">Identity & Role</p>
  </div>
  <div className="border rounded-lg p-4 bg-purple-50/50 dark:bg-purple-950/20 border-purple-200 dark:border-purple-900">
    <p className="font-semibold text-purple-700 dark:text-purple-300 m-0!">Planning Prompts</p>
    <p className="text-xs text-purple-600 dark:text-purple-400 m-0! mt-1">How to Think</p>
  </div>
  <div className="border rounded-lg p-4 bg-amber-50/50 dark:bg-amber-950/20 border-amber-200 dark:border-amber-900">
    <p className="font-semibold text-amber-700 dark:text-amber-300 m-0!">Tool Prompts</p>
    <p className="text-xs text-amber-600 dark:text-amber-400 m-0! mt-1">How to Act</p>
  </div>
  <div className="border rounded-lg p-4 bg-rose-50/50 dark:bg-rose-950/20 border-rose-200 dark:border-rose-900">
    <p className="font-semibold text-rose-700 dark:text-rose-300 m-0!">Recovery Prompts</p>
    <p className="text-xs text-rose-600 dark:text-rose-400 m-0! mt-1">How to Recover</p>
  </div>
</div>

These prompt types stack together to form complete agent behavior:

### System Prompts (The Agent's Identity)

The foundational prompt that establishes who the agent is and how it behaves:

```markdown
You are a code review assistant. Your role is to:
- Analyze code for bugs, security issues, and performance problems
- Suggest improvements following best practices
- Explain your reasoning clearly
- Be constructive and educational in feedback

You have access to tools for reading files, searching code, and running tests.
```

### Planning Prompts (How to Think)

Instructions that guide the agent's reasoning and planning process:

```markdown
Before taking action, always:
1. Understand the complete request
2. Break it into smaller, verifiable steps
3. Identify which tools you'll need
4. Consider edge cases and potential issues
5. Execute step by step, validating as you go
```

### Tool-Use Prompts (How to Act)

Guidance on when and how to use available tools:

```markdown
When you need to understand a codebase:
- Use grep_search for finding specific patterns
- Use read_file to examine file contents
- Use list_dir to explore directory structure
- Always verify your understanding before making changes
```

### Recovery Prompts (How to Handle Failure)

Instructions for when things go wrong:

```markdown
If an action fails:
1. Analyze the error message carefully
2. Consider alternative approaches
3. Ask for clarification if the task is ambiguous
4. Never repeat the same failed action without changes
```

<Callout type="info" title="The Prompt Stack">
An agent's behavior emerges from layers of prompts working together. The system prompt sets the foundation, planning prompts guide reasoning, tool prompts enable action, and recovery prompts handle failures. Together, they create coherent, capable behavior.
</Callout>

## What Are Skills?

If prompts are the atoms, **skills are the molecules**—reusable building blocks that give agents specific capabilities.

A **skill** is a comprehensive, portable package of instructions that gives an AI agent expertise in a specific domain or task. Skills are the reusable blocks of agents: you build them once, and any agent can use them.

<Callout type="tip" title="Skills = Reusable Agent Blocks">
Write a skill for code review once. Now every coding agent—whether it's for Python, JavaScript, or Rust—can instantly become an expert code reviewer by loading that skill. Skills let you build agent capabilities like LEGO blocks.
</Callout>

### Anatomy of a Skill

A well-designed skill typically includes:

<div className="my-6 grid md:grid-cols-2 gap-4">
  <div className="border rounded-lg p-4 bg-muted/30">
    <p className="font-semibold text-sm m-0! mb-2">📄 SKILL.md (Required)</p>
    <p className="text-sm text-muted-foreground m-0!">The main instruction file. Contains the core expertise, guidelines, and behaviors that define the skill.</p>
  </div>
  <div className="border rounded-lg p-4 bg-muted/30">
    <p className="font-semibold text-sm m-0! mb-2">📚 Reference Docs</p>
    <p className="text-sm text-muted-foreground m-0!">Supporting documentation, examples, and context the agent can reference while working.</p>
  </div>
  <div className="border rounded-lg p-4 bg-muted/30">
    <p className="font-semibold text-sm m-0! mb-2">🔧 Scripts & Tools</p>
    <p className="text-sm text-muted-foreground m-0!">Helper scripts, templates, or tool configurations that support the skill's functionality.</p>
  </div>
  <div className="border rounded-lg p-4 bg-muted/30">
    <p className="font-semibold text-sm m-0! mb-2">⚙️ Configuration</p>
    <p className="text-sm text-muted-foreground m-0!">Settings, parameters, and customization options for adapting the skill to different contexts.</p>
  </div>
</div>

### Example: Code Review Skill

Here's what a code review skill might look like:

<div className="my-6 border rounded-lg overflow-hidden bg-muted/20">
  <div className="px-3 py-2 bg-muted/50 border-b flex items-center gap-2">
    <span className="text-sm">📁</span>
    <span className="text-sm font-medium">code-review-skill/</span>
  </div>
  <div className="p-3 space-y-1 text-sm font-mono">
    <div className="flex items-center gap-2 px-2 py-1 rounded hover:bg-muted/50">
      <span>📄</span>
      <span className="font-medium">SKILL.md</span>
      <span className="text-muted-foreground text-xs ml-auto">Core review guidelines</span>
    </div>
    <div className="flex items-center gap-2 px-2 py-1 rounded hover:bg-muted/50">
      <span>📄</span>
      <span>security-checklist.md</span>
      <span className="text-muted-foreground text-xs ml-auto">Security patterns</span>
    </div>
    <div className="flex items-center gap-2 px-2 py-1 rounded hover:bg-muted/50">
      <span>📄</span>
      <span>performance-tips.md</span>
      <span className="text-muted-foreground text-xs ml-auto">Optimization guide</span>
    </div>
    <div className="mt-2 border-t pt-2">
      <div className="flex items-center gap-2 px-2 py-1">
        <span>📁</span>
        <span className="font-medium">language-specific/</span>
      </div>
      <div className="ml-6 space-y-1">
        <div className="flex items-center gap-2 px-2 py-1 rounded hover:bg-muted/50">
          <span>📄</span>
          <span>python.md</span>
          <span className="text-muted-foreground text-xs ml-auto">Python best practices</span>
        </div>
        <div className="flex items-center gap-2 px-2 py-1 rounded hover:bg-muted/50">
          <span>📄</span>
          <span>javascript.md</span>
          <span className="text-muted-foreground text-xs ml-auto">JavaScript patterns</span>
        </div>
        <div className="flex items-center gap-2 px-2 py-1 rounded hover:bg-muted/50">
          <span>📄</span>
          <span>rust.md</span>
          <span className="text-muted-foreground text-xs ml-auto">Rust guidelines</span>
        </div>
      </div>
    </div>
  </div>
</div>

The `SKILL.md` file defines the overall approach:

```markdown
---
name: code-review
description: Comprehensive code review with security, performance, and style analysis
---

# Code Review Skill

You are an expert code reviewer. When reviewing code:

## Process
1. **Understand Context** - What does this code do? What problem does it solve?
2. **Check Correctness** - Does it work? Are there logic errors?
3. **Security Scan** - Reference security-checklist.md for common vulnerabilities
4. **Performance Review** - Check performance-tips.md for optimization opportunities
5. **Style & Maintainability** - Is the code readable and maintainable?

## Output Format
Provide feedback in categories:
- 🔴 **Critical** - Must fix before merge
- 🟡 **Suggested** - Recommended improvements
- 🟢 **Nice to have** - Optional enhancements

Always explain *why* something is an issue, not just *what* is wrong.
```

## Skills vs. Simple Prompts

<div className="my-6 grid md:grid-cols-2 gap-4">
  <div className="border rounded-lg bg-muted/30">
    <p className="text-sm font-semibold px-4 pt-3 m-0!">Simple Prompt</p>
    <div className="text-sm p-4 pt-2 space-y-2">
      <p className="m-0!">Single instruction</p>
      <p className="m-0!">One-off use</p>
      <p className="m-0!">Limited context</p>
      <p className="m-0!">Generic approach</p>
      <p className="m-0!">No supporting materials</p>
    </div>
  </div>
  <div className="border rounded-lg bg-primary/5 border-primary/20">
    <p className="text-sm font-semibold px-4 pt-3 m-0!">Skill</p>
    <div className="text-sm p-4 pt-2 space-y-2">
      <p className="m-0!">Comprehensive instruction set</p>
      <p className="m-0!">Reusable across projects</p>
      <p className="m-0!">Rich context with references</p>
      <p className="m-0!">Domain-specific expertise</p>
      <p className="m-0!">Supporting docs, scripts, configs</p>
    </div>
  </div>
</div>

## Building Effective Skills

### 1. Define the Expertise Clearly

Start with a clear description of what the skill enables:

```markdown
---
name: api-design
description: Design RESTful APIs following industry best practices, 
  including versioning, error handling, and documentation standards
---
```

### 2. Structure Knowledge Hierarchically

Organize information from general to specific:

```markdown
# API Design Skill

## Core Principles
- Resources should be nouns, not verbs
- Use HTTP methods semantically
- Version your APIs from day one

## Detailed Guidelines
[More specific rules...]

## Reference Materials
- See `rest-conventions.md` for naming conventions
- See `error-codes.md` for standard error responses
```

### 3. Include Concrete Examples

Abstract rules become clear with examples:

```markdown
## Endpoint Naming

✅ Good:
- GET /users/{id}
- POST /orders
- DELETE /products/{id}/reviews/{reviewId}

❌ Avoid:
- GET /getUser
- POST /createNewOrder
- DELETE /removeProductReview
```

### 4. Provide Decision Frameworks

Help the agent make choices in ambiguous situations:

```markdown
## When to Use Pagination

Use pagination when:
- Collection could exceed 100 items
- Response size impacts performance
- Client may not need all items

Use full response when:
- Collection is always small (<20 items)
- Client typically needs everything
- Real-time consistency is critical
```

### 5. Add Recovery Patterns

Anticipate what can go wrong:

```markdown
## Common Issues

**Problem**: Client needs fields not in standard response
**Solution**: Implement field selection: GET /users?fields=id,name,email

**Problem**: Breaking changes needed
**Solution**: Create new version, deprecate old with timeline
```

## Composing Skills

Agents become powerful when multiple skills work together. Consider how skills can complement each other:

<div className="my-6 flex flex-wrap items-center justify-center gap-4 p-6 bg-muted/30 rounded-lg">
  <div className="px-4 py-2 bg-blue-100 dark:bg-blue-900/50 border border-blue-200 dark:border-blue-800 rounded-lg text-sm font-medium text-blue-700 dark:text-blue-300">
    Code Review
  </div>
  <div className="text-xl">+</div>
  <div className="px-4 py-2 bg-purple-100 dark:bg-purple-900/50 border border-purple-200 dark:border-purple-800 rounded-lg text-sm font-medium text-purple-700 dark:text-purple-300">
    Security Audit
  </div>
  <div className="text-xl">+</div>
  <div className="px-4 py-2 bg-green-100 dark:bg-green-900/50 border border-green-200 dark:border-green-800 rounded-lg text-sm font-medium text-green-700 dark:text-green-300">
    Documentation
  </div>
  <div className="text-xl">=</div>
  <div className="px-4 py-2 bg-amber-100 dark:bg-amber-900/50 border border-amber-200 dark:border-amber-800 rounded-lg text-sm font-medium text-amber-700 dark:text-amber-300">
    Complete Code Quality Agent
  </div>
</div>

When composing skills, ensure they don't conflict. Skills should be:

- **Modular** - Each skill handles one domain well
- **Compatible** - Skills shouldn't give contradictory instructions
- **Prioritized** - When skills overlap, define which takes precedence

## Sharing and Discovering Skills

Skills are most valuable when shared. Platforms like [prompts.chat](https://prompts.chat/skills) allow you to:

- **Discover** community-created skills for common tasks
- **Download** skills directly to your projects
- **Share** your own expertise as reusable skills
- **Iterate** on skills based on real-world usage

<Callout type="tip" title="Start with Community Skills">
Before building a skill from scratch, check if someone has already solved your problem. Community skills are battle-tested and often better than starting from zero.
</Callout>

## The Agent-Skill Ecosystem

The relationship between agents and skills creates a powerful ecosystem:

<div className="my-6 p-6 bg-muted/30 rounded-lg border">
  <div className="text-center mb-4">
    <span className="text-sm font-semibold text-muted-foreground">AI Agent</span>
  </div>
  <div className="flex flex-wrap justify-center gap-3 mb-4">
    <div className="px-4 py-3 bg-blue-100 dark:bg-blue-900/50 border border-blue-200 dark:border-blue-800 rounded-lg text-center">
      <p className="font-medium text-blue-700 dark:text-blue-300 text-sm m-0!">Code Review</p>
      <p className="text-xs text-blue-600 dark:text-blue-400 m-0!">Skill 1</p>
    </div>
    <div className="px-4 py-3 bg-purple-100 dark:bg-purple-900/50 border border-purple-200 dark:border-purple-800 rounded-lg text-center">
      <p className="font-medium text-purple-700 dark:text-purple-300 text-sm m-0!">API Design</p>
      <p className="text-xs text-purple-600 dark:text-purple-400 m-0!">Skill 2</p>
    </div>
    <div className="px-4 py-3 bg-teal-100 dark:bg-teal-900/50 border border-teal-200 dark:border-teal-800 rounded-lg text-center">
      <p className="font-medium text-teal-700 dark:text-teal-300 text-sm m-0!">Test Writing</p>
      <p className="text-xs text-teal-600 dark:text-teal-400 m-0!">Skill 3</p>
    </div>
  </div>
  <div className="flex justify-center mb-3">
    <div className="text-muted-foreground">↓</div>
  </div>
  <div className="flex justify-center">
    <div className="px-6 py-4 bg-amber-100 dark:bg-amber-900/50 border border-amber-200 dark:border-amber-800 rounded-lg text-center">
      <p className="font-semibold text-amber-700 dark:text-amber-300 text-sm m-0!">Core Prompts</p>
      <p className="text-xs text-amber-600 dark:text-amber-400 m-0!">Planning • Tools • Recovery • Memory</p>
    </div>
  </div>
</div>

The agent provides the execution framework—planning, tool use, and memory—while skills provide domain expertise. This separation means:

- **Skills are portable** - The same skill works with different agents
- **Agents are extensible** - Add new capabilities by adding skills
- **Expertise is shareable** - Domain experts can contribute skills without building full agents

## Best Practices

### For Building Skills

1. **Start specific, then generalize** - Build a skill for your exact use case first, then abstract
2. **Include failure cases** - Document what the skill can't do and how to handle it
3. **Version your skills** - Track changes so agents can depend on stable versions
4. **Test with real tasks** - Validate skills against actual work, not just theory

### For Using Skills with Agents

1. **Read the skill first** - Understand what a skill does before deploying it
2. **Customize thoughtfully** - Override skill defaults only when necessary
3. **Monitor performance** - Track how well skills perform in your context
4. **Contribute improvements** - When you improve a skill, consider sharing back

<Callout type="info" title="The Future is Composable">
As AI agents become more capable, the ability to compose, share, and customize skills will become a core competency. The prompt engineers of tomorrow won't just write prompts—they'll architect skill ecosystems that make AI agents genuinely expert in specific domains.
</Callout>

<Quiz 
  question="What is the key difference between a simple prompt and a skill?"
  options={[
    "Skills are longer than prompts",
    "Skills are reusable, multi-file packages that give agents domain expertise",
    "Skills only work with specific AI models",
    "Skills don't require any prompts"
  ]}
  correctIndex={1}
  explanation="Skills are comprehensive, portable packages that combine multiple prompts, reference docs, scripts, and configuration. They're reusable building blocks that can be added to any agent to give it specific capabilities."
/>

<Quiz 
  question="What is the agent loop?"
  options={[
    "A debugging technique for AI errors",
    "Plan → Execute → Observe → Adapt, repeated until the goal is achieved",
    "A way to chain multiple prompts together",
    "A method for training new AI models"
  ]}
  correctIndex={1}
  explanation="AI agents work in a continuous loop: they plan how to approach a task, execute actions, observe the results, and adapt their approach based on feedback—repeating until the goal is complete."
/>

<Quiz 
  question="Why are skills described as 'reusable blocks of agents'?"
  options={[
    "Because they can only be used once",
    "Because they're written in a block programming language",
    "Because any agent can load a skill to gain that capability instantly",
    "Because skills replace the need for agents"
  ]}
  correctIndex={2}
  explanation="Skills are portable expertise packages. Write a code review skill once, and any coding agent can become an expert code reviewer by loading that skill—like LEGO blocks that snap into any structure."
/>
