Find relevant patterns for the current task by scoring against the memory store. Return top-5 matches ranked by tag overlap, recency, confidence, and usage. Triggers: match pattern, find pattern, similar task, what worked before, recall approach
swarm-decompose to enrich sub-tasks with known approachesmemory/patterns/index.json exists and contains at least one patternmemory/patterns/Extract keywords from the current task description:
Read memory/patterns/index.json. For each pattern entry, note:
id, name, tags, confidence, last_usedFor every pattern in the index, calculate a relevance score using four weighted factors:
| Factor | Weight | Calculation |
|---|---|---|
| Tag overlap | 0.4 | (number of matching tags / total tags in pattern) |
| Recency | 0.2 | 1.0 if used within 7 days, 0.5 if within 30, 0.2 if within 90, 0.0 if older |
| Confidence | 0.3 | Direct value from pattern (0.0–1.0) |
| Usage frequency | 0.1 | min(usage_count / 10, 1.0) — caps at 10 uses |
Relevance score = (tag_overlap * 0.4) + (recency * 0.2) + (confidence * 0.3) + (usage * 0.1)
Sort patterns by relevance score descending. Apply filters:
For each of the top-5 matches, read the full pattern JSON from memory/patterns/pat-[slug].json. Extract the approach, tools_used, and agents_involved fields.
Format the matches for consumption by the requesting agent:
## Relevant Patterns Found
### 1. [Pattern Name] — Score: [x.xx]
- **Approach**: [summary]
- **Tools**: [list]
- **Confidence**: [x.xx] (used [N] times, [N] successes)
- **Last used**: [date]
### 2. [Pattern Name] — Score: [x.xx]
...
Inject the context enrichment block into the agent's prompt or task description. The agent can choose to follow a matched pattern or ignore it if the current task differs.