Class: DecisionAgent::Monitoring::MonitoredAgent
- Inherits:
-
Object
- Object
- DecisionAgent::Monitoring::MonitoredAgent
- Defined in:
- lib/decision_agent/monitoring/monitored_agent.rb
Overview
Wrapper around Agent that automatically records metrics
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#metrics_collector ⇒ Object
readonly
Returns the value of attribute metrics_collector.
Instance Method Summary collapse
-
#decide(context:, feedback: {}) ⇒ Object
Make a decision and automatically record metrics.
-
#initialize(agent:, metrics_collector:) ⇒ MonitoredAgent
constructor
A new instance of MonitoredAgent.
-
#method_missing(method) ⇒ Object
Delegate other methods to the wrapped agent.
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(agent:, metrics_collector:) ⇒ MonitoredAgent
Returns a new instance of MonitoredAgent.
9 10 11 12 |
# File 'lib/decision_agent/monitoring/monitored_agent.rb', line 9 def initialize(agent:, metrics_collector:) @agent = agent @metrics_collector = metrics_collector end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
Delegate other methods to the wrapped agent
64 65 66 |
# File 'lib/decision_agent/monitoring/monitored_agent.rb', line 64 def method_missing(method, ...) @agent.send(method, ...) end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
7 8 9 |
# File 'lib/decision_agent/monitoring/monitored_agent.rb', line 7 def agent @agent end |
#metrics_collector ⇒ Object (readonly)
Returns the value of attribute metrics_collector.
7 8 9 |
# File 'lib/decision_agent/monitoring/monitored_agent.rb', line 7 def metrics_collector @metrics_collector end |
Instance Method Details
#decide(context:, feedback: {}) ⇒ Object
Make a decision and automatically record metrics
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 |
# File 'lib/decision_agent/monitoring/monitored_agent.rb', line 15 def decide(context:, feedback: {}) ctx = context.is_a?(Context) ? context : Context.new(context) start_time = Time.now begin result = @agent.decide(context: ctx, feedback: feedback) duration_ms = (Time.now - start_time) * 1000 # Record decision metrics @metrics_collector.record_decision(result, ctx, duration_ms: duration_ms) # Record each evaluation result.evaluations.each do |evaluation| @metrics_collector.record_evaluation(evaluation) end # Record successful performance @metrics_collector.record_performance( operation: "decide", duration_ms: duration_ms, success: true, metadata: { evaluators_count: result.evaluations.size, decision: result.decision, confidence: result.confidence } ) result rescue StandardError => e duration_ms = (Time.now - start_time) * 1000 # Record error @metrics_collector.record_error(e, context: ctx.to_h) # Record failed performance @metrics_collector.record_performance( operation: "decide", duration_ms: duration_ms, success: false, metadata: { error_class: e.class.name } ) raise end end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
68 69 70 |
# File 'lib/decision_agent/monitoring/monitored_agent.rb', line 68 def respond_to_missing?(method, include_private = false) @agent.respond_to?(method, include_private) || super end |