Class: Legion::MCP::Tools::PlanAction
- Inherits:
-
MCP::Tool
- Object
- MCP::Tool
- Legion::MCP::Tools::PlanAction
- Extended by:
- Logging::Helper
- Defined in:
- lib/legion/mcp/tools/plan_action.rb
Class Method Summary collapse
-
.call(goal:, context: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
Class Method Details
.call(goal:, context: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/legion/mcp/tools/plan_action.rb', line 21 def call(goal:, context: {}) # rubocop:disable Lint/UnusedMethodArgument log.info('Starting legion.mcp.tools.plan_action.call') matched = ContextCompiler.match_tools(goal, limit: 10) steps = matched.map.with_index(1) do |tool, idx| { step: idx, tool: tool[:name], relevance: tool[:score].round(3) } end return text_response({ plan: nil, reason: 'no matching tools found for goal' }) if steps.empty? plan = { goal: goal, steps: steps, tool_count: steps.size } plan[:narrative] = generate_narrative(goal, steps) if llm_available? text_response(plan) rescue StandardError => e handle_exception(e, level: :warn, operation: 'legion.mcp.tools.plan_action.call') log.warn("PlanAction#call failed: #{e.}") error_response("Plan failed: #{e.}") end |