Class: RubyLLM::SemanticRouter::RoutingDecision
- Inherits:
-
Object
- Object
- RubyLLM::SemanticRouter::RoutingDecision
- Defined in:
- lib/rubyllm/semantic_router/routing_decision.rb
Overview
Value object representing a routing decision
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
The name of the agent to route to.
-
#confidence ⇒ Object
readonly
Confidence score (0.0 - 1.0) of the routing decision.
-
#inject_instruction ⇒ Object
readonly
Optional instruction to inject (used for ask_clarification).
-
#matched_example ⇒ Object
readonly
The example text that matched (for debugging).
-
#reason ⇒ Object
readonly
Reason for the decision (:semantic_match, :fallback, :kept_current, :needs_clarification).
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#confident? ⇒ Boolean
Returns true if this was a confident semantic match.
-
#fallback? ⇒ Boolean
Returns true if this decision used a fallback.
-
#initialize(agent:, confidence: 0.0, matched_example: nil, reason: :semantic_match, inject_instruction: nil) ⇒ RoutingDecision
constructor
A new instance of RoutingDecision.
- #inspect ⇒ Object
-
#needs_clarification? ⇒ Boolean
Returns true if clarification is needed.
- #to_h ⇒ Object
Constructor Details
#initialize(agent:, confidence: 0.0, matched_example: nil, reason: :semantic_match, inject_instruction: nil) ⇒ RoutingDecision
Returns a new instance of RoutingDecision.
22 23 24 25 26 27 28 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 22 def initialize(agent:, confidence: 0.0, matched_example: nil, reason: :semantic_match, inject_instruction: nil) @agent = agent&.to_sym @confidence = confidence.to_f @matched_example = matched_example @reason = reason @inject_instruction = inject_instruction end |
Instance Attribute Details
#agent ⇒ Object (readonly)
The name of the agent to route to
8 9 10 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 8 def agent @agent end |
#confidence ⇒ Object (readonly)
Confidence score (0.0 - 1.0) of the routing decision
11 12 13 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 11 def confidence @confidence end |
#inject_instruction ⇒ Object (readonly)
Optional instruction to inject (used for ask_clarification)
20 21 22 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 20 def inject_instruction @inject_instruction end |
#matched_example ⇒ Object (readonly)
The example text that matched (for debugging)
14 15 16 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 14 def matched_example @matched_example end |
#reason ⇒ Object (readonly)
Reason for the decision (:semantic_match, :fallback, :kept_current, :needs_clarification)
17 18 19 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 17 def reason @reason end |
Instance Method Details
#==(other) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 55 def ==(other) return false unless other.is_a?(RoutingDecision) agent == other.agent && confidence == other.confidence && reason == other.reason end |
#confident? ⇒ Boolean
Returns true if this was a confident semantic match
31 32 33 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 31 def confident? reason == :semantic_match && confidence > 0 end |
#fallback? ⇒ Boolean
Returns true if this decision used a fallback
36 37 38 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 36 def fallback? %i[fallback kept_current needs_clarification].include?(reason) end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 63 def inspect "#<RoutingDecision agent=#{agent.inspect} confidence=#{confidence.round(3)} reason=#{reason.inspect}>" end |
#needs_clarification? ⇒ Boolean
Returns true if clarification is needed
41 42 43 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 41 def needs_clarification? reason == :needs_clarification end |
#to_h ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/rubyllm/semantic_router/routing_decision.rb', line 45 def to_h { agent: agent, confidence: confidence, matched_example: matched_example, reason: reason, inject_instruction: inject_instruction }.compact end |