Class: RubyLLM::Agents::Routing::RoutingResult
- Inherits:
-
RubyLLM::Agents::Result
- Object
- RubyLLM::Agents::Result
- RubyLLM::Agents::Routing::RoutingResult
- Defined in:
- lib/ruby_llm/agents/routing/result.rb
Overview
Wraps a standard Result with routing-specific accessors.
When the route has an ‘agent:` mapping, the router auto-delegates to that agent. The delegated result is available via `delegated_result`, and `content` returns the delegated agent’s content.
Instance Attribute Summary collapse
-
#agent_class ⇒ Class?
readonly
The mapped agent class (if defined via ‘agent:`).
-
#delegated_result ⇒ Result?
readonly
The result from the delegated agent (if auto-delegated).
-
#raw_response ⇒ String
readonly
The raw text response from the LLM.
-
#route ⇒ Symbol
readonly
The classified route name.
Attributes inherited from RubyLLM::Agents::Result
#agent_class_name, #attempts, #attempts_count, #cache_creation_tokens, #cached_tokens, #cancelled, #chosen_model_id, #completed_at, #content, #duration_ms, #error_class, #error_message, #execution_id, #finish_reason, #input_cost, #input_tokens, #model_id, #output_cost, #output_tokens, #started_at, #streaming, #temperature, #thinking_signature, #thinking_text, #thinking_tokens, #time_to_first_token_ms, #tool_calls, #tool_calls_count, #total_cost, #trace
Instance Method Summary collapse
-
#delegated? ⇒ Boolean
Whether the router auto-delegated to a mapped agent.
-
#delegated_to ⇒ Class?
The agent class that was auto-invoked (alias for agent_class).
-
#initialize(base_result:, route_data:) ⇒ RoutingResult
constructor
Creates a new RoutingResult by wrapping a base Result with route data.
-
#routing_cost ⇒ Float
Cost of the classification step only (excluding delegation).
-
#to_h ⇒ Hash
Converts the result to a hash including routing fields.
Methods inherited from RubyLLM::Agents::Result
#[], #cancelled?, #dig, #each, #error?, #execution, #keys, #map, #streaming?, #success?, #thinking?, #to_json, #tool_calls?, #total_tokens, #truncated?, #used_fallback?, #values
Constructor Details
#initialize(base_result:, route_data:) ⇒ RoutingResult
Creates a new RoutingResult by wrapping a base Result with route data.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ruby_llm/agents/routing/result.rb', line 47 def initialize(base_result:, route_data:) @delegated_result = route_data[:delegated_result] @routing_cost = base_result.total_cost # When delegated, merge costs from both classification and delegation total = if @delegated_result (base_result.total_cost || 0) + (@delegated_result.respond_to?(:total_cost) ? @delegated_result.total_cost || 0 : 0) else base_result.total_cost end # Use delegated content when available effective_content = if @delegated_result @delegated_result.respond_to?(:content) ? @delegated_result.content : route_data else route_data end super( content: effective_content, input_tokens: base_result.input_tokens, output_tokens: base_result.output_tokens, input_cost: base_result.input_cost, output_cost: base_result.output_cost, total_cost: total, model_id: base_result.model_id, chosen_model_id: base_result.chosen_model_id, temperature: base_result.temperature, started_at: base_result.started_at, completed_at: base_result.completed_at, duration_ms: base_result.duration_ms, finish_reason: base_result.finish_reason, streaming: base_result.streaming, error_class: base_result.error_class, error_message: base_result., attempts_count: base_result.attempts_count ) @route = route_data[:route] @agent_class = route_data[:agent_class] @raw_response = route_data[:raw_response] end |
Instance Attribute Details
#agent_class ⇒ Class? (readonly)
Returns The mapped agent class (if defined via ‘agent:`).
31 32 33 |
# File 'lib/ruby_llm/agents/routing/result.rb', line 31 def agent_class @agent_class end |
#delegated_result ⇒ Result? (readonly)
Returns The result from the delegated agent (if auto-delegated).
37 38 39 |
# File 'lib/ruby_llm/agents/routing/result.rb', line 37 def delegated_result @delegated_result end |
#raw_response ⇒ String (readonly)
Returns The raw text response from the LLM.
34 35 36 |
# File 'lib/ruby_llm/agents/routing/result.rb', line 34 def raw_response @raw_response end |
#route ⇒ Symbol (readonly)
Returns The classified route name.
28 29 30 |
# File 'lib/ruby_llm/agents/routing/result.rb', line 28 def route @route end |
Instance Method Details
#delegated? ⇒ Boolean
Whether the router auto-delegated to a mapped agent
93 94 95 |
# File 'lib/ruby_llm/agents/routing/result.rb', line 93 def delegated? !@delegated_result.nil? end |
#delegated_to ⇒ Class?
The agent class that was auto-invoked (alias for agent_class)
100 101 102 |
# File 'lib/ruby_llm/agents/routing/result.rb', line 100 def delegated_to @agent_class if delegated? end |
#routing_cost ⇒ Float
Cost of the classification step only (excluding delegation)
107 108 109 |
# File 'lib/ruby_llm/agents/routing/result.rb', line 107 def routing_cost @routing_cost || 0 end |
#to_h ⇒ Hash
Converts the result to a hash including routing fields.
114 115 116 117 118 119 120 121 |
# File 'lib/ruby_llm/agents/routing/result.rb', line 114 def to_h super.merge( route: route, agent_class: agent_class&.name, raw_response: raw_response, delegated: delegated? ) end |