AI Programming Concepts: Rules, Commands, Subagents, MCP, Skills, Modes, Hooks
The article systematically defines and compares the seven key AI programming abstractions—Rules, Commands, Subagents, MCP, Skills, Modes, and Hooks—detailing their core characteristics, typical use cases, implementation patterns, and best‑practice guidelines while highlighting common misunderstand‑ings and design trade‑offs.
Concept hierarchy
From an architectural perspective the concepts are organized into three layers:
Constraint layer : Rules – define behavior boundaries and norms.
Capability layer : Skills, MCP, Commands – extend the agent’s functional range.
Application layer : Subagents, Modes, Hooks – control complex task execution and strategy.
┌─────────────────────────────────────────┐
│ Application / Orchestration │
│ (Subagent, Modes, Hooks) │
├─────────────────────────────────────────┤
│ Capability / Extension │
│ (Skills, MCP, Commands) │
├─────────────────────────────────────────┤
│ Constraint / Specification │
│ (Rules) │
└─────────────────────────────────────────┘1. Rules
Definition
Rules are declarative constraints that specify what an AI should or should not do in a given scenario.
Core features
Declarative : describe "should/should not" rather than "how".
Composable : multiple rules can be combined to form complex policies.
Scoped : usually bound to a specific scene, task, or capability.
Typical use case
# Example: code‑review rules
- Disallow deprecated APIs
- Highlight security vulnerabilities
- Suggest performance improvements
- Enforce team coding styleTechnical implementation
Hard rules : enforced by a rule engine or static analysis.
Soft rules : expressed in prompts to guide LLM priorities.
Comparison
Rules describe constraints; they are restrictive .
Commands describe operations; they are executable .
Skills describe capability units; they are functional .
2. Commands
Definition
Commands are directly callable operation instructions that encapsulate a specific action or task.
Core features
Imperative : clearly state "do what" and trigger execution.
Parametric : accept input parameters and return results.
Atomic : each command performs a single, well‑defined action.
Typical use case
// File operation commands
interface FileCommands {
readFile(path: string): Promise<string>;
writeFile(path: string, content: string): Promise<void>;
deleteFile(path: string): Promise<void>;
}
// LLM interaction commands
interface LLMCommands {
complete(prompt: string): Promise<string>;
chat(messages: Message[]): Promise<Message>;
}Technical implementation
Synchronous commands : return results immediately (e.g., calculations, look‑ups).
Asynchronous commands : return a Promise or Stream for long‑running tasks (e.g., network requests).
Comparison
Commands are single‑operation, stateless, focusing on execution result .
Skills encapsulate reusable knowledge and focus on capability expression .
MCP provides a remote capability interface focused on service invocation .
3. Subagent
Definition
A Subagent is an independent agent instance with domain‑specific expertise, handling a particular type of task.
Core features
Domain expertise : deep knowledge and reasoning in a specific area.
Independence : its own context, tools, and decision logic.
Delegable : the main agent can hand off work to a Subagent.
Typical use case
// Domain‑expert Subagents
const subagents = {
frontend: new FrontendExpertSubagent(), // front‑end engineering
backend: new BackendExpertSubagent(), // back‑end engineering
security: new SecurityAuditorSubagent(), // security audit
documentation: new DocWriterSubagent() // technical writing
};
// Main agent delegates a task
const result = await subagents.frontend.analyzeComponent(component);Technical implementation
Model selection : different Subagents may use different LLM sizes.
Tool set : each Subagent is equipped with domain‑specific tools.
Context isolation : prevents information leakage between Subagents.
Comparison
Subagent is a full AI entity with independent reasoning and decision‑making.
Skill is a knowledge unit that must be invoked to execute.
Command is a stateless operation interface without autonomy.
4. MCP (Model Context Protocol)
Definition
MCP is a standardized protocol that creates context‑aware connections between an LLM and external services or tools.
Core features
Protocol standardization : defines unified interface specifications and message formats.
Service discovery : supports dynamic loading of external capabilities.
Security boundaries : provides permission control and access limits.
Typical use case
// MCP server interface example
interface MCPServer {
// Tool definitions
listTools(): Tool[];
callTool(name: string, args: any): Promise<ToolResult>;
// Resource access
listResources(): Resource[];
readResource(uri: string): Promise<ResourceContent>;
// Prompt templates
listPrompts(): Prompt[];
getPrompt(name: string): Promise<PromptContent>;
}Technical implementation
Transport layer : supports stdio, SSE, etc.
Message format : JSON‑RPC or custom protocol.
Lifecycle management : connection establishment, heartbeat, reconnection.
Comparison
MCP is the protocol layer that defines communication specifications and interface standards.
Skills form the knowledge layer that defines domain capabilities and best practices.
Commands form the interface layer that defines concrete operations and invocation methods.
5. Skills
Definition
Skills are reusable capability units that encapsulate domain knowledge, tool usage, and best practices.
Core features
Knowledge‑dense : contain domain expertise and reasoning patterns.
Tool‑bound : explicitly declare required tool sets.
Composable : multiple Skills can be combined into more complex abilities.
Typical use case
# SKILL.md – Front‑end engineering
---
name: frontend-engineering
version: 1.0.0
description: Code generation, review, and refactoring for front‑end projects
tools: [playwright, eslint, prettier]
---
# Usage scenarios
- Generate React component code
- Review front‑end code quality
- Refactor CSS styles
- Provide performance‑optimisation suggestions
# Constraints
- Follow React best practices
- Use TypeScript strict typing
- Meet WCAG accessibility standardsTechnical implementation
Metadata‑driven : skill properties are defined via YAML front‑matter.
Prompt templates : include system prompts and task instructions.
Tool declaration : list required tools and permissions.
Comparison
Skills encapsulate knowledge and best practices (functional capability).
Commands define only how to invoke a function (operational interface).
Subagents are full AI entities with autonomous reasoning.
6. Modes
Definition
Modes are collections of behavior strategies and configuration sets that an agent adopts for different scenarios or task types.
Core features
State switching : changing the agent’s behavior by switching modes.
Configuration differentiation : each mode has its own parameters, tools, and policies.
Context isolation : switching may reset or clear part of the context.
Typical use case
// Agent mode definitions
const agentModes = {
development: {
tools: ["file", "git", "terminal"],
rules: ["verbose-logging", "allow-experiments"],
maxTokens: 16000
},
production: {
tools: ["read-only"],
rules: ["safety-first", "no-experiments"],
maxTokens: 4000
},
debug: {
tools: ["diagnostics", "profiler"],
rules: ["detailed-logs", "step-by-step"],
maxTokens: 32000
}
};Technical implementation
State machine : manages mode‑switching logic.
Hot‑reloading configuration : allows runtime changes.
Permission downgrade : production mode restricts dangerous operations.
Comparison
Modes define overall strategy and execution environment.
Rules define specific constraints and boundary conditions.
Skills define usable abilities and domain knowledge.
7. Hooks
Definition
Hooks are event‑driven extension points that automatically trigger at specific lifecycle nodes, allowing custom logic insertion.
Core features
Event driven : bound to events such as task start, tool call, or error.
Pluggable : can be registered or deregistered dynamically.
Side effects : used for monitoring, logging, permission checks, etc.
Typical use case
// Lifecycle hooks example
const hooks = {
beforeCommand: async (command, args) => {
logger.log(`Executing: ${command.name}`, args);
await security.checkPermission(command.name);
},
afterCommand: async (command, result) => {
metrics.record(command.name, result.duration);
if (result.error) {
alerting.notify(command.name, result.error);
}
},
onError: async (error, context) => {
telemetry.trackError(error, context);
await fallback.recover(error, context);
}
};Technical implementation
Middleware pattern : inserts interceptors into the request handling chain.
Event bus : publish‑subscribe model decouples registration from triggering.
Asynchronous execution : supports async hooks to avoid blocking the main flow.
Comparison
Hooks handle events and extend specific processes.
Commands are direct invocations for executing concrete tasks.
Rules are behavior constraints that control agent actions.
Practical example – Code review agent
// Define a code‑review agent
class CodeReviewAgent {
// Mode configuration
modes = {
quick: { rules: ["basic-syntax"], tools: ["linter"] },
deep: { rules: ["security", "performance"], tools: ["linter", "scanner"] }
};
// Register hooks
hooks = {
beforeReview: [logStart, checkPermissions],
afterReview: [generateReport, notifyTeam]
};
// Available skills
skills = {
frontend: loadSkill("frontend-engineering"),
backend: loadSkill("backend-security"),
documentation: loadSkill("tech-writing")
};
// Sub‑experts
subagents = {
security: new SecurityExpertSubagent(),
performance: new PerformanceOptimizerSubagent()
};
// MCP‑connected external tools
mcpClients = {
github: connectMCP("github://api"),
sonarqube: connectMCP("sonarqube://server")
};
async review(code, mode) {
// Switch mode
await this.switchMode(mode);
// Trigger before‑review hooks
for (const h of this.hooks.beforeReview) await h();
// Choose appropriate skill
const skill = this.detectSkill(code);
await skill.execute(code);
// Delegate deep analysis to a Subagent when needed
const securityIssues = await this.subagents.security.analyze(code);
// Call MCP tool for external metadata
const metadata = await this.mcpClients.github.getPRMetadata();
// Trigger after‑review hooks
for (const h of this.hooks.afterReview) await h();
}
}Best practices
Single responsibility : each concept should solve one class of problem.
Clear layering : avoid overlapping responsibilities across concepts.
Composability : design abstractions to be combined where needed.
Start simple : introduce Subagents or MCP only when required.
Prefer built‑in Commands and Skills before adding custom layers.
Common pitfalls
Confusing Commands with Skills – use Commands for simple operations (e.g., file I/O) and Skills for richer capabilities (e.g., code review).
Overusing Subagents – reserve Subagents for tasks that need independent reasoning and tool sets.
Ignoring Hooks – leverage Hooks to keep core logic pure and handle cross‑cutting concerns separately.
Redundant Mode configurations – use Modes for major strategy differences; fine‑grained tweaks belong in Rules or parameters.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Frontend AI Walk
Looking for a one‑stop platform that deeply merges frontend development with AI? This community focuses on intelligent frontend tech, offering cutting‑edge insights, practical implementation experience, toolchain innovations, and rich content to help developers quickly break through in the AI‑driven frontend era.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
