@rfxlamia/skillkit 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/agents/agents/creative-copywriter.md +212 -0
  2. package/agents/agents/dario-amodei.md +135 -0
  3. package/agents/agents/doc-simplifier.md +63 -0
  4. package/agents/agents/kotlin-pro.md +433 -0
  5. package/agents/agents/red-team.md +136 -0
  6. package/agents/agents/sam-altman.md +121 -0
  7. package/agents/agents/seo-manager.md +184 -0
  8. package/package.json +1 -1
  9. package/skills/skillkit-help/SKILL.md +81 -0
  10. package/skills/skillkit-help/knowledge/application/09-case-studies.md +257 -0
  11. package/skills/skillkit-help/knowledge/application/12-testing-and-validation.md +276 -0
  12. package/skills/skillkit-help/knowledge/foundation/01-why-skills-exist.md +246 -0
  13. package/skills/skillkit-help/knowledge/foundation/02-skills-vs-subagents-comparison.md +312 -0
  14. package/skills/skillkit-help/knowledge/foundation/03-skills-vs-subagents-decision-tree.md +346 -0
  15. package/skills/skillkit-help/knowledge/foundation/06-platform-constraints.md +237 -0
  16. package/skills/skillkit-help/knowledge/foundation/08-when-not-to-use-skills.md +270 -0
  17. package/skills/skillkit-help/template/SKILL.md +52 -0
  18. package/skills/skills/adversarial-review/SKILL.md +219 -0
  19. package/skills/skills/baby-education/SKILL.md +260 -0
  20. package/skills/skills/baby-education/references/advanced-techniques.md +323 -0
  21. package/skills/skills/baby-education/references/transformations.md +345 -0
  22. package/skills/skills/been-there-done-that/SKILL.md +455 -0
  23. package/skills/skills/been-there-done-that/references/analysis-patterns.md +162 -0
  24. package/skills/skills/been-there-done-that/references/git-commands.md +132 -0
  25. package/skills/skills/been-there-done-that/references/tree-insertion-logic.md +145 -0
  26. package/skills/skills/coolhunter/SKILL.md +270 -0
  27. package/skills/skills/coolhunter/assets/elicitation-methods.csv +51 -0
  28. package/skills/skills/coolhunter/knowledge/elicitation-methods.md +312 -0
  29. package/skills/skills/coolhunter/references/workflow-execution.md +238 -0
  30. package/skills/skills/coolhunter/workflow-plan-coolhunter.md +232 -0
  31. package/skills/skills/creative-copywriting/SKILL.md +324 -0
  32. package/skills/skills/creative-copywriting/databases/README.md +60 -0
  33. package/skills/skills/creative-copywriting/databases/carousel-structures.csv +16 -0
  34. package/skills/skills/creative-copywriting/databases/emotional-arcs.csv +11 -0
  35. package/skills/skills/creative-copywriting/databases/hook-formulas.csv +51 -0
  36. package/skills/skills/creative-copywriting/databases/power-words.csv +201 -0
  37. package/skills/skills/creative-copywriting/databases/psychological-triggers.csv +21 -0
  38. package/skills/skills/creative-copywriting/databases/read-more-patterns.csv +26 -0
  39. package/skills/skills/creative-copywriting/databases/swipe-triggers.csv +31 -0
  40. package/skills/skills/creative-copywriting/references/carousel-psychology.md +223 -0
  41. package/skills/skills/creative-copywriting/references/hook-anatomy.md +169 -0
  42. package/skills/skills/creative-copywriting/references/power-word-science.md +134 -0
  43. package/skills/skills/creative-copywriting/references/storytelling-frameworks.md +157 -0
  44. package/skills/skills/diverse-content-gen/SKILL.md +201 -0
  45. package/skills/skills/diverse-content-gen/references/advanced-techniques.md +320 -0
  46. package/skills/skills/diverse-content-gen/references/research-findings.md +379 -0
  47. package/skills/skills/diverse-content-gen/references/task-workflows.md +241 -0
  48. package/skills/skills/diverse-content-gen/references/tool-integration.md +419 -0
  49. package/skills/skills/diverse-content-gen/references/troubleshooting.md +426 -0
  50. package/skills/skills/diverse-content-gen/references/vs-core-technique.md +240 -0
  51. package/skills/skills/framework-critical-thinking/SKILL.md +220 -0
  52. package/skills/skills/framework-critical-thinking/references/bias_detector.md +375 -0
  53. package/skills/skills/framework-critical-thinking/references/fallback_handler.md +239 -0
  54. package/skills/skills/framework-critical-thinking/references/memory_curator.md +161 -0
  55. package/skills/skills/framework-critical-thinking/references/metacognitive_monitor.md +297 -0
  56. package/skills/skills/framework-critical-thinking/references/producer_critic_orchestrator.md +333 -0
  57. package/skills/skills/framework-critical-thinking/references/reasoning_router.md +235 -0
  58. package/skills/skills/framework-critical-thinking/references/reasoning_validator.md +97 -0
  59. package/skills/skills/framework-critical-thinking/references/reflection_trigger.md +78 -0
  60. package/skills/skills/framework-critical-thinking/references/self_verification.md +388 -0
  61. package/skills/skills/framework-critical-thinking/references/uncertainty_quantifier.md +207 -0
  62. package/skills/skills/framework-initiative/SKILL.md +231 -0
  63. package/skills/skills/framework-initiative/references/examples.md +150 -0
  64. package/skills/skills/framework-initiative/references/impact-analysis.md +157 -0
  65. package/skills/skills/framework-initiative/references/intent-patterns.md +145 -0
  66. package/skills/skills/framework-initiative/references/star-framework.md +165 -0
  67. package/skills/skills/humanize-docs/SKILL.md +203 -0
  68. package/skills/skills/humanize-docs/references/advanced-techniques.md +13 -0
  69. package/skills/skills/humanize-docs/references/core-transformations.md +368 -0
  70. package/skills/skills/humanize-docs/references/detection-patterns.md +400 -0
  71. package/skills/skills/humanize-docs/references/examples-gallery.md +374 -0
  72. package/skills/skills/imagine/SKILL.md +190 -0
  73. package/skills/skills/imagine/references/artstyle-corporate-memphis.md +625 -0
  74. package/skills/skills/imagine/references/artstyle-crewdson-hyperrealism.md +295 -0
  75. package/skills/skills/imagine/references/artstyle-iphone-social-media.md +426 -0
  76. package/skills/skills/imagine/references/artstyle-sciencesaru.md +276 -0
  77. package/skills/skills/pre-deploy-checklist/README.md +26 -0
  78. package/skills/skills/pre-deploy-checklist/SKILL.md +153 -0
  79. package/skills/skills/pre-deploy-checklist/references/checklist-categories.md +174 -0
  80. package/skills/skills/pre-deploy-checklist/references/domain-prompts.md +216 -0
  81. package/skills/skills/prompt-engineering/SKILL.md +209 -0
  82. package/skills/skills/prompt-engineering/references/advanced-combinations.md +444 -0
  83. package/skills/skills/prompt-engineering/references/chain-of-thought.md +140 -0
  84. package/skills/skills/prompt-engineering/references/decision_matrix.md +220 -0
  85. package/skills/skills/prompt-engineering/references/few-shot.md +346 -0
  86. package/skills/skills/prompt-engineering/references/json-format.md +270 -0
  87. package/skills/skills/prompt-engineering/references/natural-language.md +420 -0
  88. package/skills/skills/prompt-engineering/references/pitfalls.md +365 -0
  89. package/skills/skills/prompt-engineering/references/prompt-chaining.md +498 -0
  90. package/skills/skills/prompt-engineering/references/react.md +108 -0
  91. package/skills/skills/prompt-engineering/references/self-consistency.md +322 -0
  92. package/skills/skills/prompt-engineering/references/tree-of-thoughts.md +386 -0
  93. package/skills/skills/prompt-engineering/references/xml-format.md +220 -0
  94. package/skills/skills/prompt-engineering/references/yaml-format.md +488 -0
  95. package/skills/skills/prompt-engineering/references/zero-shot.md +74 -0
  96. package/skills/skills/quick-spec/SKILL.md +280 -0
  97. package/skills/skills/quick-spec/assets/tech-spec-template.md +74 -0
  98. package/skills/skills/quick-spec/references/step-01-understand.md +189 -0
  99. package/skills/skills/quick-spec/references/step-02-investigate.md +144 -0
  100. package/skills/skills/quick-spec/references/step-03-generate.md +128 -0
  101. package/skills/skills/quick-spec/references/step-04-review.md +173 -0
  102. package/skills/skills/quick-spec/tests/__pycache__/test_skill.cpython-314-pytest-9.0.2.pyc +0 -0
  103. package/skills/skills/quick-spec/tests/test_scenarios.md +83 -0
  104. package/skills/skills/quick-spec/tests/test_skill.py +136 -0
  105. package/skills/skills/readme-expert/SKILL.md +538 -0
  106. package/skills/skills/readme-expert/knowledge/INDEX.md +192 -0
  107. package/skills/skills/readme-expert/knowledge/application/quality-standards.md +470 -0
  108. package/skills/skills/readme-expert/knowledge/application/script-executor.md +604 -0
  109. package/skills/skills/readme-expert/knowledge/application/template-library.md +822 -0
  110. package/skills/skills/readme-expert/knowledge/foundation/codebase-scanner.md +361 -0
  111. package/skills/skills/readme-expert/knowledge/foundation/validation-checklist.md +481 -0
  112. package/skills/skills/red-teaming/SKILL.md +321 -0
  113. package/skills/skills/red-teaming/references/ai-llm-redteam.md +517 -0
  114. package/skills/skills/red-teaming/references/attack-techniques.md +410 -0
  115. package/skills/skills/red-teaming/references/cybersecurity-redteam.md +383 -0
  116. package/skills/skills/red-teaming/references/tools-frameworks.md +446 -0
  117. package/skills/skills/releasing/.skillkit-mode +1 -0
  118. package/skills/skills/releasing/SKILL.md +225 -0
  119. package/skills/skills/releasing/references/version-detection.md +108 -0
  120. package/skills/skills/screenwriter/SKILL.md +273 -0
  121. package/skills/skills/screenwriter/references/advanced-techniques.md +216 -0
  122. package/skills/skills/screenwriter/references/pipeline-integration.md +266 -0
  123. package/skills/skills/skillkit/.claude/settings.local.json +7 -0
  124. package/skills/skills/skillkit/.claude-plugin/plugin.json +27 -0
  125. package/skills/skills/skillkit/CHANGELOG.md +484 -0
  126. package/skills/skills/skillkit/SKILL.md +511 -0
  127. package/skills/skills/skillkit/commands/skillkit.md +6 -0
  128. package/skills/skills/skillkit/commands/validate-plan.md +6 -0
  129. package/skills/skills/skillkit/commands/verify.md +6 -0
  130. package/skills/skills/skillkit/knowledge/INDEX.md +352 -0
  131. package/skills/skills/skillkit/knowledge/application/09-case-studies.md +257 -0
  132. package/skills/skills/skillkit/knowledge/application/10-technical-architecture.md +324 -0
  133. package/skills/skills/skillkit/knowledge/application/11-adoption-strategy.md +267 -0
  134. package/skills/skills/skillkit/knowledge/application/12-testing-and-validation.md +276 -0
  135. package/skills/skills/skillkit/knowledge/application/13-competitive-landscape.md +198 -0
  136. package/skills/skills/skillkit/knowledge/foundation/01-why-skills-exist.md +246 -0
  137. package/skills/skills/skillkit/knowledge/foundation/02-skills-vs-subagents-comparison.md +312 -0
  138. package/skills/skills/skillkit/knowledge/foundation/03-skills-vs-subagents-decision-tree.md +346 -0
  139. package/skills/skills/skillkit/knowledge/foundation/04-hybrid-patterns.md +308 -0
  140. package/skills/skills/skillkit/knowledge/foundation/05-token-economics.md +275 -0
  141. package/skills/skills/skillkit/knowledge/foundation/06-platform-constraints.md +237 -0
  142. package/skills/skills/skillkit/knowledge/foundation/07-security-concerns.md +322 -0
  143. package/skills/skills/skillkit/knowledge/foundation/08-when-not-to-use-skills.md +270 -0
  144. package/skills/skills/skillkit/knowledge/plugin-guide.md +614 -0
  145. package/skills/skills/skillkit/knowledge/tools/14-validation-tools-guide.md +150 -0
  146. package/skills/skills/skillkit/knowledge/tools/15-cost-tools-guide.md +157 -0
  147. package/skills/skills/skillkit/knowledge/tools/16-security-tools-guide.md +122 -0
  148. package/skills/skills/skillkit/knowledge/tools/17-pattern-tools-guide.md +161 -0
  149. package/skills/skills/skillkit/knowledge/tools/18-decision-helper-guide.md +243 -0
  150. package/skills/skills/skillkit/knowledge/tools/19-test-generator-guide.md +275 -0
  151. package/skills/skills/skillkit/knowledge/tools/20-split-skill-guide.md +149 -0
  152. package/skills/skills/skillkit/knowledge/tools/21-quality-scorer-guide.md +226 -0
  153. package/skills/skills/skillkit/knowledge/tools/22-migration-helper-guide.md +356 -0
  154. package/skills/skills/skillkit/knowledge/tools/23-subagent-creation-guide.md +448 -0
  155. package/skills/skills/skillkit/knowledge/tools/24-behavioral-testing-guide.md +122 -0
  156. package/skills/skills/skillkit/references/proposal-generation.md +982 -0
  157. package/skills/skills/skillkit/references/rationalization-catalog.md +75 -0
  158. package/skills/skills/skillkit/references/research-methodology.md +661 -0
  159. package/skills/skills/skillkit/references/section-2-full-creation-workflow.md +452 -0
  160. package/skills/skills/skillkit/references/section-3-validation-workflow-existing-skill.md +63 -0
  161. package/skills/skills/skillkit/references/section-4-decision-workflow-skills-vs-subagents.md +64 -0
  162. package/skills/skills/skillkit/references/section-5-migration-workflow-doc-to-skill.md +58 -0
  163. package/skills/skills/skillkit/references/section-6-subagent-creation-workflow.md +499 -0
  164. package/skills/skills/skillkit/references/section-7-knowledge-reference-map.md +72 -0
  165. package/skills/skills/skillkit/scripts/__pycache__/decision_helper.cpython-314.pyc +0 -0
  166. package/skills/skills/skillkit/scripts/__pycache__/quick_validate.cpython-312.pyc +0 -0
  167. package/skills/skills/skillkit/scripts/__pycache__/quick_validate.cpython-314.pyc +0 -0
  168. package/skills/skills/skillkit/scripts/__pycache__/test_generator.cpython-314-pytest-9.0.2.pyc +0 -0
  169. package/skills/skills/skillkit/scripts/decision_helper.py +799 -0
  170. package/skills/skills/skillkit/scripts/init_skill.py +400 -0
  171. package/skills/skills/skillkit/scripts/init_subagent.py +231 -0
  172. package/skills/skills/skillkit/scripts/migration_helper.py +669 -0
  173. package/skills/skills/skillkit/scripts/package_skill.py +211 -0
  174. package/skills/skills/skillkit/scripts/pattern_detector.py +381 -0
  175. package/skills/skills/skillkit/scripts/pattern_detector_new.py +382 -0
  176. package/skills/skills/skillkit/scripts/pressure_tester.py +157 -0
  177. package/skills/skills/skillkit/scripts/quality_scorer.py +999 -0
  178. package/skills/skills/skillkit/scripts/quick_validate.py +100 -0
  179. package/skills/skills/skillkit/scripts/security_scanner.py +474 -0
  180. package/skills/skills/skillkit/scripts/split_skill.py +540 -0
  181. package/skills/skills/skillkit/scripts/test_generator.py +695 -0
  182. package/skills/skills/skillkit/scripts/token_estimator.py +493 -0
  183. package/skills/skills/skillkit/scripts/utils/__init__.py +49 -0
  184. package/skills/skills/skillkit/scripts/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  185. package/skills/skills/skillkit/scripts/utils/__pycache__/__init__.cpython-314.pyc +0 -0
  186. package/skills/skills/skillkit/scripts/utils/__pycache__/budget_tracker.cpython-312.pyc +0 -0
  187. package/skills/skills/skillkit/scripts/utils/__pycache__/budget_tracker.cpython-314.pyc +0 -0
  188. package/skills/skills/skillkit/scripts/utils/__pycache__/output_formatter.cpython-312.pyc +0 -0
  189. package/skills/skills/skillkit/scripts/utils/__pycache__/output_formatter.cpython-314.pyc +0 -0
  190. package/skills/skills/skillkit/scripts/utils/__pycache__/reference_validator.cpython-312.pyc +0 -0
  191. package/skills/skills/skillkit/scripts/utils/__pycache__/reference_validator.cpython-314.pyc +0 -0
  192. package/skills/skills/skillkit/scripts/utils/budget_tracker.py +388 -0
  193. package/skills/skills/skillkit/scripts/utils/output_formatter.py +263 -0
  194. package/skills/skills/skillkit/scripts/utils/reference_validator.py +401 -0
  195. package/skills/skills/skillkit/scripts/validate_skill.py +594 -0
  196. package/skills/skills/skillkit/tests/test_behavioral.py +39 -0
  197. package/skills/skills/skillkit/tests/test_scenarios.md +83 -0
  198. package/skills/skills/skillkit/tests/test_skill.py +136 -0
  199. package/skills/skills/skillkit-help/SKILL.md +81 -0
  200. package/skills/skills/skillkit-help/knowledge/application/09-case-studies.md +257 -0
  201. package/skills/skills/skillkit-help/knowledge/application/12-testing-and-validation.md +276 -0
  202. package/skills/skills/skillkit-help/knowledge/foundation/01-why-skills-exist.md +246 -0
  203. package/skills/skills/skillkit-help/knowledge/foundation/02-skills-vs-subagents-comparison.md +312 -0
  204. package/skills/skills/skillkit-help/knowledge/foundation/03-skills-vs-subagents-decision-tree.md +346 -0
  205. package/skills/skills/skillkit-help/knowledge/foundation/06-platform-constraints.md +237 -0
  206. package/skills/skills/skillkit-help/knowledge/foundation/08-when-not-to-use-skills.md +270 -0
  207. package/skills/skills/skillkit-help/template/SKILL.md +52 -0
  208. package/skills/skills/social-media-seo/SKILL.md +278 -0
  209. package/skills/skills/social-media-seo/databases/caption-styles.csv +31 -0
  210. package/skills/skills/social-media-seo/databases/engagement-tactics.csv +16 -0
  211. package/skills/skills/social-media-seo/databases/hashtag-strategies.csv +21 -0
  212. package/skills/skills/social-media-seo/databases/hook-formulas.csv +26 -0
  213. package/skills/skills/social-media-seo/databases/keyword-clusters.csv +11 -0
  214. package/skills/skills/social-media-seo/databases/thread-structures.csv +26 -0
  215. package/skills/skills/social-media-seo/databases/viral-patterns.csv +21 -0
  216. package/skills/skills/social-media-seo/references/analytics-guide.md +321 -0
  217. package/skills/skills/social-media-seo/references/instagram-seo.md +235 -0
  218. package/skills/skills/social-media-seo/references/threads-seo.md +305 -0
  219. package/skills/skills/social-media-seo/references/x-twitter-seo.md +337 -0
  220. package/skills/skills/social-media-seo/scripts/query_database.py +191 -0
  221. package/skills/skills/storyteller/SKILL.md +241 -0
  222. package/skills/skills/storyteller/references/transformation-methodology.md +293 -0
  223. package/skills/skills/storyteller/references/visual-vocabulary.md +177 -0
  224. package/skills/skills/thread-pro/SKILL.md +162 -0
  225. package/skills/skills/thread-pro/anti-ai-patterns.md +120 -0
  226. package/skills/skills/thread-pro/hook-formulas.md +138 -0
  227. package/skills/skills/thread-pro/references/anti-ai-patterns.md +120 -0
  228. package/skills/skills/thread-pro/references/hook-formulas.md +138 -0
  229. package/skills/skills/thread-pro/references/thread-structures.md +240 -0
  230. package/skills/skills/thread-pro/references/voice-injection.md +130 -0
  231. package/skills/skills/thread-pro/thread-structures.md +240 -0
  232. package/skills/skills/thread-pro/voice-injection.md +130 -0
  233. package/skills/skills/tinkering/SKILL.md +251 -0
  234. package/skills/skills/tinkering/references/graduation-checklist.md +100 -0
  235. package/skills/skills/validate-plan/.skillkit-mode +1 -0
  236. package/skills/skills/validate-plan/SKILL.md +406 -0
  237. package/skills/skills/validate-plan/references/dry-principles.md +251 -0
  238. package/skills/skills/validate-plan/references/gap-analysis-guide.md +320 -0
  239. package/skills/skills/validate-plan/references/tdd-patterns.md +413 -0
  240. package/skills/skills/validate-plan/references/yagni-checklist.md +330 -0
  241. package/skills/skills/verify-before-ship/.skillkit-mode +1 -0
  242. package/skills/skills/verify-before-ship/SKILL.md +116 -0
  243. package/skills/skills/verify-before-ship/references/anti-rationalization.md +212 -0
  244. package/skills/skills/verify-before-ship/references/verification-gates.md +305 -0
  245. package/skills-manifest.json +8 -2
  246. package/src/picker.js +11 -5
  247. package/src/picker.test.js +36 -1
