Class: RubyLLM::Modes::Route
- Inherits:
-
Data
- Object
- Data
- RubyLLM::Modes::Route
- Defined in:
- lib/ruby_llm/modes/route.rb
Overview
What the router decided for one chat, with the classifier's decision attached.
mode_class: the agent class mode_name: its registration name decided_by: :caller, :classifier, or :fallback reason: why this mode decision: Decision, or nil when no classifier ran duration_ms: Integer, nil on caller-decided routes classifier: { with: "chat" | "judge" | "custom", model: String | nil }, or nil when no backend was called error: the exception a failed classifier raised, or nil chat: the chat the route was decided for inputs: the router's inputs, handed to the mode's agent
Instance Attribute Summary collapse
-
#chat ⇒ Object
readonly
Returns the value of attribute chat.
-
#classifier ⇒ Object
readonly
Returns the value of attribute classifier.
-
#decided_by ⇒ Object
readonly
Returns the value of attribute decided_by.
-
#decision ⇒ Object
readonly
Returns the value of attribute decision.
-
#duration_ms ⇒ Object
readonly
Returns the value of attribute duration_ms.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#mode_class ⇒ Object
readonly
Returns the value of attribute mode_class.
-
#mode_name ⇒ Object
readonly
Returns the value of attribute mode_name.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Instance Method Summary collapse
-
#initialize(mode_class:, mode_name:, decided_by:, reason:, decision: nil, duration_ms: nil, classifier: nil, error: nil, chat: nil, inputs: {}) ⇒ Route
constructor
A new instance of Route.
-
#mode(**options) ⇒ Object
The mode as an agent on the route's chat: Agent.new applies the mode's configuration to the chat and returns the agent wrapping it, so call this once per turn.
-
#to_h ⇒ Object
The fields with string keys, for logs.
Constructor Details
#initialize(mode_class:, mode_name:, decided_by:, reason:, decision: nil, duration_ms: nil, classifier: nil, error: nil, chat: nil, inputs: {}) ⇒ Route
21 22 23 24 |
# File 'lib/ruby_llm/modes/route.rb', line 21 def initialize(mode_class:, mode_name:, decided_by:, reason:, decision: nil, duration_ms: nil, classifier: nil, error: nil, chat: nil, inputs: {}) super end |
Instance Attribute Details
#chat ⇒ Object (readonly)
Returns the value of attribute chat
19 20 21 |
# File 'lib/ruby_llm/modes/route.rb', line 19 def chat @chat end |
#classifier ⇒ Object (readonly)
Returns the value of attribute classifier
19 20 21 |
# File 'lib/ruby_llm/modes/route.rb', line 19 def classifier @classifier end |
#decided_by ⇒ Object (readonly)
Returns the value of attribute decided_by
19 20 21 |
# File 'lib/ruby_llm/modes/route.rb', line 19 def decided_by @decided_by end |
#decision ⇒ Object (readonly)
Returns the value of attribute decision
19 20 21 |
# File 'lib/ruby_llm/modes/route.rb', line 19 def decision @decision end |
#duration_ms ⇒ Object (readonly)
Returns the value of attribute duration_ms
19 20 21 |
# File 'lib/ruby_llm/modes/route.rb', line 19 def duration_ms @duration_ms end |
#error ⇒ Object (readonly)
Returns the value of attribute error
19 20 21 |
# File 'lib/ruby_llm/modes/route.rb', line 19 def error @error end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs
19 20 21 |
# File 'lib/ruby_llm/modes/route.rb', line 19 def inputs @inputs end |
#mode_class ⇒ Object (readonly)
Returns the value of attribute mode_class
19 20 21 |
# File 'lib/ruby_llm/modes/route.rb', line 19 def mode_class @mode_class end |
#mode_name ⇒ Object (readonly)
Returns the value of attribute mode_name
19 20 21 |
# File 'lib/ruby_llm/modes/route.rb', line 19 def mode_name @mode_name end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason
19 20 21 |
# File 'lib/ruby_llm/modes/route.rb', line 19 def reason @reason end |
Instance Method Details
#mode(**options) ⇒ Object
The mode as an agent on the route's chat: Agent.new applies the
mode's configuration to the chat and returns the agent wrapping
it, so call this once per turn. The router's inputs are the
agent's inputs:; the agent takes the names it declared and
ignores the rest. Extra keywords go to Agent.new as given, except
chat:: the route was decided for its own chat.
32 33 34 35 36 |
# File 'lib/ruby_llm/modes/route.rb', line 32 def mode(**) raise ArgumentError, "the route is bound to its chat; mode takes no chat:" if .key?(:chat) mode_class.new(chat:, inputs:, **) end |
#to_h ⇒ Object
The fields with string keys, for logs. Drops the mode class, the error, the chat, and the inputs; the nested decision and classifier trace get string keys too. Serializes decided_by as a string.
41 42 43 44 45 46 47 |
# File 'lib/ruby_llm/modes/route.rb', line 41 def to_h super.except(:mode_class, :error, :chat, :inputs).transform_keys(&:to_s).tap do |hash| hash["decided_by"] = decided_by.to_s hash["decision"] = decision&.to_h hash["classifier"] = classifier&.transform_keys(&:to_s) end end |