Module: Clacky::Agent::SkillReflector

Included in:
Clacky::Agent
Defined in:
lib/clacky/agent/skill_reflector.rb

Overview

Scenario 2: Reflect on skill execution and suggest improvements.

After a skill completes, forks a subagent to analyze:

- Were instructions clear enough?
- Any missing edge cases?
- Any improvements needed?

If the LLM identifies concrete improvements, it invokes skill-creator to update the skill.

Constant Summary collapse

MIN_SKILL_ITERATIONS =

Minimum iterations for a skill execution to warrant reflection. Raised to 5 to filter out lightweight skill invocations (e.g. platform management skills like cron-task-creator that the user triggered incidentally).

5

Instance Method Summary collapse

Instance Method Details

#maybe_reflect_on_skillObject

Check if we should reflect on the skill that just executed Called from SkillEvolution#run_skill_evolution_hooks



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/clacky/agent/skill_reflector.rb', line 22

def maybe_reflect_on_skill
  return unless @skill_execution_context

  # Only reflect on skills that the user explicitly invoked via slash command.
  # Skills triggered by the LLM itself (e.g. as part of a broader task) or
  # platform-management skills invoked incidentally should not be reflected on.
  return unless @skill_execution_context[:slash_command]

  # Skip default and brand skills — they are system-owned and should not be
  # auto-improved by the evolution system.
  source = @skill_execution_context[:source]
  return if source == :default || source == :brand

  skill_name = @skill_execution_context[:skill_name]
  start_iteration = @skill_execution_context[:start_iteration]
  iterations = @iterations - start_iteration

  # Only reflect if the skill actually ran for a meaningful number of iterations
  return if iterations < MIN_SKILL_ITERATIONS

  # Fork an isolated subagent to reflect + improve — does NOT touch main history
  @ui&.show_info("Reflecting on skill execution: #{skill_name}")
  subagent = fork_subagent
  subagent.run(build_skill_reflection_prompt(skill_name, iterations))

  # Clear the context so we don't reflect again
  @skill_execution_context = nil
end