Skip to content

Examples

SelfAgency ships with 12 examples that progressively demonstrate its features. All examples live in the examples/ directory.

Running Examples

Most examples require a running LLM. The default configuration targets Ollama:

# Start Ollama
ollama serve

# Run an example
bundle exec ruby examples/01_basic_usage.rb

Examples 06 and 07 run offline (no LLM required) as they only exercise configuration and error handling.

Example Index

# Name Features LLM Required
01 Basic Usage _(), single method generation Yes
02 Multiple Methods Multiple methods from one call Yes
03 Scopes Instance, singleton, class scopes Yes
04 Source Inspection _source_for, file fallback Yes
05 Lifecycle Hook on_method_generated Yes
06 Configuration All config options, reset!, ensure_configured! No
07 Error Handling Error hierarchy, rescue patterns No
08 Class Context Instance variables, method awareness Yes
09 Method Override Replacing existing methods Yes
10 Full Workflow Complete real-world workflow Yes
11 Collaborative Robots Multi-robot pipeline, message bus Yes
12 Autonomous Robots Three-layer LLM, self-repair Yes

Examples 01--09 are covered in Basic Examples. Examples 10--12 each have their own deep-dive page.