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. Procs are stored unresolved and resolved per-instance later.
Constant Summary collapse
- DEFAULT_MAX_STEPS =
: Integer
16
Instance Attribute Summary collapse
-
#guardrails ⇒ Object
readonly
Registered guardrail entries keyed by phase.
-
#identifier ⇒ Object
The configured agent identifier.
-
#instructions ⇒ Object
The configured instructions.
-
#max_steps ⇒ Object
The maximum number of LLM call steps in the tool-use loop.
-
#mcp_configs ⇒ Object
readonly
The accumulated
use_mcptag configurations. -
#model ⇒ Object
The configured model.
-
#model_options ⇒ Object
Options passed to generate_text/stream_text.
-
#provider_options ⇒ Object
Options passed to the provider client.
-
#skills_config ⇒ Object
The configured skills.
-
#structured_output ⇒ Object
The configured structured-output schema.
-
#tool_runtime ⇒ Object
The configured tool runtime.
-
#tools_config ⇒ Object
The configured tools.
Instance Method Summary collapse
-
#add_guardrail(phase, klass:, options: {}) ⇒ Object
Appends a guardrail entry to
guardrailsfor the given phase;:aroundappends to both:beforeand:after. -
#add_mcp(tag, progressive: true) ⇒ 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. 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
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 |
# File 'lib/riffer/agent/config.rb', line 50 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)
Registered guardrail entries keyed by phase.
44 45 46 |
# File 'lib/riffer/agent/config.rb', line 44 def guardrails @guardrails end |
#identifier ⇒ Object
The configured agent identifier.
11 12 13 |
# File 'lib/riffer/agent/config.rb', line 11 def identifier @identifier end |
#instructions ⇒ Object
The configured instructions.
17 18 19 |
# File 'lib/riffer/agent/config.rb', line 17 def instructions @instructions end |
#max_steps ⇒ Object
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 ⇒ Object (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 ⇒ Object
The configured model.
14 15 16 |
# File 'lib/riffer/agent/config.rb', line 14 def model @model end |
#model_options ⇒ Object
Options passed to generate_text/stream_text.
23 24 25 |
# File 'lib/riffer/agent/config.rb', line 23 def @model_options end |
#provider_options ⇒ Object
Options passed to the provider client.
20 21 22 |
# File 'lib/riffer/agent/config.rb', line 20 def @provider_options end |
#skills_config ⇒ Object
The configured skills.
41 42 43 |
# File 'lib/riffer/agent/config.rb', line 41 def skills_config @skills_config end |
#structured_output ⇒ Object
The configured structured-output schema.
26 27 28 |
# File 'lib/riffer/agent/config.rb', line 26 def structured_output @structured_output end |
#tool_runtime ⇒ Object
The configured tool runtime.
38 39 40 |
# File 'lib/riffer/agent/config.rb', line 38 def tool_runtime @tool_runtime end |
#tools_config ⇒ Object
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: {}) ⇒ Object
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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/riffer/agent/config.rb', line 134 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, progressive: true) ⇒ Object
Appends an MCP tag entry to mcp_configs.
– : (String | Symbol, ?progressive: bool) -> Array[Hash[Symbol, untyped]]
124 125 126 127 |
# File 'lib/riffer/agent/config.rb', line 124 def add_mcp(tag, progressive: true) raise Riffer::ArgumentError, "progressive must be a boolean" unless progressive == true || progressive == false @mcp_configs << {tags: [tag.to_sym], progressive: progressive} end |
#guardrails_for(phase) ⇒ Object
Returns the guardrail entries for the given phase, or [] if none.
– : (Symbol) -> Array[Hash[Symbol, untyped]]
155 156 157 |
# File 'lib/riffer/agent/config.rb', line 155 def guardrails_for(phase) @guardrails[phase] || [] end |