Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

Missing Hook: Skill Invocation Requires Deterministic Trigger Detection

Open MarkoSteenbergen opened this issue 10 months ago • 3 comments

Summary

PAI's skill system uses lazy loading: load frontmatter at session start → invoke skill when matched → load full workflow on demand. However, there's no hook that deterministically detects when skills should be invoked. This leaves skill invocation entirely to AI judgment, which creates two failure modes:

  1. Architectural: No code enforcement means even explicit prompts can be ignored
  2. Behavioral: Vague or indirect prompting makes the problem significantly worse

The gap: Skills define USE WHEN clauses in YAML frontmatter, but nothing enforces that matched skills actually get invoked.


The Problem

What exists:

  • SessionStart hook → loads CORE context
  • Skills define USE WHEN triggers in frontmatter
  • The Skill tool for invoking skills

What's missing:

  • A UserPromptSubmit hook that parses USE WHEN clauses and enforces skill invocation when triggers match

Without deterministic enforcement, the AI must:

  1. Remember to check if a skill applies
  2. Decide to invoke the Skill tool
  3. Not improvise when it "knows" the domain

This violates PAI's own Principle #4: "Code Before Prompts" — behavior depends on AI discipline rather than code enforcement.


Why Prompting Quality Matters

The architectural gap is significantly exacerbated by prompt characteristics:

Indirect language increases failure rate: ❌ "Could you maybe check if this works?" ✅ "Use the Browser skill to validate danielmiessler.com"

Vague instructions allow improvisation: ❌ "Analyze this" ✅ "Spawn CodexResearcher agent. Search for: [specific criteria]"

Missing tool specification lets AI choose: ❌ "Research Daniel's content about skill invocation" ✅ "Use WebSearch skill: 'Daniel Miessler PAI skill routing 2026'"

Empirical observation: Strong, imperative prompting (as documented in skills/Prompting/Standards.md) significantly improves skill invocation rates, but doesn't eliminate failures. Even direct commands like "Use the Browser skill" can be ignored without code enforcement.

This suggests the problem is architectural (no enforcement hook) amplified by behavioral factors (prompt quality).


Real-World Impact

Without code enforcement:

  • Skills bypassed even when explicitly named
  • Workflows never execute
  • AI improvises instead of following documented processes
  • No way to validate that invoked skills actually loaded
  • Multilingual prompts (e.g., Dutch) have even lower match rates

Current workarounds:

  • Users must use explicit slash commands (/browser, /osint) to force invocation
  • This defeats the purpose of USE WHEN trigger-based routing
  • Reduces skill system to manual command execution

Proposed Solution

Add hooks/skill-enforcer.ts triggered on UserPromptSubmit:

Pseudo-code outline:

function enforceSkillInvocation(userPrompt: string) {
  // 1. Parse all SKILL.md frontmatter at session start (cache)
  const skills = parseAllSkillFrontmatter();

  // 2. Match user prompt against USE WHEN triggers
  const matched = matchTriggers(userPrompt, skills);

  // 3. If match found, inject blocking instruction
  if (matched) {
    injectSystemMessage(`
      🚨 SKILL MATCH DETECTED: ${matched.name}

      You MUST invoke the Skill tool:
      Skill({ skill: "${matched.name}" })

      Do not improvise or skip this invocation.
      The skill contains specialized workflows for this task.
    `);
  }
}

Benefits:
- ✅ Makes lazy loading architecture work as designed
- ✅ Ensures skills actually execute when triggered
- ✅ Aligns with Principle #4: "Code Before Prompts"
- ✅ Testable and debuggable (log matches, verify invocations)
- ✅ Works regardless of prompt quality (though good prompts still help)

Matching Strategy:
- Simple: Keyword matching with stopword filtering (fast, deterministic)
- Advanced: Semantic embedding similarity for multilingual support (optional upgrade)

---
Related Issues

This architectural gap may explain other skill-related issues where workflows don't load or execute:
- Skills appear to work but don't follow documented workflows
- Inconsistent behavior between sessions
- "The system just knows" works unreliably in practice

---
Research Note

Based on analysis of effective prompting patterns (Anthropic's Claude 4.x Best Practices, IndyDevDan's XML structure framework, PAI's own Prompting/Standards.md), strong prompting significantly improves outcomes but doesn't solve the fundamental issue:

Strong prompting reduces the problem ~40-60%, but doesn't eliminate it.

The root cause remains architectural: without code-based trigger detection, even perfect prompts rely on AI compliance rather than deterministic execution.

---
Question

Is the current AI-based approach a conscious design trade-off (simplicity vs reliability), or would code-based skill enforcement be a valuable improvement?

Environment: PAI 2.3.0, Claude Code, Linux
---
Acknowledgment

This issue was identified through systematic analysis comparing:
1. PAI's documented prompting standards (skills/Prompting/Standards.md)
2. Effective prompting patterns (IndyDevDan's frameworks, Anthropic best practices)
3. Observed skill invocation behavior across various prompt styles

The analysis revealed that while prompt quality is a significant factor, the architectural gap (no code enforcement) is the fundamental issue that should be addressed.

MarkoSteenbergen avatar Jan 17 '26 22:01 MarkoSteenbergen

Thanks for reporting this! We've been doing a major restructuring of PAI's core systems, including a complete redesign of the hook architecture (consolidated from 22 to ~19 hooks), a rewritten Algorithm (now v0.5.1 with PRD-based verification), removal of the observability system, and numerous path/configuration fixes.

This specific issue is addressed by those changes. We're targeting a v3.0 release soon that will include all of this. We appreciate your patience and your help in identifying these issues — it directly informed our redesign work. Stay tuned!

danielmiessler avatar Feb 10 '26 21:02 danielmiessler

I follow the progression of PAI closely and I both love and hate the project. I love it because it is very close to the way I feel we should use AI and how a real assistant should act. I hate it because it often causes me the opposite of a good assistant, it provides more work for me. I underwrite your statement that you are working to address the issue, kudos! Some observations that might help you:

  • The root-cause for almost every time the llm decides to skip guardrails or skill use is a build-in bias to choose speed over process. It can even happen within one prompt (i.e. one council with skill, and with exactly the same context the next execution without skill for no other reason than speed)
  • It is written for macos, I use linux, so after each upgrade I need to check and adopt the changes for my system (obs, voice, ttyd+tmux vs kitty) -> some macos tools but mostly path names and sometimes hardcoded localhost (I use a headless server for pai).
  • I've extended pai with my own skills, after each upgrade I need to migrate and regression test them. Obviously this should be automated, but I miss the scaffolding for this (structure for core pai skills and user skills so upgrades don't break old stuff like it does now every time). Additionally a change list as context would speed up testing for the upgrade.

Big compliment for what you did with the algorithm in v2.5, this helps this issue big time!

btw, 'we' is you and Kai?

MarkoSteenbergen avatar Feb 11 '26 15:02 MarkoSteenbergen

Thanks for the detailed analysis! In v3.0 (now released), skill invocation detection was implemented via the SkillGuard hook and capability audit system. Please upgrade to v3.0.

kaimagnus avatar Feb 15 '26 17:02 kaimagnus