Skip to content

⛰️ LifeOS — The AI-powered Life Operating System that helps you hill climb to wherever you're going.

feat: Enforce AgentFactory usage and improve trait inference

Timo S.6d2b27d26216
diff --git a/Packs/kai-agents-skill/src/skills/Agents/Data/Traits.yaml b/Packs/kai-agents-skill/src/skills/Agents/Data/Traits.yaml
index 88fb5b7a..78f6ce8b 100644
--- a/Packs/kai-agents-skill/src/skills/Agents/Data/Traits.yaml
+++ b/Packs/kai-agents-skill/src/skills/Agents/Data/Traits.yaml
@@ -99,6 +99,28 @@ expertise:
- database
- infrastructure
- software
+ - script
+ - bash
+ - shell
+ - POSIX
+ - programming
+ - TypeScript
+ - JavaScript
+ - Python
+ - Java
+ - Rust
+ - Go
+ - error
+ - development
+ - transform
+ - conversion
+ - CLI
+ - function
+ - class
+ - module
+ - procedure
+ - refactor
+ - test
research:
name: "Research Specialist"
diff --git a/Packs/kai-agents-skill/src/skills/Agents/SKILL.md b/Packs/kai-agents-skill/src/skills/Agents/SKILL.md
index e196148b..6c46535a 100644
--- a/Packs/kai-agents-skill/src/skills/Agents/SKILL.md
+++ b/Packs/kai-agents-skill/src/skills/Agents/SKILL.md
@@ -7,6 +7,69 @@ description: Dynamic agent composition and management system. USE WHEN user says
**Auto-routes when user mentions custom agents, agent creation, or specialized personalities.**
+---
+
+## MANDATORY: AgentFactory Execution (Constitutional Rule)
+
+**BEFORE launching ANY custom agent, you MUST execute AgentFactory.ts via Bash.**
+
+```bash
+# REQUIRED for each custom agent:
+bun run $PAI_DIR/skills/Agents/Tools/AgentFactory.ts \
+ --traits "<expertise>,<personality>,<approach>" \
+ --task "<task description>" \
+ --output json
+```
+
+### Validation Checklist
+
+Before calling `Task()` for custom agents, confirm:
+
+- [ ] I executed `AgentFactory.ts` via Bash for EACH agent
+- [ ] I captured the JSON output (prompt + voice_id)
+- [ ] I am using the factory's `prompt` field verbatim
+- [ ] I am using `subagent_type: "general-purpose"`
+- [ ] Each agent has DIFFERENT trait combinations
+
+### What is FORBIDDEN
+
+| Action | Why It's Wrong |
+|--------|----------------|
+| Reading Traits.yaml and manually composing prompts | Bypasses voice mapping and template |
+| Copy-pasting trait descriptions into Task prompts | Creates inconsistent agent format |
+| Using `subagent_type: "Intern"` for custom agents | Overrides custom voice assignment |
+| Same traits for multiple agents | All agents get same voice |
+
+**If you haven't run AgentFactory.ts in this conversation, you have NOT created custom agents.**
+
+### Error Recovery Protocol
+
+**If AgentFactory returns "Unknown traits" error:**
+
+1. **DO NOT guess again** - Don't try different trait names randomly
+2. **Read the error output** - AgentFactory now lists all available traits on error
+3. **Select valid traits** - Choose from EXPERTISE, PERSONALITY, and APPROACH categories
+4. **Retry with correct traits** - Use the valid trait names from the error message
+
+**Example error output:**
+```
+Error: Unknown traits: typescript, bash
+
+Available traits:
+ EXPERTISE: security, legal, finance, medical, technical, research, creative, business, data, communications
+ PERSONALITY: skeptical, enthusiastic, cautious, bold, analytical, creative, empathetic, contrarian, pragmatic, meticulous
+ APPROACH: thorough, rapid, systematic, exploratory, comparative, synthesizing, adversarial, consultative
+
+Run with --list to see full trait descriptions
+```
+
+**Pro tip:** Use `--task` instead of `--traits` to let AgentFactory infer valid traits automatically:
+```bash
+bun run AgentFactory.ts --task "TypeScript transformation with careful type checking" --output json
+```
+
+---
+
## Overview
The Agents skill provides complete agent composition and management:
@@ -34,9 +97,10 @@ The Agents skill provides complete agent composition and management:
**CONSTITUTIONAL RULE FOR CUSTOM AGENTS:**
When user says "custom agents", you MUST:
-1. Use AgentFactory to compose EACH agent with DIFFERENT traits
-2. Use `subagent_type: "general-purpose"` - **NEVER** "Intern", "Designer", "Architect", etc.
-3. Each agent gets their own voice from the trait-to-voice mapping
+1. Execute AgentFactory.ts via Bash for EACH agent with DIFFERENT traits
+2. Capture and use the JSON output (prompt + voice_id)
+3. Use `subagent_type: "general-purpose"` - **NEVER** "Intern", "Designer", "Architect", etc.
+4. Each agent gets their own voice from the trait-to-voice mapping
## Architecture
diff --git a/Packs/kai-agents-skill/src/skills/Agents/Tools/AgentFactory.ts b/Packs/kai-agents-skill/src/skills/Agents/Tools/AgentFactory.ts
index 2b9b581a..3d349749 100644
--- a/Packs/kai-agents-skill/src/skills/Agents/Tools/AgentFactory.ts
+++ b/Packs/kai-agents-skill/src/skills/Agents/Tools/AgentFactory.ts
@@ -10,7 +10,12 @@
* bun run AgentFactory.ts --traits "security,skeptical,thorough"
* bun run AgentFactory.ts --list
*
- * @version 1.0.0
+ * @version 1.1.0
+ *
+ * Changelog v1.1.0:
+ * - Expanded technical keywords (bash, TypeScript, POSIX, error handling, etc.)
+ * - Improved error messages showing available traits on invalid input
+ * - Fixed: Explicit --traits now override inference (no longer merge)
*/
import { parseArgs } from "util";
@@ -295,11 +300,10 @@ EXAMPLES:
if (values.traits) {
traitKeys = values.traits.split(",").map((t) => t.trim().toLowerCase());
- }
-
- if (values.task) {
+ } else if (values.task) {
+ // Only infer from task if explicit traits NOT provided
const inferred = inferTraitsFromTask(values.task, traits);
- traitKeys = [...new Set([...traitKeys, ...inferred])];
+ traitKeys = [...new Set(inferred)];
}
if (traitKeys.length === 0) {
@@ -314,7 +318,12 @@ EXAMPLES:
];
const invalidTraits = traitKeys.filter((t) => !allTraitKeys.includes(t));
if (invalidTraits.length > 0) {
- console.error(`Error: Unknown traits: ${invalidTraits.join(", ")}`);
+ console.error(`Error: Unknown traits: ${invalidTraits.join(", ")}\n`);
+ console.error("Available traits:");
+ console.error(" EXPERTISE: " + Object.keys(traits.expertise).join(", "));
+ console.error(" PERSONALITY: " + Object.keys(traits.personality).join(", "));
+ console.error(" APPROACH: " + Object.keys(traits.approach).join(", "));
+ console.error('\nRun with --list to see full trait descriptions');
process.exit(1);
}
diff --git a/Packs/kai-agents-skill/src/skills/Agents/Workflows/CreateCustomAgent.md b/Packs/kai-agents-skill/src/skills/Agents/Workflows/CreateCustomAgent.md
index 87efe7ec..59fdda43 100644
--- a/Packs/kai-agents-skill/src/skills/Agents/Workflows/CreateCustomAgent.md
+++ b/Packs/kai-agents-skill/src/skills/Agents/Workflows/CreateCustomAgent.md
@@ -2,6 +2,22 @@
**Creates custom agents with unique personalities and voice IDs using AgentFactory.**
+---
+
+## Pre-flight Checklist (MANDATORY)
+
+**STOP! Before proceeding, you MUST complete this checklist:**
+
+- [ ] I understand I must run `AgentFactory.ts` via Bash
+- [ ] I will NOT manually compose prompts from Traits.yaml
+- [ ] I will capture JSON output and use the `prompt` field verbatim
+- [ ] I will use `subagent_type: "general-purpose"` (NEVER "Intern")
+- [ ] Each agent will have DIFFERENT trait combinations
+
+**⚠️ VIOLATION: If you skip AgentFactory, you are NOT creating custom agents.**
+
+---
+
## When to Use
User says:
@@ -20,12 +36,36 @@ Extract from user's request:
- What's the task?
- Are specific traits mentioned?
-### Step 2: Run AgentFactory for EACH Agent with DIFFERENT Traits
+### Step 1.5: Choose Traits (RECOMMENDED) or Infer from Task
+
+**⚠️ RECOMMENDED: Use explicit `--traits` for precise control**
+
+Trait inference is convenient but may produce unexpected results for ambiguous tasks.
+
+| Approach | Precision | Example |
+|----------|-----------|---------|
+| **Explicit** ✅ | High - you control exactly which traits | `--traits "technical,meticulous,systematic"` |
+| **Inference** ⚠️ | Low - keywords may match wrong expertise | `--task "TypeScript transformation"` (might infer wrong traits) |
+
+**When to use explicit traits:**
+- Technical/programming tasks (avoid false matches with legal/medical)
+- When you need specific personality/approach combinations
+- When voice diversity matters
+
+**When inference is OK:**
+- Task description has very clear domain keywords
+- You're comfortable with defaults (analytical + thorough)
-**CRITICAL: Each agent MUST have different trait combinations for unique voices.**
+**Pro tip:** Run `bun run AgentFactory.ts --list` to see all available traits before choosing.
+
+### Step 2: Run AgentFactory for EACH Agent (MANDATORY)
+
+**⚠️ THIS STEP IS NOT OPTIONAL - YOU MUST EXECUTE AGENTFACTORY.TS VIA BASH**
+
+**RECOMMENDED: Use explicit `--traits` parameter**
```bash
-# Example for 3 custom research agents:
+# REQUIRED: Run for EACH agent with DIFFERENT traits
# Agent 1 - Enthusiastic Explorer
bun run $PAI_DIR/skills/Agents/Tools/AgentFactory.ts \
@@ -46,6 +86,27 @@ bun run $PAI_DIR/skills/Agents/Tools/AgentFactory.ts \
--output json
```
+**Alternative (inference - less precise):**
+```bash
+# AgentFactory will infer traits from task description
+bun run $PAI_DIR/skills/Agents/Tools/AgentFactory.ts \
+ --task "Research quantum computing with enthusiastic exploration" \
+ --output json
+```
+
+**What AgentFactory returns (JSON output):**
+```json
+{
+ "name": "Research Specialist Enthusiastic Exploratory",
+ "traits": ["research", "enthusiastic", "exploratory"],
+ "voice": "Energetic",
+ "voice_id": "muSxG4dqYjBCkbpXqbEl",
+ "prompt": "... full agent prompt ..."
+}
+```
+
+**You MUST use the `prompt` field from this output in your Task call.**
+
### Step 3: Launch Agents in Parallel
**CRITICAL: Use `subagent_type: "general-purpose"` - NEVER "Intern" for custom agents!**