Class: Riffer::Agent::Config
- Inherits:
-
Object
- Object
- Riffer::Agent::Config
- Defined in:
- lib/riffer/agent/config.rb
Overview
Typed configuration object holding every class-level DSL setting on a Riffer::Agent subclass.
Each subclass of Riffer::Agent owns one Config, accessible via the class method config. The class-level DSL (model, instructions, uses_tools, etc.) reads and mutates this Config in place. Append-style DSL methods (use_mcp, guardrail) are handled by the add_mcp and add_guardrail helpers below.
Config stores Procs unresolved. Per-instance resolution happens elsewhere (instructions, model, tools, tool runtime, skills).
Constant Summary collapse
- DEFAULT_MAX_STEPS =
: Integer
16
Instance Attribute Summary collapse
-
#guardrails ⇒ Object
readonly
: Hash[Symbol, Array[Hash[Symbol, untyped]]].
-
#identifier ⇒ Object
: String?.
-
#instructions ⇒ Object
: (String | Proc)?.
-
#max_steps ⇒ Object
: Numeric.
-
#mcp_configs ⇒ Object
readonly
: Array[Hash[Symbol, untyped]].
-
#model ⇒ Object
: (String | Proc)?.
-
#model_options ⇒ Object
: Hash[Symbol, untyped].
-
#provider_options ⇒ Object
: Hash[Symbol, untyped].
-
#skills_config ⇒ Object
: Riffer::Skills::Config?.
-
#structured_output ⇒ Object
: Riffer::Params?.
-
#tool_runtime ⇒ Object
: (singleton(Riffer::Tools::Runtime) | Riffer::Tools::Runtime | Proc).
-
#tools_config ⇒ Object
: (Array | Proc)?.
Instance Method Summary collapse
-
#add_guardrail(phase, klass:, options: {}) ⇒ Object
Appends a guardrail entry to
guardrailsfor the given phase. -
#add_mcp(tag) ⇒ Object
Appends an MCP tag entry to
mcp_configs. -
#guardrails_for(phase) ⇒ Object
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.
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. All fields are optional; unset fields take the documented defaults.
Raises Riffer::ArgumentError if model or instructions is provided as a non-String, non-Proc value (or as 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/riffer/agent/config.rb', line 39 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 ⇒ Object (readonly)
: Hash[Symbol, Array[Hash[Symbol, untyped]]]
29 30 31 |
# File 'lib/riffer/agent/config.rb', line 29 def guardrails @guardrails end |
#identifier ⇒ Object
: String?
18 19 20 |
# File 'lib/riffer/agent/config.rb', line 18 def identifier @identifier end |
#instructions ⇒ Object
: (String | Proc)?
20 21 22 |
# File 'lib/riffer/agent/config.rb', line 20 def instructions @instructions end |
#max_steps ⇒ Object
: Numeric
24 25 26 |
# File 'lib/riffer/agent/config.rb', line 24 def max_steps @max_steps end |
#mcp_configs ⇒ Object (readonly)
: Array[Hash[Symbol, untyped]]
26 27 28 |
# File 'lib/riffer/agent/config.rb', line 26 def mcp_configs @mcp_configs end |
#model ⇒ Object
: (String | Proc)?
19 20 21 |
# File 'lib/riffer/agent/config.rb', line 19 def model @model end |
#model_options ⇒ Object
: Hash[Symbol, untyped]
22 23 24 |
# File 'lib/riffer/agent/config.rb', line 22 def @model_options end |
#provider_options ⇒ Object
: Hash[Symbol, untyped]
21 22 23 |
# File 'lib/riffer/agent/config.rb', line 21 def @provider_options end |
#skills_config ⇒ Object
: Riffer::Skills::Config?
28 29 30 |
# File 'lib/riffer/agent/config.rb', line 28 def skills_config @skills_config end |
#structured_output ⇒ Object
: Riffer::Params?
23 24 25 |
# File 'lib/riffer/agent/config.rb', line 23 def structured_output @structured_output end |
#tool_runtime ⇒ Object
: (singleton(Riffer::Tools::Runtime) | Riffer::Tools::Runtime | Proc)
27 28 29 |
# File 'lib/riffer/agent/config.rb', line 27 def tool_runtime @tool_runtime end |
#tools_config ⇒ Object
: (Array | Proc)?
25 26 27 |
# File 'lib/riffer/agent/config.rb', line 25 def tools_config @tools_config end |
Instance Method Details
#add_guardrail(phase, klass:, options: {}) ⇒ Object
Appends a guardrail entry to guardrails for the given phase.
- phase
-
:before,:after, or:around.:aroundappends to both
+:before+ and +:after+.
- klass
-
the Riffer::Guardrail subclass to register.
- options
-
options forwarded to the guardrail at runtime.
Raises Riffer::ArgumentError on an invalid phase or non-Guardrail class.
– : (Symbol, klass: singleton(Riffer::Guardrail), ?options: Hash[Symbol, untyped]) -> void
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/riffer/agent/config.rb', line 140 def add_guardrail(phase, klass:, options: {}) valid_phases = [*Riffer::Guardrails::PHASES, :around] raise Riffer::ArgumentError, "Invalid guardrail phase: #{phase}" unless valid_phases.include?(phase) raise Riffer::ArgumentError, "Guardrail must be a Riffer::Guardrail subclass" unless klass.is_a?(Class) && klass <= Riffer::Guardrail 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) ⇒ Object
Appends an MCP tag entry to mcp_configs.
– : (String | Symbol) -> Array[Hash[Symbol, untyped]]
125 126 127 |
# File 'lib/riffer/agent/config.rb', line 125 def add_mcp(tag) @mcp_configs << {tags: [tag.to_sym]} end |
#guardrails_for(phase) ⇒ Object
Returns the guardrail entries for the given phase, or [] if none.
– : (Symbol) -> Array[Hash[Symbol, untyped]]
161 162 163 |
# File 'lib/riffer/agent/config.rb', line 161 def guardrails_for(phase) @guardrails[phase] || [] end |