Class: RobotLab::RunConfig
- Inherits:
-
Object
- Object
- RobotLab::RunConfig
- Defined in:
- lib/robot_lab/run_config.rb
Overview
Shared configuration object for LLM, tools, callbacks, and infrastructure.
RunConfig provides a unified way to express operational defaults that flow through the configuration hierarchy:
RobotLab.config -> Network -> Robot -> Template front matter -> Task -> Runtime
Only explicitly set values are stored. Merge semantics: the more-specific config’s non-nil values win over the less-specific config.
Constant Summary collapse
- LLM_FIELDS =
LLM configuration fields (applied to chat via with_* methods)
%i[ model temperature top_p top_k max_tokens presence_penalty frequency_penalty stop ].freeze
- TOOL_FIELDS =
Tool-related fields
%i[mcp tools].freeze
- CALLBACK_FIELDS =
Callback fields (Procs)
%i[on_tool_call on_tool_result on_content].freeze
- INFRA_FIELDS =
Infrastructure fields
%i[bus enable_cache max_tool_rounds token_budget ractor_pool_size].freeze
- FIELDS =
All recognized fields
(LLM_FIELDS + TOOL_FIELDS + CALLBACK_FIELDS + INFRA_FIELDS).freeze
- NON_SERIALIZABLE_FIELDS =
Fields that cannot be serialized to JSON (Procs, IO objects, etc.)
(CALLBACK_FIELDS + %i[bus]).freeze
Class Method Summary collapse
-
.from_front_matter(metadata) ⇒ RunConfig
Build a RunConfig from prompt_manager front matter metadata.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#apply_to(chat) ⇒ Object
Applies LLM fields to a chat object via its with_* methods.
-
#empty? ⇒ Boolean
True if no fields have been set.
-
#initialize(**kwargs) {|self| ... } ⇒ RunConfig
constructor
Creates a new RunConfig.
- #inspect ⇒ String
-
#key?(field) ⇒ Boolean
True if the field has been explicitly set.
-
#merge(other) ⇒ RunConfig
Merges another RunConfig (or Hash) on top of this one.
-
#to_h ⇒ Hash
Returns a duplicate of the internal fields hash.
-
#to_json_hash ⇒ Hash
Returns a JSON-safe hash (skips Procs, IO, and other non-serializable values).
Constructor Details
#initialize(**kwargs) {|self| ... } ⇒ RunConfig
Creates a new RunConfig.
56 57 58 59 60 61 62 63 64 |
# File 'lib/robot_lab/run_config.rb', line 56 def initialize(**kwargs) @fields = {} kwargs.each do |key, value| set(key, value) end yield self if block_given? end |
Class Method Details
.from_front_matter(metadata) ⇒ RunConfig
Build a RunConfig from prompt_manager front matter metadata.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/robot_lab/run_config.rb', line 127 def self.from_front_matter() fields = {} LLM_FIELDS.each do |key| value = .respond_to?(key) ? .send(key) : nil fields[key] = value if value end # Extract tool-related fields %i[mcp tools].each do |key| value = .respond_to?(key) ? .send(key) : nil fields[key] = value if value end new(**fields) end |
Instance Method Details
#==(other) ⇒ Boolean
160 161 162 |
# File 'lib/robot_lab/run_config.rb', line 160 def ==(other) other.is_a?(RunConfig) && to_h == other.to_h end |
#apply_to(chat) ⇒ Object
Applies LLM fields to a chat object via its with_* methods.
112 113 114 115 116 117 118 119 120 |
# File 'lib/robot_lab/run_config.rb', line 112 def apply_to(chat) LLM_FIELDS.each do |field| value = @fields[field] next unless value method = :"with_#{field}" chat.public_send(method, value) if chat.respond_to?(method) end end |
#empty? ⇒ Boolean
Returns true if no fields have been set.
146 147 148 |
# File 'lib/robot_lab/run_config.rb', line 146 def empty? @fields.empty? end |
#inspect ⇒ String
166 167 168 |
# File 'lib/robot_lab/run_config.rb', line 166 def inspect "#<#{self.class} #{@fields.inspect}>" end |
#key?(field) ⇒ Boolean
Returns true if the field has been explicitly set.
153 154 155 |
# File 'lib/robot_lab/run_config.rb', line 153 def key?(field) @fields.key?(field) end |
#merge(other) ⇒ RunConfig
Merges another RunConfig (or Hash) on top of this one. The other’s non-nil values win. Returns a new RunConfig.
102 103 104 105 106 |
# File 'lib/robot_lab/run_config.rb', line 102 def merge(other) other_hash = other.is_a?(RunConfig) ? other.to_h : other merged = @fields.merge(other_hash) { |_k, old_v, new_v| new_v.nil? ? old_v : new_v } self.class.new(**merged) end |
#to_h ⇒ Hash
Returns a duplicate of the internal fields hash.
84 85 86 |
# File 'lib/robot_lab/run_config.rb', line 84 def to_h @fields.dup end |
#to_json_hash ⇒ Hash
Returns a JSON-safe hash (skips Procs, IO, and other non-serializable values).
92 93 94 |
# File 'lib/robot_lab/run_config.rb', line 92 def to_json_hash @fields.reject { |k, _| NON_SERIALIZABLE_FIELDS.include?(k) } end |