Quick Start¶
This guide walks through a complete example from configuration to using generated methods.
1. Configure SelfAgency¶
Before generating any methods, call SelfAgency.configure:
require "self_agency"
SelfAgency.configure do |config|
config.provider = :ollama
config.model = "qwen3-coder:30b"
config.api_base = "http://localhost:11434/v1"
end
Configuration is mandatory. Calling _() before configure raises SelfAgency::Error.
2. Include the Module¶
Add include SelfAgency to any class:
3. Generate a Method¶
Call _() with a natural language description:
names = calc._("an instance method named 'add' that accepts two integer parameters a and b, and returns their sum")
#=> [:add]
_() always returns an Array of Symbol method names.
4. Use the Method¶
The generated method is available immediately:
Instance methods (the default scope) are available on all instances of the class:
5. View the Source¶
Inspect what the LLM generated:
puts calc._source_for(:add)
# >> # an instance method named 'add' that accepts two integer
# >> # parameters a and b, and returns their sum
# >> def add(a, b)
# >> a + b
# >> end
6. Generate Multiple Methods¶
A single _() call can produce several methods:
names = calc._(
"create add, subtract, multiply, and divide methods for two integers"
)
#=> [:add, :subtract, :multiply, :divide]
calc.subtract(10, 3) #=> 7
calc.multiply(4, 5) #=> 20
calc.divide(10, 3) #=> 3.333...
Next Steps¶
- How to Use SelfAgency -- Where SelfAgency fits in your design workflow
- Scopes -- Generate singleton and class methods
- Source Inspection -- View and retrieve generated source
- Saving Methods -- Persist generated methods to files
- Configuration -- All configuration options