Class: Ask::Agent::MetaAgent
- Inherits:
-
Object
- Object
- Ask::Agent::MetaAgent
- Defined in:
- lib/ask/agent/meta_agent.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #analyze(error_threshold: 3, loop_threshold: 2, max_turns_threshold: 2) ⇒ Object
- #auto_resolve! ⇒ Object
- #generate_report(results = nil) ⇒ Object
-
#initialize(telemetry: nil, model: nil, **chat_options) ⇒ MetaAgent
constructor
A new instance of MetaAgent.
- #track_resolution(recommendation_id) ⇒ Object
Constructor Details
#initialize(telemetry: nil, model: nil, **chat_options) ⇒ MetaAgent
Returns a new instance of MetaAgent.
11 12 13 14 15 16 |
# File 'lib/ask/agent/meta_agent.rb', line 11 def initialize(telemetry: nil, model: nil, **) @telemetry = telemetry || Telemetry.new @model = model || Ask::Agent.configuration.default_model @chat_options = @agent_source = nil end |
Instance Method Details
#analyze(error_threshold: 3, loop_threshold: 2, max_turns_threshold: 2) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ask/agent/meta_agent.rb', line 18 def analyze(error_threshold: 3, loop_threshold: 2, max_turns_threshold: 2) load_source telemetry_data = @telemetry.read resolved_ids = resolved_recommendation_ids recommendations = @telemetry.read_recommendations(status: "open") unless has_data?(telemetry_data, error_threshold, loop_threshold, max_turns_threshold) return [] end results = call_llm_for_analysis(telemetry_data, recommendations, resolved_ids) return [] if results.empty? results.each do |r| r[:recommendation_id] = @telemetry.track_recommendation(build_result(r)) end results.map { |r| build_result(r) } end |
#auto_resolve! ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ask/agent/meta_agent.rb', line 74 def auto_resolve! load_source count = 0 @telemetry.read_recommendations(status: "open").each do |rec| source = @agent_source[rec["file"]] next unless source && rec["suggested_code"] if source.include?(rec["suggested_code"].strip) @telemetry.track_resolution(rec["recommendation_id"]) count += 1 end end count end |
#generate_report(results = nil) ⇒ Object
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 |
# File 'lib/ask/agent/meta_agent.rb', line 38 def generate_report(results = nil) results ||= analyze return "No improvement opportunities found." if results.empty? lines = [] lines << "# Agent Self-Improvement Report" lines << "*Generated: #{Time.now.utc.iso8601}*" lines << "" results.each_with_index do |result, i| lines << "## #{i + 1}. #{result.issue}" lines << "" lines << "| | |" lines << "|---|---|" lines << "| **File** | `#{result.file}:#{result.line}` |" lines << "| **Confidence** | #{result.confidence} |" lines << "| **Recommendation ID** | `#{result.recommendation_id}` |" lines << "" if result.suggested_code lines << "### Suggested Code" lines << "" lines << "```ruby" lines << result.suggested_code lines << "```" end lines << "---" end lines.join("\n") end |
#track_resolution(recommendation_id) ⇒ Object
69 70 71 72 |
# File 'lib/ask/agent/meta_agent.rb', line 69 def track_resolution(recommendation_id) return false unless recommendation_id @telemetry.track_resolution(recommendation_id) end |