Module: Legion::MCP::PatternCompiler
- Extended by:
- Logging::Helper
- Defined in:
- lib/legion/mcp/pattern_compiler.rb
Class Method Summary collapse
Class Method Details
.compile_tool_definitions ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/legion/mcp/pattern_compiler.rb', line 10 def compile_tool_definitions return [] unless defined?(Legion::MCP::Server) Legion::MCP::Server.tool_registry.map do |klass| name = klass.respond_to?(:tool_name) ? klass.tool_name : klass.name desc = klass.respond_to?(:description) ? klass.description : '' params = extract_params(klass) compressed = "#{name}(#{params.join(', ')}) -- #{desc.split('.').first}" { name: name, compressed: compressed.slice(0, 200), full_description: desc } end end |
.compile_workflows ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/legion/mcp/pattern_compiler.rb', line 23 def compile_workflows PatternStore.patterns.filter_map do |_hash, pattern| next if (pattern[:confidence] || 0) < 0.6 { intent: pattern[:intent_text], tools: pattern[:tool_chain], confidence: pattern[:confidence], template: pattern[:response_template] } end end |
.extract_params(klass) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/legion/mcp/pattern_compiler.rb', line 36 def extract_params(klass) return [] unless klass.respond_to?(:input_schema) schema = klass.input_schema props = if schema.is_a?(Hash) schema[:properties] || schema['properties'] elsif schema.respond_to?(:to_h) schema.to_h[:properties] end return [] unless props props.keys.map(&:to_s) rescue StandardError => e handle_exception(e, level: :warn, operation: 'legion.mcp.pattern_compiler.extract_params') log.warn("PatternCompiler#extract_params failed: #{e.}") [] end |