Configuration¶
SelfAgency must be configured before generating any methods. Call SelfAgency.configure with a block:
SelfAgency.configure do |config|
config.provider = :ollama
config.model = "qwen3-coder:30b"
config.api_base = "http://localhost:11434/v1"
end
Options¶
| Option | Type | Default | Description |
|---|---|---|---|
provider |
Symbol |
:ollama |
RubyLLM provider name |
model |
String |
"qwen3-coder:30b" |
LLM model identifier |
api_base |
String |
"http://localhost:11434/v1" |
Provider API endpoint |
request_timeout |
Integer |
30 |
Request timeout in seconds |
max_retries |
Integer |
1 |
Number of retries on failure |
retry_interval |
Float |
0.5 |
Seconds between retries |
template_directory |
String |
lib/self_agency/prompts |
Path to ERB prompt templates |
generation_retries |
Integer |
3 |
Max retry attempts when validation or security checks fail |
logger |
Proc, Logger, or nil |
nil |
Logger for pipeline events (see Logging below) |
Configuration Is Mandatory¶
Calling _() before configure raises SelfAgency::Error:
SelfAgency.reset!
class Widget
include SelfAgency
end
Widget.new._("a method")
#=> SelfAgency::Error: SelfAgency.configure has not been called
Applying Configuration¶
SelfAgency.configure delegates to RubyLLM.configure and RubyLLM::Template.configure under the hood:
provider+api_baseset the provider-specific API base on RubyLLM. Theapi_basevalue is assigned to the RubyLLM config key<provider>_api_base. For example,:openaimaps toopenai_api_base,:ollamamaps toollama_api_base.request_timeout,max_retries, andretry_intervalmap directly to RubyLLM settingstemplate_directoryis passed toRubyLLM::Template
Resetting Configuration¶
SelfAgency.reset! restores all defaults and marks the gem as unconfigured:
SelfAgency.reset!
SelfAgency.ensure_configured!
#=> SelfAgency::Error: SelfAgency.configure has not been called
Checking Configuration¶
SelfAgency.ensure_configured! raises if configure has not been called:
Logging¶
Set logger to observe each stage of the pipeline. It accepts either a callable (receives stage and message) or a Logger-compatible object (uses .debug):
# Callable logger
SelfAgency.configure do |config|
config.logger = ->(stage, message) { puts "[#{stage}] #{message}" }
# ...
end
# Standard library Logger
require "logger"
SelfAgency.configure do |config|
config.logger = Logger.new($stdout)
# ...
end
Logged stages: :shape, :generate, :validate, :retry, :complete.
Example: Custom Timeouts¶
For complex method generation that takes longer:
SelfAgency.configure do |config|
config.provider = :ollama
config.model = "qwen3-coder:30b"
config.api_base = "http://localhost:11434/v1"
config.request_timeout = 120
config.max_retries = 3
config.retry_interval = 1.0
end