Module: Legion::Extensions::Agentic::Social::Apprenticeship::Runners::CognitiveApprenticeship

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb

Instance Method Summary collapse

Instance Method Details

#active_apprenticeshipsObject



67
68
69
70
71
# File 'lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb', line 67

def active_apprenticeships(**)
  list = engine.active_apprenticeships
  log.debug "[cognitive_apprenticeship] active count=#{list.size}"
  { success: true, apprenticeships: list.map(&:to_h), count: list.size }
end

#apprentice_apprenticeships(apprentice_id:) ⇒ Object



79
80
81
82
83
# File 'lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb', line 79

def apprentice_apprenticeships(apprentice_id:, **)
  list = engine.by_apprentice(apprentice_id: apprentice_id)
  log.debug "[cognitive_apprenticeship] apprentice=#{apprentice_id} count=#{list.size}"
  { success: true, apprentice_id: apprentice_id, apprenticeships: list.map(&:to_h), count: list.size }
end

#cognitive_apprenticeship_statsObject



95
96
97
98
99
# File 'lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb', line 95

def cognitive_apprenticeship_stats(**)
  stats = engine.to_h
  log.debug "[cognitive_apprenticeship] stats=#{stats.inspect}"
  { success: true }.merge(stats)
end

#conduct_apprenticeship_session(apprenticeship_id:, method:, success:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb', line 32

def conduct_apprenticeship_session(apprenticeship_id:, method:, success:, **)
  return { success: false, reason: :invalid_method } unless Helpers::ApprenticeshipModel::METHODS.include?(method.to_sym)

  appr = engine.conduct_session(
    apprenticeship_id: apprenticeship_id,
    method:            method.to_sym,
    success:           success
  )

  if appr
    log.debug "[cognitive_apprenticeship] session id=#{apprenticeship_id} method=#{method} " \
              "success=#{success} mastery=#{appr.mastery.round(3)}"
    { success: true, apprenticeship: appr.to_h }
  else
    { success: false, reason: :not_found }
  end
end

#create_apprenticeship(skill_name:, domain:, mentor_id:, apprentice_id:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb', line 13

def create_apprenticeship(skill_name:, domain:, mentor_id:, apprentice_id:, **)
  return { success: false, reason: :param_too_short } if [skill_name, domain, mentor_id, apprentice_id].any? { |p| p.to_s.length < 3 }

  appr = engine.create_apprenticeship(
    skill_name:    skill_name,
    domain:        domain,
    mentor_id:     mentor_id,
    apprentice_id: apprentice_id
  )

  if appr
    log.info "[cognitive_apprenticeship] created id=#{appr.id} skill=#{skill_name} domain=#{domain}"
    { success: true, apprenticeship: appr.to_h }
  else
    log.warn '[cognitive_apprenticeship] create failed: capacity reached'
    { success: false, reason: :capacity_reached }
  end
end

#domain_apprenticeships(domain:) ⇒ Object



85
86
87
88
89
# File 'lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb', line 85

def domain_apprenticeships(domain:, **)
  list = engine.by_domain(domain: domain)
  log.debug "[cognitive_apprenticeship] domain=#{domain} count=#{list.size}"
  { success: true, domain: domain, apprenticeships: list.map(&:to_h), count: list.size }
end

#graduated_apprenticeshipsObject



61
62
63
64
65
# File 'lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb', line 61

def graduated_apprenticeships(**)
  list = engine.graduated_apprenticeships
  log.debug "[cognitive_apprenticeship] graduated count=#{list.size}"
  { success: true, apprenticeships: list.map(&:to_h), count: list.size }
end

#mentor_apprenticeships(mentor_id:) ⇒ Object



73
74
75
76
77
# File 'lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb', line 73

def mentor_apprenticeships(mentor_id:, **)
  list = engine.by_mentor(mentor_id: mentor_id)
  log.debug "[cognitive_apprenticeship] mentor=#{mentor_id} count=#{list.size}"
  { success: true, mentor_id: mentor_id, apprenticeships: list.map(&:to_h), count: list.size }
end

#recommend_apprenticeship_method(apprenticeship_id:) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb', line 50

def recommend_apprenticeship_method(apprenticeship_id:, **)
  method = engine.recommend_method(apprenticeship_id: apprenticeship_id)

  if method
    log.debug "[cognitive_apprenticeship] recommend id=#{apprenticeship_id} method=#{method}"
    { success: true, apprenticeship_id: apprenticeship_id, recommended_method: method }
  else
    { success: false, reason: :not_found }
  end
end

#update_cognitive_apprenticeship(apprenticeship_id:, method:, success:) ⇒ Object



91
92
93
# File 'lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb', line 91

def update_cognitive_apprenticeship(apprenticeship_id:, method:, success:, **)
  conduct_apprenticeship_session(apprenticeship_id: apprenticeship_id, method: method, success: success)
end