Class: Riffer::Agent::Config
- Inherits:
-
Object
- Object
- Riffer::Agent::Config
- Defined in:
- lib/riffer/agent/config.rb,
sig/generated/riffer/agent/config.rbs
Overview
Typed configuration object holding every class-level DSL setting on a Riffer::Agent subclass. Procs are stored unresolved and resolved per-instance later.
Constant Summary collapse
- DEFAULT_MAX_STEPS =
16
Instance Attribute Summary collapse
-
#guardrails ⇒ Hash[Symbol, Array[Hash[Symbol, untyped]]]
readonly
Registered guardrail entries keyed by phase.
-
#identifier ⇒ String?
The configured agent identifier.
-
#instructions ⇒ String, ...
The configured instructions.
-
#max_steps ⇒ Numeric?
The maximum number of LLM call steps in the tool-use loop.
-
#mcp_configs ⇒ Array[Hash[Symbol, untyped]]
readonly
The accumulated
use_mcptag configurations. -
#model ⇒ String, ...
The configured model.
-
#model_options ⇒ Hash[Symbol, untyped]
Options passed to generate_text/stream_text.
-
#provider_options ⇒ Hash[Symbol, untyped]
Options passed to the provider client.
-
#skills_config ⇒ Riffer::Skills::Config?
The configured skills.
-
#structured_output ⇒ Riffer::Params?
The configured structured-output schema.
-
#tool_runtime ⇒ singleton(Riffer::Tools::Runtime), ...
The configured tool runtime.
-
#tools_config ⇒ Array[singleton(Riffer::Tool)], ...
The configured tools.
Instance Method Summary collapse
-
#add_guardrail(phase, klass:, options: {}) ⇒ void
Appends a guardrail entry to
guardrailsfor the given phase;:aroundappends to both:beforeand:after. -
#add_mcp(tag, progressive: true) ⇒ Array[Hash[Symbol, untyped]]
Appends an MCP tag entry to
mcp_configs. -
#guardrails_for(phase) ⇒ Array[Hash[Symbol, untyped]]
Returns the guardrail entries for the given phase, or
[]if none. -
#initialize(identifier: nil, model: nil, instructions: nil, provider_options: {}, model_options: {}, structured_output: nil, max_steps: DEFAULT_MAX_STEPS, tools_config: nil, mcp_configs: [], tool_runtime: Riffer.config.tool_runtime, skills_config: nil, guardrails: { before: [], after: [] }) ⇒ Config
constructor
Builds a new Config.
-
#validate_string_or_proc!(value, name) ⇒ void
-- : (untyped, String) -> void.
Constructor Details
#initialize(identifier: nil, model: nil, instructions: nil, provider_options: {}, model_options: {}, structured_output: nil, max_steps: DEFAULT_MAX_STEPS, tools_config: nil, mcp_configs: [], tool_runtime: Riffer.config.tool_runtime, skills_config: nil, guardrails: { before: [], after: [] }) ⇒ Config
Builds a new Config. Raises Riffer::ArgumentError if model or
instructions is invalid (e.g. an empty string).
: ( ?identifier: String?, ?model: (String | Proc)?, ?instructions: (String | Proc)?, ?provider_options: Hash[Symbol, untyped], ?model_options: Hash[Symbol, untyped], ?structured_output: Riffer::Params?, ?max_steps: Numeric?, ?tools_config: (Array | Proc)?, ?mcp_configs: Array[Hash[Symbol, untyped]], ?tool_runtime: (singleton(Riffer::Tools::Runtime) | Riffer::Tools::Runtime | Proc), ?skills_config: Riffer::Skills::Config?, ?guardrails: Hash[Symbol, Array[Hash[Symbol, untyped]]] ) -> void
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 89 |
# File 'lib/riffer/agent/config.rb', line 63 def initialize( identifier: nil, model: nil, instructions: nil, provider_options: {}, model_options: {}, structured_output: nil, max_steps: DEFAULT_MAX_STEPS, tools_config: nil, mcp_configs: [], tool_runtime: Riffer.config.tool_runtime, skills_config: nil, guardrails: { before: [], after: [] } ) @provider_options = @model_options = @max_steps = max_steps @tools_config = tools_config @mcp_configs = mcp_configs @skills_config = skills_config @guardrails = guardrails self.identifier = identifier self.model = model self.instructions = instructions self.structured_output = structured_output self.tool_runtime = tool_runtime end |
Instance Attribute Details
#guardrails ⇒ Hash[Symbol, Array[Hash[Symbol, untyped]]] (readonly)
Registered guardrail entries keyed by phase.
44 45 46 |
# File 'lib/riffer/agent/config.rb', line 44 def guardrails @guardrails end |
#identifier ⇒ String?
The configured agent identifier.
11 12 13 |
# File 'lib/riffer/agent/config.rb', line 11 def identifier @identifier end |
#instructions ⇒ String, ...
The configured instructions.
17 18 19 |
# File 'lib/riffer/agent/config.rb', line 17 def instructions @instructions end |
#max_steps ⇒ Numeric?
The maximum number of LLM call steps in the tool-use loop.
29 30 31 |
# File 'lib/riffer/agent/config.rb', line 29 def max_steps @max_steps end |
#mcp_configs ⇒ Array[Hash[Symbol, untyped]] (readonly)
The accumulated use_mcp tag configurations.
35 36 37 |
# File 'lib/riffer/agent/config.rb', line 35 def mcp_configs @mcp_configs end |
#model ⇒ String, ...
The configured model.
14 15 16 |
# File 'lib/riffer/agent/config.rb', line 14 def model @model end |
#model_options ⇒ Hash[Symbol, untyped]
Options passed to generate_text/stream_text.
23 24 25 |
# File 'lib/riffer/agent/config.rb', line 23 def @model_options end |
#provider_options ⇒ Hash[Symbol, untyped]
Options passed to the provider client.
20 21 22 |
# File 'lib/riffer/agent/config.rb', line 20 def @provider_options end |
#skills_config ⇒ Riffer::Skills::Config?
The configured skills.
41 42 43 |
# File 'lib/riffer/agent/config.rb', line 41 def skills_config @skills_config end |
#structured_output ⇒ Riffer::Params?
The configured structured-output schema.
26 27 28 |
# File 'lib/riffer/agent/config.rb', line 26 def structured_output @structured_output end |
#tool_runtime ⇒ singleton(Riffer::Tools::Runtime), ...
The configured tool runtime.
38 39 40 |
# File 'lib/riffer/agent/config.rb', line 38 def tool_runtime @tool_runtime end |
#tools_config ⇒ Array[singleton(Riffer::Tool)], ...
The configured tools.
32 33 34 |
# File 'lib/riffer/agent/config.rb', line 32 def tools_config @tools_config end |
Instance Method Details
#add_guardrail(phase, klass:, options: {}) ⇒ void
This method returns an undefined value.
Appends a guardrail entry to guardrails for the given phase; :around
appends to both :before and :after. Raises Riffer::ArgumentError unless
phase is :before, :after, or :around.
: (Symbol, klass: singleton(Riffer::Guardrail), ?options: Hash[Symbol, untyped]) -> void
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/riffer/agent/config.rb', line 156 def add_guardrail(phase, klass:, options: {}) valid_phases = [*Riffer::Guardrails::PHASES, :around] raise Riffer::ArgumentError, "Invalid guardrail phase: #{phase}" unless valid_phases.include?(phase) unless klass.is_a?(Class) && klass <= Riffer::Guardrail raise Riffer::ArgumentError, "Guardrail must be a Riffer::Guardrail subclass" end cfg = { class: klass, options: } case phase when :before @guardrails[:before] << cfg when :after @guardrails[:after] << cfg when :around @guardrails[:before] << cfg @guardrails[:after] << cfg end end |
#add_mcp(tag, progressive: true) ⇒ Array[Hash[Symbol, untyped]]
Appends an MCP tag entry to mcp_configs.
-- : (String | Symbol, ?progressive: bool) -> Array[Hash[Symbol, untyped]]
145 146 147 148 149 |
# File 'lib/riffer/agent/config.rb', line 145 def add_mcp(tag, progressive: true) raise Riffer::ArgumentError, "progressive must be a boolean" unless [true, false].include?(progressive) @mcp_configs << { tags: [tag.to_sym], progressive: progressive } end |
#guardrails_for(phase) ⇒ Array[Hash[Symbol, untyped]]
Returns the guardrail entries for the given phase, or [] if none.
-- : (Symbol) -> Array[Hash[Symbol, untyped]]
180 181 182 |
# File 'lib/riffer/agent/config.rb', line 180 def guardrails_for(phase) @guardrails[phase] || [] end |
#validate_string_or_proc!(value, name) ⇒ void
This method returns an undefined value.
-- : (untyped, String) -> void
188 189 190 191 192 |
# File 'lib/riffer/agent/config.rb', line 188 def validate_string_or_proc!(value, name) return if value.nil? || value.is_a?(Proc) raise Riffer::ArgumentError, "#{name} must be a String" unless value.is_a?(String) raise Riffer::ArgumentError, "#{name} cannot be empty" if value.strip.empty? end |