@@ -0,0 +1,239 @@
1
+ # Fallback Handler
2
+
3
+ ## Purpose
4
+
5
+ The Fallback Handler manages graceful degradation when the agent encounters situations it cannot handle, ensuring appropriate escalation to human oversight or alternative approaches.
6
+
7
+ ## Fallback Levels
8
+
9
+ ### Level 1: Alternative Approach
10
+
11
+ Try a different method before escalating.
12
+
13
+ ```python
14
+ class AlternativeApproachFallback:
15
+ def __init__(self, available_approaches):
16
+ self.approaches = available_approaches
17
+ self.attempted = []
18
+
19
+ def try_fallback(self, task, current_approach, failure_reason):
20
+ """Try alternative approach."""
21
+ for approach in self.approaches:
22
+ if approach not in self.attempted:
23
+ self.attempted.append(approach)
24
+ return {
25
+ 'action': 'try_alternative',
26
+ 'approach': approach,
27
+ 'reason': f"Switching from {current_approach} due to: {failure_reason}"
28
+ }
29
+
30
+ return {'action': 'escalate', 'reason': 'All approaches exhausted'}
31
+ ```
32
+
33
+ ### Level 2: Simplified Task
34
+
35
+ Decompose or simplify the task.
36
+
37
+ ```python
38
+ class SimplificationFallback:
39
+ def simplify(self, task):
40
+ """Create simplified version of task."""
41
+ simplifications = []
42
+
43
+ # Remove non-essential constraints
44
+ if 'constraints' in task:
45
+ essential_only = {
46
+ k: v for k, v in task['constraints'].items()
47
+ if v.get('essential', False)
48
+ }
49
+ simplifications.append({
50
+ 'type': 'reduced_constraints',
51
+ 'task': {**task, 'constraints': essential_only}
52
+ })
53
+
54
+ # Reduce scope
55
+ if 'scope' in task:
56
+ reduced_scope = self.reduce_scope(task['scope'])
57
+ simplifications.append({
58
+ 'type': 'reduced_scope',
59
+ 'task': {**task, 'scope': reduced_scope}
60
+ })
61
+
62
+ return simplifications
63
+
64
+ def try_simplified(self, task, agent):
65
+ """Try simplified versions."""
66
+ for simplified in self.simplify(task):
67
+ result = agent.attempt(simplified['task'])
68
+ if result['success']:
69
+ return {
70
+ 'action': 'use_simplified',
71
+ 'simplification_type': simplified['type'],
72
+ 'result': result
73
+ }
74
+
75
+ return {'action': 'escalate', 'reason': 'All simplifications failed'}
76
+ ```
77
+
78
+ ### Level 3: Partial Solution
79
+
80
+ Provide partial results with clear caveats.
81
+
82
+ ```python
83
+ class PartialSolutionFallback:
84
+ def create_partial_solution(self, progress, failed_components):
85
+ """Generate partial solution from progress."""
86
+ return {
87
+ 'action': 'provide_partial',
88
+ 'solution': {
89
+ 'completed_components': progress['completed'],
90
+ 'partial_results': progress['results'],
91
+ 'failed_components': failed_components,
92
+ 'confidence': progress['confidence']
93
+ },
94
+ 'caveats': [
95
+ f"Solution incomplete: {len(failed_components)} components failed",
96
+ "Results may not be fully valid",
97
+ "Human review strongly recommended"
98
+ ]
99
+ }
100
+ ```
101
+
102
+ ### Level 4: Human Handoff
103
+
104
+ Escalate to human operator.
105
+
106
+ ```python
107
+ class HumanHandoffFallback:
108
+ def prepare_handoff(self, task, failure_context, attempted_solutions):
109
+ """Prepare comprehensive handoff package."""
110
+ return {
111
+ 'action': 'human_handoff',
112
+ 'handoff_package': {
113
+ 'original_task': task,
114
+ 'failure_context': {
115
+ 'reason': failure_context['reason'],
116
+ 'step': failure_context['step'],
117
+ 'error': failure_context.get('error')
118
+ },
119
+ 'attempted_solutions': attempted_solutions,
120
+ 'current_state': failure_context.get('state'),
121
+ 'partial_results': failure_context.get('partial_results'),
122
+ 'recommended_action': failure_context.get('recommendation'),
123
+ 'urgency': self.assess_urgency(failure_context)
124
+ }
125
+ }
126
+
127
+ def assess_urgency(self, context):
128
+ """Assess urgency of handoff."""
129
+ if context.get('critical_path', False):
130
+ return 'critical'
131
+ if context.get('time_sensitive', False):
132
+ return 'high'
133
+ return 'normal'
134
+ ```
135
+
136
+ ## Fallback Decision Tree
137
+
138
+ ```
139
+ Agent encounters failure
140
+
141
+ ├─ Can try alternative approach?
142
+ │ └─ YES → Try alternative method
143
+ │ └─ Success? → Return result
144
+ │ └─ Fail? → Continue to next fallback
145
+
146
+ ├─ Can simplify task?
147
+ │ └─ YES → Try simplified version
148
+ │ └─ Success? → Return partial with caveats
149
+ │ └─ Fail? → Continue to next fallback
150
+
151
+ ├─ Has partial progress?
152
+ │ └─ YES → Return partial solution with warnings
153
+
154
+ └─ Handoff to human
155
+ ├─ Prepare context package
156
+ ├─ Escalate with priority
157
+ └─ Log for analysis
158
+ ```
159
+
160
+ ## Implementation
161
+
162
+ ```python
163
+ class FallbackHandler:
164
+ def __init__(self, config):
165
+ self.fallbacks = [
166
+ AlternativeApproachFallback(config['approaches']),
167
+ SimplificationFallback(),
168
+ PartialSolutionFallback(),
169
+ HumanHandoffFallback()
170
+ ]
171
+ self.max_fallback_depth = config.get('max_depth', 3)
172
+
173
+ def handle_failure(self, task, context, depth=0):
174
+ """Execute fallback chain."""
175
+ if depth >= self.max_fallback_depth:
176
+ return self.fallbacks[-1].prepare_handoff(
177
+ task, context, context.get('attempted', [])
178
+ )
179
+
180
+ for fallback in self.fallbacks:
181
+ result = fallback.try_fallback(task, context)
182
+
183
+ if result['action'] != 'escalate':
184
+ return result
185
+
186
+ # All fallbacks exhausted
187
+ return self.fallbacks[-1].prepare_handoff(
188
+ task, context, context.get('attempted', [])
189
+ )
190
+ ```
191
+
192
+ ## Handoff Context Package
193
+
194
+ What to include when handing off to humans:
195
+
196
+ ```python
197
+ HANDOFF_CONTEXT = {
198
+ 'task_description': 'Original task and requirements',
199
+ 'failure_point': 'Where and why the agent failed',
200
+ 'attempted_approaches': 'What was tried',
201
+ 'intermediate_results': 'What was successfully completed',
202
+ 'confidence_assessment': 'Agent confidence in partial results',
203
+ 'recommended_resolution': 'Agent suggestion for human',
204
+ 'time_constraints': 'Any deadlines or urgency',
205
+ 'domain_expertise_needed': 'What expertise is required'
206
+ }
207
+ ```
208
+
209
+ ## Usage Example
210
+
211
+ ```python
212
+ handler = FallbackHandler(config={
213
+ 'approaches': ['cot', 'tot', 'got'],
214
+ 'max_depth': 3
215
+ })
216
+
217
+ try:
218
+ result = agent.solve(task)
219
+ except AgentFailure as e:
220
+ fallback_result = handler.handle_failure(
221
+ task,
222
+ context={
223
+ 'reason': str(e),
224
+ 'step': e.step,
225
+ 'state': agent.current_state,
226
+ 'attempted': agent.attempted_approaches
227
+ }
228
+ )
229
+
230
+ if fallback_result['action'] == 'human_handoff':
231
+ escalate_to_human(fallback_result['handoff_package'])
232
+ else:
233
+ return fallback_result
234
+ ```
235
+
236
+ ---
237
+
238
+ **Sources:**
239
+ - [Graceful Degradation in AI Systems](https://www.microsoft.com/en-us/research/publication/graceful-degradation/)
@@ -0,0 +1,161 @@
1
+ # Memory Curator
2
+
3
+ ## Table of Contents
4
+
5
+ - [Purpose](#purpose)
6
+ - [Memory Types (CoALA Model)](#memory-types-coala-model)
7
+ - [Episodic Memory Structure](#episodic-memory-structure)
8
+ - [Quality Weighting System](#quality-weighting-system)
9
+ - [Memory Operations](#memory-operations)
10
+ - [Memory Consolidation](#memory-consolidation)
11
+ - [Experience Replay](#experience-replay)
12
+ - [Usage Example](#usage-example)
13
+ - [Best Practices](#best-practices)
14
+
15
+ ## Purpose
16
+
17
+ The Memory Curator manages episodic memory with quality weighting to enable agents to learn from past experiences while preventing memory pollution from unsuccessful episodes.
18
+
19
+ ## Memory Types (CoALA Model)
20
+
21
+ Following the CoALA (Cognitive Architectures for Language Agents) framework:
22
+
23
+ ```
24
+ ┌─────────────────────────────────────────────────────────────┐
25
+ │ Memory Systems │
26
+ ├──────────────┬──────────────┬──────────────┬────────────────┤
27
+ │ Working │ Episodic │ Semantic │ Procedural │
28
+ │ Memory │ Memory │ Memory │ Memory │
29
+ ├──────────────┼──────────────┼──────────────┼────────────────┤
30
+ │ - Current │ - Past │ - Facts │ - Skills │
31
+ │ context │ experiences│ - Concepts │ - Procedures │
32
+ │ - Active │ - Specific │ - Relations │ - Tool usage │
33
+ │ task │ episodes │ │ │
34
+ ├──────────────┼──────────────┼──────────────┼────────────────┤
35
+ │ Limited │ Large, │ Large, │ Learned │
36
+ │ capacity │ selectable │ queryable │ patterns │
37
+ └──────────────┴──────────────┴──────────────┴────────────────┘
38
+ ```
39
+
40
+ This module focuses primarily on **Episodic Memory** management.
41
+
42
+ ## Episodic Memory Structure
43
+
44
+ ```python
45
+ class EpisodicMemory:
46
+ def __init__(self):
47
+ self.episodes = []
48
+
49
+ class Episode:
50
+ def __init__(self):
51
+ self.id = generate_id()
52
+ self.timestamp = datetime.now()
53
+ self.task = None
54
+ self.reasoning_trace = []
55
+ self.outcome = None
56
+ self.quality_score = 0.0
57
+ self.retrieval_count = 0
58
+ self.last_accessed = None
59
+ self.tags = []
60
+ self.embedding = None
61
+ ```
62
+
63
+ ## Quality Weighting System
64
+
65
+ ### Scoring Dimensions
66
+
67
+ ```python
68
+ class QualityScorer:
69
+ def score_episode(self, episode):
70
+ scores = {
71
+ 'outcome_success': self.outcome_score(episode),
72
+ 'reasoning_quality': self.reasoning_score(episode),
73
+ 'efficiency': self.efficiency_score(episode),
74
+ 'reusability': self.reusability_score(episode)
75
+ }
76
+
77
+ # Weighted combination
78
+ weights = {
79
+ 'outcome_success': 0.4,
80
+ 'reasoning_quality': 0.3,
81
+ 'efficiency': 0.2,
82
+ 'reusability': 0.1
83
+ }
84
+
85
+ episode.quality_score = sum(
86
+ scores[k] * weights[k] for k in scores
87
+ )
88
+
89
+ return episode.quality_score
90
+ ```
91
+
92
+ ### Quality Tiers
93
+
94
+ ```python
95
+ QUALITY_TIERS = {
96
+ 'exemplar': (0.9, 1.0), # Always retain, priority retrieval
97
+ 'good': (0.7, 0.9), # Standard retention
98
+ 'acceptable': (0.5, 0.7), # Conditional retention
99
+ 'poor': (0.0, 0.5) # Flag for review or discard
100
+ }
101
+ ```
102
+
103
+ ## Memory Operations
104
+
105
+ ### Storage
106
+
107
+ ```python
108
+ def store_episode(self, task, reasoning_trace, outcome):
109
+ episode = Episode()
110
+ episode.task = task
111
+ episode.reasoning_trace = reasoning_trace
112
+ episode.outcome = outcome
113
+ episode.embedding = self.compute_embedding(task + " " + str(reasoning_trace))
114
+ episode.quality_score = self.quality_scorer.score_episode(episode)
115
+ episode.tags = self.auto_tag(task, reasoning_trace)
116
+
117
+ if self.should_retain(episode):
118
+ self.episodes.append(episode)
119
+ self.maintain_capacity()
120
+
121
+ return episode
122
+ ```
123
+
124
+ ### Retrieval
125
+
126
+ ```python
127
+ def retrieve_similar(self, query, k=5, quality_threshold=0.6):
128
+ query_embedding = self.compute_embedding(query)
129
+ scored_episodes = []
130
+
131
+ for episode in self.episodes:
132
+ if episode.quality_score < quality_threshold:
133
+ continue
134
+ similarity = cosine_similarity(query_embedding, episode.embedding)
135
+ adjusted_score = similarity * (0.5 + 0.5 * episode.quality_score)
136
+ scored_episodes.append((episode, adjusted_score))
137
+
138
+ scored_episodes.sort(key=lambda x: x[1], reverse=True)
139
+ return [ep for ep, _ in scored_episodes[:k]]
140
+ ```
141
+
142
+ ## Usage Example
143
+
144
+ ```python
145
+ curator = MemoryCurator(max_episodes=1000, quality_threshold=0.5)
146
+
147
+ # Store experience
148
+ episode = curator.store_episode(
149
+ task="Solve differential equation",
150
+ reasoning_trace=[...],
151
+ outcome={'success': True, 'quality': 0.9}
152
+ )
153
+
154
+ # Retrieve similar
155
+ similar = curator.retrieve_similar("Solve differential equation", k=3)
156
+ ```
157
+
158
+ ---
159
+
160
+ **Sources:**
161
+ - [Cognitive Architectures for Language Agents (CoALA)](https://arxiv.org/abs/2309.02427)
@@ -0,0 +1,297 @@
1
+ # Metacognitive Monitor
2
+
3
+ ## Purpose
4
+
5
+ The Metacognitive Monitor provides self-assessment and error detection capabilities for AI agents. It implements the Producer-Critic pattern to continuously evaluate the quality of reasoning and trigger corrective actions when needed.
6
+
7
+ ## Architecture
8
+
9
+ ### Producer-Critic Pattern
10
+
11
+ ```
12
+ ┌─────────────────────────────────────────────────────────────┐
13
+ │ Master Agent │
14
+ └──────────────┬──────────────────────────────┬───────────────┘
15
+ │ │
16
+ ▼ ▼
17
+ ┌──────────────────────┐ ┌──────────────────────┐
18
+ │ Producer Agent │ │ Critic Agent │
19
+ │ (Generate) │ │ (Evaluate) │
20
+ └──────────┬───────────┘ └──────────┬───────────┘
21
+ │ │
22
+ │ ┌──────────────┐ │
23
+ └────────►│ Output │◄───────┘
24
+ │ Quality │
25
+ └──────────────┘
26
+
27
+
28
+ ┌──────────────┐
29
+ │ Decision │
30
+ │ Continue / │
31
+ │ Refine / │
32
+ │ Handoff │
33
+ └──────────────┘
34
+ ```
35
+
36
+ ### Components
37
+
38
+ #### 1. Confidence Scorer
39
+
40
+ Evaluates confidence at multiple levels:
41
+
42
+ ```python
43
+ class ConfidenceScorer:
44
+ def assess_step(self, reasoning_step):
45
+ return {
46
+ 'certainty_score': self.compute_certainty(reasoning_step),
47
+ 'consistency_check': self.check_internal_consistency(reasoning_step),
48
+ 'grounding_score': self.verify_grounding(reasoning_step),
49
+ 'overall_confidence': weighted_average([
50
+ certainty * 0.4,
51
+ consistency * 0.3,
52
+ grounding * 0.3
53
+ ])
54
+ }
55
+ ```
56
+
57
+ **Scoring dimensions:**
58
+ - **Certainty:** How definitive is the statement? (0.0 - 1.0)
59
+ - **Consistency:** Does it align with previous steps?
60
+ - **Grounding:** Is it supported by evidence/context?
61
+
62
+ #### 2. Anomaly Detector
63
+
64
+ Identifies unusual patterns in reasoning:
65
+
66
+ ```python
67
+ class AnomalyDetector:
68
+ def detect(self, thought_history):
69
+ anomalies = []
70
+
71
+ # Pattern 1: Sudden topic shift
72
+ if self.topic_coherence_score(thought_history) < 0.5:
73
+ anomalies.append(Anomaly.TOPIC_DRIFT)
74
+
75
+ # Pattern 2: Repetitive reasoning
76
+ if self.repetition_detected(thought_history):
77
+ anomalies.append(Anomaly.LOOPING)
78
+
79
+ # Pattern 3: Confidence degradation
80
+ if self.confidence_trend(thought_history) == 'decreasing':
81
+ anomalies.append(Anomaly.DEGRADING_QUALITY)
82
+
83
+ # Pattern 4: Contradiction emergence
84
+ if self.find_contradictions(thought_history):
85
+ anomalies.append(Anomaly.CONTRADICTION)
86
+
87
+ return anomalies
88
+ ```
89
+
90
+ #### 3. Reflection Controller
91
+
92
+ Manages when and how to trigger reflection:
93
+
94
+ ```python
95
+ class ReflectionController:
96
+ def __init__(self):
97
+ self.reflection_budget = 3 # Max reflections per task
98
+ self.min_confidence_threshold = 0.7
99
+ self.criticality_boost = 1.2 # Multiply threshold for critical tasks
100
+
101
+ def should_reflect(self, current_state):
102
+ if self.reflection_budget <= 0:
103
+ return False, "Budget exhausted"
104
+
105
+ adjusted_threshold = self.min_confidence_threshold
106
+ if current_state.task_criticality == 'HIGH':
107
+ adjusted_threshold *= self.criticality_boost
108
+
109
+ if current_state.confidence < adjusted_threshold:
110
+ return True, f"Confidence {current_state.confidence} below threshold {adjusted_threshold}"
111
+
112
+ if current_state.anomalies_detected:
113
+ return True, f"Anomalies detected: {current_state.anomalies}"
114
+
115
+ return False, "No reflection needed"
116
+ ```
117
+
118
+ ## Implementation
119
+
120
+ ### Basic Monitor Setup
121
+
122
+ ```python
123
+ class MetacognitiveMonitor:
124
+ def __init__(self, config):
125
+ self.confidence_scorer = ConfidenceScorer()
126
+ self.anomaly_detector = AnomalyDetector()
127
+ self.reflection_controller = ReflectionController(config)
128
+ self.thought_history = []
129
+
130
+ def monitor(self, current_step, context):
131
+ # Score the current step
132
+ confidence = self.confidence_scorer.assess_step(current_step)
133
+
134
+ # Update history
135
+ self.thought_history.append({
136
+ 'step': current_step,
137
+ 'confidence': confidence,
138
+ 'timestamp': now()
139
+ })
140
+
141
+ # Detect anomalies
142
+ anomalies = self.anomaly_detector.detect(self.thought_history)
143
+
144
+ # Create state snapshot
145
+ state = MonitorState(
146
+ confidence=confidence['overall_confidence'],
147
+ anomalies=anomalies,
148
+ thought_count=len(self.thought_history),
149
+ task_criticality=context.criticality
150
+ )
151
+
152
+ # Decide on action
153
+ should_reflect, reason = self.reflection_controller.should_reflect(state)
154
+
155
+ return MonitorResult(
156
+ confidence=confidence,
157
+ anomalies=anomalies,
158
+ should_reflect=should_reflect,
159
+ reflection_reason=reason,
160
+ recommended_action=self.determine_action(state, should_reflect)
161
+ )
162
+
163
+ def determine_action(self, state, should_reflect):
164
+ if state.confidence < 0.3:
165
+ return Action.HUMAN_HANDOFF
166
+ elif should_reflect:
167
+ return Action.REFLECT_AND_REFINE
168
+ elif state.anomalies:
169
+ return Action.REVIEW_ANOMALIES
170
+ else:
171
+ return Action.CONTINUE
172
+ ```
173
+
174
+ ### Confidence Calibration
175
+
176
+ Calibrate confidence scores to match actual accuracy:
177
+
178
+ ```python
179
+ def calibrate_confidence(raw_confidence, task_type):
180
+ # Use historical performance data
181
+ calibration_map = {
182
+ 'arithmetic': lambda x: x * 0.95, # Usually overconfident
183
+ 'reasoning': lambda x: x * 0.85, # Often overconfident
184
+ 'creative': lambda x: x * 0.70, # Highly overconfident
185
+ 'factual': lambda x: min(x * 1.1, 1.0) # Often underconfident
186
+ }
187
+
188
+ calibrator = calibration_map.get(task_type, lambda x: x)
189
+ return calibrator(raw_confidence)
190
+ ```
191
+
192
+ ## Monitoring Heuristics
193
+
194
+ ### 1. Reasoning Quality Indicators
195
+
196
+ **Positive indicators:**
197
+ - Progressive narrowing of solution space
198
+ - Increasing specificity in claims
199
+ - Consistent terminology usage
200
+ - Appropriate uncertainty acknowledgment
201
+
202
+ **Negative indicators:**
203
+ - Circular reasoning
204
+ - Unjustified leaps
205
+ - Confusing correlation with causation
206
+ - Overgeneralization
207
+
208
+ ### 2. Confidence-Accuracy Correlation
209
+
210
+ Track the relationship between stated confidence and actual correctness:
211
+
212
+ ```python
213
+ def compute_calibration_error(confidence_history, accuracy_history):
214
+ # Perfect calibration: confidence == accuracy
215
+ # Overconfidence: confidence > accuracy
216
+ # Underconfidence: confidence < accuracy
217
+
218
+ expected_accuracy = sum(confidence_history) / len(confidence_history)
219
+ actual_accuracy = sum(accuracy_history) / len(accuracy_history)
220
+
221
+ return abs(expected_accuracy - actual_accuracy)
222
+ ```
223
+
224
+ ## Human Handoff Protocols
225
+
226
+ ### When to Handoff
227
+
228
+ | Condition | Threshold | Action |
229
+ |-----------|-----------|--------|
230
+ | Very low confidence | < 0.3 | Immediate handoff |
231
+ | Repeated reflection failures | > 3 attempts | Handoff with context |
232
+ | Critical task + uncertainty | Confidence < 0.8 | Request verification |
233
+ | Anomaly cluster | > 2 anomalies | Handoff for review |
234
+
235
+ ### Handoff Context
236
+
237
+ Include in handoff:
238
+ - Current reasoning chain
239
+ - Confidence trajectory
240
+ - Detected anomalies
241
+ - Attempted corrections
242
+ - Specific uncertainty points
243
+
244
+ ## Usage Example
245
+
246
+ ```python
247
+ # Initialize monitor
248
+ monitor = MetacognitiveMonitor(config={
249
+ 'reflection_budget': 3,
250
+ 'confidence_threshold': 0.7,
251
+ 'enable_human_handoff': True
252
+ })
253
+
254
+ # Use in agent loop
255
+ for step in reasoning_process:
256
+ result = monitor.monitor(step, context={'criticality': 'HIGH'})
257
+
258
+ if result.recommended_action == Action.HUMAN_HANDOFF:
259
+ await handoff_to_human(result)
260
+ break
261
+
262
+ elif result.recommended_action == Action.REFLECT_AND_REFINE:
263
+ reflection = generate_reflection(result.anomalies)
264
+ refined_step = refine_with_reflection(step, reflection)
265
+ step = refined_step
266
+
267
+ elif result.recommended_action == Action.REVIEW_ANOMALIES:
268
+ for anomaly in result.anomalies:
269
+ log_warning(f"Anomaly detected: {anomaly}")
270
+
271
+ # Continue with (possibly refined) step
272
+ execute(step)
273
+ ```
274
+
275
+ ## Performance Metrics
276
+
277
+ Track these metrics to evaluate monitor effectiveness:
278
+
279
+ 1. **False Positive Rate:** Reflection triggered when not needed
280
+ 2. **False Negative Rate:** Missed errors that should have been caught
281
+ 3. **Calibration Error:** Difference between confidence and accuracy
282
+ 4. **Reflection Success Rate:** % of reflections that improve output
283
+ 5. **Average Reflections per Task:** Efficiency measure
284
+
285
+ ## Best Practices
286
+
287
+ 1. **Start with high thresholds** and gradually lower based on performance
288
+ 2. **Log all monitoring decisions** for post-hoc analysis
289
+ 3. **Calibrate confidence** per task type using historical data
290
+ 4. **Respect the reflection budget** to avoid infinite loops
291
+ 5. **Provide clear handoff reasons** for human reviewers
292
+
293
+ ---
294
+
295
+ **Sources:**
296
+ - [Self-Corrective Agent Architecture](https://www.emergentmind.com/topics/self-corrective-agent-architecture)
297
+ - [Building Metacognitive AI Agents](https://rewire.it/blog/building-metacognitive-ai-agents-complete-guide/)