Class: KairosMcp::Tools::FormalizationRecord

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/kairos_mcp/tools/formalization_record.rb

Instance Method Summary collapse

Methods inherited from BaseTool

#initialize, #invoke_tool, #to_full_schema, #to_schema

Constructor Details

This class inherits a constructor from KairosMcp::Tools::BaseTool

Instance Method Details

#call(arguments) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/kairos_mcp/tools/formalization_record.rb', line 94

def call(arguments)
  # Validate required fields
  %w[skill_id skill_version source_text result rationale formalization_category].each do |field|
    unless arguments[field] && !arguments[field].to_s.empty?
      return text_content("Error: #{field} is required")
    end
  end

  # Validate result value
  unless %w[formalized not_formalized].include?(arguments['result'])
    return text_content("Error: result must be 'formalized' or 'not_formalized'")
  end

  # Validate formalization_category
  valid_categories = %w[invariant rule guideline policy philosophy]
  unless valid_categories.include?(arguments['formalization_category'])
    return text_content("Error: formalization_category must be one of: #{valid_categories.join(', ')}")
  end

  # Build the decision
  decision = KairosChain::FormalizationDecision.new(
    skill_id: arguments['skill_id'],
    skill_version: arguments['skill_version'],
    source_text: arguments['source_text'],
    source_span: arguments['source_span'],
    result: arguments['result'].to_sym,
    rationale: arguments['rationale'],
    formalization_category: arguments['formalization_category'].to_sym,
    ambiguity_before: arguments['ambiguity_before']&.to_sym,
    ambiguity_after: arguments['ambiguity_after']&.to_sym,
    decided_by: (arguments['decided_by'] || 'human').to_sym,
    model: arguments['model'],
    confidence: arguments['confidence']&.to_f
  )

  # Record to blockchain
  chain = KairosChain::Chain.new
  new_block = chain.add_block([decision.to_json])

  output = "## Formalization Decision Recorded\n\n"
  output += "**Block**: ##{new_block.index}\n"
  output += "**Hash**: #{new_block.hash[0..15]}...\n"
  output += "**Skill**: #{arguments['skill_id']} v#{arguments['skill_version']}\n"
  output += "**Result**: #{arguments['result']}\n"
  output += "**Category**: #{arguments['formalization_category']}\n"
  output += "**Rationale**: #{arguments['rationale']}\n"

  text_content(output)
end

#categoryObject



16
17
18
# File 'lib/kairos_mcp/tools/formalization_record.rb', line 16

def category
  :chain
end

#descriptionObject



12
13
14
# File 'lib/kairos_mcp/tools/formalization_record.rb', line 12

def description
  'Record a formalization decision to the blockchain. Documents why a piece of natural language was (or was not) converted to a formal AST node.'
end

#examplesObject



24
25
26
27
28
29
30
31
# File 'lib/kairos_mcp/tools/formalization_record.rb', line 24

def examples
  [
    {
      title: 'Record a formalization decision',
      code: 'formalization_record(skill_id: "core_safety", skill_version: "1.1", source_text: "Evolution is disabled by default", result: "formalized", rationale: "Binary condition, measurable", formalization_category: "invariant")'
    }
  ]
end

#input_schemaObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/kairos_mcp/tools/formalization_record.rb', line 37

def input_schema
  {
    type: 'object',
    properties: {
      skill_id: {
        type: 'string',
        description: 'The skill ID this decision applies to'
      },
      skill_version: {
        type: 'string',
        description: 'The skill version at the time of this decision'
      },
      source_text: {
        type: 'string',
        description: 'The natural language text being evaluated for formalization'
      },
      result: {
        type: 'string',
        description: 'Whether the text was formalized: "formalized" or "not_formalized"'
      },
      rationale: {
        type: 'string',
        description: 'Why this formalization decision was made'
      },
      formalization_category: {
        type: 'string',
        description: 'Category on the formalization spectrum: invariant, rule, guideline, policy, or philosophy'
      },
      source_span: {
        type: 'string',
        description: 'The original text span in the content (optional)'
      },
      ambiguity_before: {
        type: 'string',
        description: 'Ambiguity level before formalization: none, low, medium, high (optional)'
      },
      ambiguity_after: {
        type: 'string',
        description: 'Ambiguity level after formalization: none, low, medium, high (optional)'
      },
      decided_by: {
        type: 'string',
        description: 'Who made the decision: human, ai, or collaborative (default: human)'
      },
      model: {
        type: 'string',
        description: 'LLM model used if AI-assisted (optional)'
      },
      confidence: {
        type: 'number',
        description: 'Confidence score 0.0-1.0 (optional)'
      }
    },
    required: %w[skill_id skill_version source_text result rationale formalization_category]
  }
end

#nameObject



8
9
10
# File 'lib/kairos_mcp/tools/formalization_record.rb', line 8

def name
  'formalization_record'
end


33
34
35
# File 'lib/kairos_mcp/tools/formalization_record.rb', line 33

def related_tools
  %w[formalization_history skills_dsl_get chain_history]
end

#usecase_tagsObject



20
21
22
# File 'lib/kairos_mcp/tools/formalization_record.rb', line 20

def usecase_tags
  %w[formalization record decision DSL AST blockchain provenance]
end