Patterns are code generation templates that guide how the LLM structures handler code. They capture proven approaches for common tasks.
Patterns are short markdown files that describe:
- When to use a specific approach
- What modules/profiles are needed
- Step-by-step structure
Unlike skills (which provide domain knowledge), patterns focus on code architecture.
| Pattern | Description |
|---|---|
two-handler-pipeline |
Research → Build using shared-state |
file-generation |
Creating binary files (ZIP, PPTX, etc.) |
fetch-and-process |
Fetch data then transform it |
data-transformation |
Transform input data structures |
data-extraction |
Extract specific data from sources |
image-embed |
Embed images in generated files |
Patterns live in patterns/<name>/PATTERN.md:
---
name: two-handler-pipeline
description: Research data then build output using separate handlers
modules: [shared-state]
profiles: []
---
1. Register a RESEARCH handler that collects data
2. Store results in ha:shared-state
3. Register a BUILD handler that reads shared-state
4. Execute research → build in sequence
5. Use ha:shared-state for cross-handler data| Field | Description |
|---|---|
name |
Pattern identifier |
description |
One-line summary |
modules |
Required modules |
profiles |
Suggested profiles |
Numbered steps describing the pattern structure. Keep it concise — these are injected into prompts.
Skills can reference patterns in their frontmatter:
---
name: pptx-expert
patterns:
- two-handler-pipeline
- file-generation
- image-embed
---When the skill is loaded, referenced patterns are included in the system message.
Patterns are loaded by src/agent/pattern-loader.ts:
- Discovers patterns in
patterns/directory - Parses YAML frontmatter
- Provides pattern content to system message builder
For tasks that need to gather data before building output:
┌──────────────────┐ ┌──────────────────┐
│ RESEARCH │ │ BUILD │
│ handler │────▶│ handler │
│ │ │ │
│ Collects data │ │ Creates output │
│ Stores in │ │ Reads from │
│ shared-state │ │ shared-state │
└──────────────────┘ └──────────────────┘
Why two handlers?
- Keeps each handler small and focused, pushes the LLM to structure code in a modular way
- Separates concerns
- Shared-state persists across recompiles
For creating binary files:
- Import required modules (zip-format, pptx, etc.)
- Build file structure in memory
- Return as Uint8Array or base64
- Host writes to filesystem (if fs-write enabled)
For web data tasks:
- Validate URLs (require fetch plugin)
- Fetch data with error handling
- Parse response (JSON, HTML, etc.)
- Transform into desired format
- Store or return results
mkdir -p patterns/my-pattern---
name: my-pattern
description: Brief description of when to use this
modules: [required-module]
profiles: [suggested-profile]
---
1. First step
2. Second step
3. Third stepAdd to skill frontmatter:
patterns:
- my-pattern| Aspect | Pattern | Skill |
|---|---|---|
| Focus | Code structure | Domain knowledge |
| Content | Step-by-step instructions | Guidance and context |
| Size | Brief (10-20 lines) | Detailed (100+ lines) |
| Usage | Referenced by skills | Loaded directly |
Patterns and skills work together:
- Skills provide domain expertise
- Skills reference patterns for code structure
- Both are injected into system message
- SKILLS.md - Domain expertise
- MODULES.md - Available modules
- HOW-IT-WORKS.md - System overview