Skip to content

Commit ef0528f

Browse files
nhortonclaude
andauthored
Add template agent support to create-agent skill (#226)
* Add template agent support to create-agent skill Allow seeding a new LearningAgent from an existing one by passing an optional template path. Copies core-knowledge.md, topics, and learnings from the template as a starting point, which the user can then customize. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add requirements and tests for template agent creation Add REQ-002.16 through REQ-002.24 covering template-based agent seeding (validation, copying, reporting, skill guidance). Update REQ-002.5 and REQ-002.6 to reflect the optional template argument. Add 16 tests for create_agent.sh covering both baseline and template flows — all passing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix ruff formatting in test_create_agent_script.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1a5cc56 commit ef0528f

File tree

4 files changed

+324
-10
lines changed

4 files changed

+324
-10
lines changed

learning_agents/scripts/create_agent.sh

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#!/bin/bash
22
# create_agent.sh - Create a new LearningAgent scaffold
33
#
4-
# Usage: create_agent.sh <agent-name>
4+
# Usage: create_agent.sh <agent-name> [template-agent-path]
5+
#
6+
# Arguments:
7+
# agent-name Name for the new agent (use dashes for multi-word)
8+
# template-agent-path Optional path to an existing learning agent directory
9+
# (e.g., .deepwork/learning-agents/my-existing-agent)
10+
# If provided, copies core-knowledge.md, topics/*, and
11+
# learnings/* from the template into the new agent.
512
#
613
# Creates:
714
# .deepwork/learning-agents/<agent-name>/core-knowledge.md
@@ -13,12 +20,25 @@
1320
set -euo pipefail
1421

1522
AGENT_NAME="${1:-}"
23+
TEMPLATE_PATH="${2:-}"
1624

1725
if [ -z "$AGENT_NAME" ]; then
18-
echo "Usage: create_agent.sh <agent-name>" >&2
26+
echo "Usage: create_agent.sh <agent-name> [template-agent-path]" >&2
1927
exit 1
2028
fi
2129

30+
# Validate template path if provided
31+
if [ -n "$TEMPLATE_PATH" ]; then
32+
if [ ! -d "$TEMPLATE_PATH" ]; then
33+
echo "Template agent directory not found: ${TEMPLATE_PATH}" >&2
34+
exit 1
35+
fi
36+
if [ ! -f "$TEMPLATE_PATH/core-knowledge.md" ]; then
37+
echo "Template directory missing core-knowledge.md: ${TEMPLATE_PATH}" >&2
38+
exit 1
39+
fi
40+
fi
41+
2242
AGENT_DIR=".deepwork/learning-agents/${AGENT_NAME}"
2343
CLAUDE_AGENT_FILE=".claude/agents/${AGENT_NAME}.md"
2444

@@ -55,8 +75,39 @@ These files let you customize how the learning cycle works for this agent. Each
5575
- **learning_from_issues.md** — Included during the `incorporate-learnings` step. Use this to guide how learnings are integrated — e.g., preferences for topics vs learnings, naming conventions, or areas of core-knowledge that should stay concise.
5676
ALG_README
5777

58-
# Create core-knowledge.md with TODO placeholder
59-
cat > "${AGENT_DIR}/core-knowledge.md" << 'CORE_KNOWLEDGE'
78+
# ========================================================================
79+
# SEED FROM TEMPLATE OR CREATE EMPTY
80+
# ========================================================================
81+
82+
if [ -n "$TEMPLATE_PATH" ]; then
83+
# Copy core-knowledge.md from template
84+
cp "$TEMPLATE_PATH/core-knowledge.md" "${AGENT_DIR}/core-knowledge.md"
85+
echo "Copied core-knowledge.md from template"
86+
87+
# Copy topics (if any exist beyond .gitkeep)
88+
TOPIC_COUNT=0
89+
for f in "$TEMPLATE_PATH/topics/"*.md; do
90+
[ -f "$f" ] || continue
91+
cp "$f" "${AGENT_DIR}/topics/"
92+
TOPIC_COUNT=$((TOPIC_COUNT + 1))
93+
done
94+
if [ "$TOPIC_COUNT" -gt 0 ]; then
95+
echo "Copied ${TOPIC_COUNT} topic(s) from template"
96+
fi
97+
98+
# Copy learnings (if any exist beyond .gitkeep)
99+
LEARNING_COUNT=0
100+
for f in "$TEMPLATE_PATH/learnings/"*.md; do
101+
[ -f "$f" ] || continue
102+
cp "$f" "${AGENT_DIR}/learnings/"
103+
LEARNING_COUNT=$((LEARNING_COUNT + 1))
104+
done
105+
if [ "$LEARNING_COUNT" -gt 0 ]; then
106+
echo "Copied ${LEARNING_COUNT} learning(s) from template"
107+
fi
108+
else
109+
# Create core-knowledge.md with TODO placeholder
110+
cat > "${AGENT_DIR}/core-knowledge.md" << 'CORE_KNOWLEDGE'
60111
TODO: Complete current knowledge of this domain.
61112
Written in second person ("You should...") because this text
62113
becomes the agent's system instructions. Structure it as:
@@ -66,6 +117,7 @@ becomes the agent's system instructions. Structure it as:
66117
4. Pitfalls to avoid
67118
5. Decision frameworks
68119
CORE_KNOWLEDGE
120+
fi
69121

70122
echo "Created agent directory: ${AGENT_DIR}"
71123
fi

learning_agents/skills/create-agent/SKILL.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,49 @@ Create a new LearningAgent and guide the user through initial configuration.
99

1010
## Arguments
1111

12-
`$ARGUMENTS` is the agent name. Use dashes for multi-word names (e.g., `rails-activejob`). If not provided, ask the user what to name the agent.
12+
`$ARGUMENTS` contains the agent name and an optional template path, separated by whitespace.
13+
14+
- **Agent name** (required): Use dashes for multi-word names (e.g., `rails-activejob`). If not provided, ask the user what to name the agent.
15+
- **Template agent path** (optional): Path to an existing learning agent directory (e.g., `.deepwork/learning-agents/my-existing-agent`). If provided, the new agent is seeded with the template's `core-knowledge.md`, `topics/`, and `learnings/` as a starting point. The user can then customize the copied content during configuration.
1316

1417
## Procedure
1518

1619
### Step 1: Validate and Run Scaffold Script
1720

21+
Parse `$ARGUMENTS` to extract the agent name (first word) and optional template path (second word, if present).
22+
1823
If the name contains spaces or uppercase letters, normalize to lowercase dashes (e.g., "Rails ActiveJob" → `rails-activejob`).
1924

2025
Check `.claude/agents/` for an existing file matching `<agent-name>.md`. If found, inform the user of the conflict and ask how to proceed.
2126

27+
If a template path was provided, verify it exists and contains `core-knowledge.md`. If not, inform the user and ask how to proceed.
28+
2229
Run the scaffold script:
2330

2431
```bash
25-
${CLAUDE_PLUGIN_ROOT}/scripts/create_agent.sh $ARGUMENTS
32+
# Without template:
33+
${CLAUDE_PLUGIN_ROOT}/scripts/create_agent.sh <agent-name>
34+
35+
# With template:
36+
${CLAUDE_PLUGIN_ROOT}/scripts/create_agent.sh <agent-name> <template-agent-path>
2637
```
2738

2839
If the script reports that directories already exist, inform the user and ask whether to proceed with updating the configuration or stop.
2940

41+
If a template was used, inform the user what was copied (the script output will list the counts).
42+
3043
### Step 2: Configure the Agent
3144

3245
Ask the user about the agent's domain:
3346

3447
- What domain or area of expertise does this agent cover?
3548
- What kinds of tasks will it be delegated to handle?
3649

50+
If a template was used, read the copied `core-knowledge.md` and present it to the user. Ask if they want to keep it as-is, modify it for the new agent's focus, or replace it entirely.
51+
3752
Based on their answers, update:
3853

39-
1. **`.deepwork/learning-agents/<agent-name>/core-knowledge.md`**: Replace the TODO content with the agent's core expertise in second person ("You should...", "You are an expert on...").
54+
1. **`.deepwork/learning-agents/<agent-name>/core-knowledge.md`**: If created from scratch, replace the TODO content with the agent's core expertise in second person ("You should...", "You are an expert on..."). If seeded from a template, adapt the content to reflect the new agent's specific focus area.
4055

4156
Example:
4257
```
@@ -52,7 +67,9 @@ Based on their answers, update:
5267

5368
### Step 3: Seed Initial Knowledge (Optional)
5469

55-
Ask the user if they want to seed any initial topics or learnings. If yes, create files using these formats:
70+
If a template was used and topics/learnings were copied, list what was copied and ask if the user wants to review, remove, or add to them.
71+
72+
Otherwise, ask the user if they want to seed any initial topics or learnings. If yes, create files using these formats:
5673

5774
**Topic file** (`.deepwork/learning-agents/<agent-name>/topics/<topic-name>.md`):
5875
```yaml

specs/learning-agents/REQ-002-agent-creation.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ If the agent directory `.deepwork/learning-agents/<agent-name>/` already exists,
2424

2525
### REQ-002.5: Scaffold Script Execution
2626

27-
The skill MUST execute the scaffold script at `${CLAUDE_PLUGIN_ROOT}/scripts/create_agent.sh` passing the normalized agent name as the argument.
27+
The skill MUST execute the scaffold script at `${CLAUDE_PLUGIN_ROOT}/scripts/create_agent.sh` passing the normalized agent name as the first argument and, when a template path is provided, the template path as the second argument.
2828

2929
### REQ-002.6: Scaffold Script -- Agent Directory Creation
3030

3131
The `create_agent.sh` script MUST create the following directory structure when the agent directory does not exist:
32-
- `.deepwork/learning-agents/<agent-name>/core-knowledge.md` -- with TODO placeholder content
32+
- `.deepwork/learning-agents/<agent-name>/core-knowledge.md` -- with TODO placeholder content (when no template is provided; see REQ-002.19 for template behavior)
3333
- `.deepwork/learning-agents/<agent-name>/topics/` -- with `.gitkeep`
3434
- `.deepwork/learning-agents/<agent-name>/learnings/` -- with `.gitkeep`
3535
- `.deepwork/learning-agents/<agent-name>/additional_learning_guidelines/` -- containing `README.md`, `issue_identification.md`, `issue_investigation.md`, and `learning_from_issues.md`
@@ -75,3 +75,39 @@ Upon completion, the skill MUST output a summary listing all files created or mo
7575
### REQ-002.15: No Overwrites Without Confirmation
7676

7777
The skill MUST NOT overwrite any existing file without explicit user confirmation.
78+
79+
### REQ-002.16: Scaffold Script -- Template Agent Argument
80+
81+
The `create_agent.sh` script MUST accept an optional second positional argument `[template-agent-path]` specifying the path to an existing LearningAgent directory. When not provided, the script MUST behave identically to the non-template flow (creating TODO placeholder content in `core-knowledge.md`).
82+
83+
### REQ-002.17: Scaffold Script -- Template Validation -- Directory Existence
84+
85+
When a template path argument is provided, the script MUST verify that the path is an existing directory. If the directory does not exist, the script MUST print an error message containing the path to stderr and exit with code 1.
86+
87+
### REQ-002.18: Scaffold Script -- Template Validation -- Core Knowledge Required
88+
89+
When a template path argument is provided and the directory exists, the script MUST verify that the template directory contains a `core-knowledge.md` file. If the file is missing, the script MUST print an error message containing the path to stderr and exit with code 1.
90+
91+
### REQ-002.19: Scaffold Script -- Template Seeding -- Core Knowledge
92+
93+
When a valid template path is provided, the script MUST copy `core-knowledge.md` from the template directory into the new agent's directory instead of creating the TODO placeholder content.
94+
95+
### REQ-002.20: Scaffold Script -- Template Seeding -- Topics
96+
97+
When a valid template path is provided, the script MUST copy all `.md` files from the template's `topics/` directory into the new agent's `topics/` directory. If no `.md` files exist in the template's `topics/` directory, the new agent's `topics/` directory MUST remain empty (aside from `.gitkeep`).
98+
99+
### REQ-002.21: Scaffold Script -- Template Seeding -- Learnings
100+
101+
When a valid template path is provided, the script MUST copy all `.md` files from the template's `learnings/` directory into the new agent's `learnings/` directory. If no `.md` files exist in the template's `learnings/` directory, the new agent's `learnings/` directory MUST remain empty (aside from `.gitkeep`).
102+
103+
### REQ-002.22: Scaffold Script -- Template Copy Reporting
104+
105+
When files are copied from a template, the script MUST output a confirmation message for the core-knowledge copy. The script MUST output the count of copied topic files when at least one topic was copied. The script MUST output the count of copied learning files when at least one learning was copied.
106+
107+
### REQ-002.23: Skill -- Template Configuration Guidance
108+
109+
When a template was used, the skill MUST read the copied `core-knowledge.md` and present it to the user, asking whether to keep it as-is, modify it for the new agent's focus, or replace it entirely. The skill MUST also list any copied topics and learnings and offer the user the opportunity to review, remove, or add to them.
110+
111+
### REQ-002.24: Skill -- Template Argument Parsing
112+
113+
The skill MUST parse `$ARGUMENTS` to extract the agent name (first token) and an optional template path (second token). Both tokens MUST be passed to the scaffold script as separate positional arguments.

0 commit comments

Comments
 (0)