Desiru v0.2.0: Building the Foundation for Declarative AI in Ruby
I’m thrilled to announce the release of Desiru v0.2.0, a major milestone in bringing the power of DSPy style (Declarative Self-Improving) programming to the Ruby ecosystem. This release implements critical infrastructure that enables Ruby developers to build sophisticated AI systems using clean, maintainable code instead of brittle prompt strings.
What is Desiru?
Desiru is a Ruby implementation of DSPy, Stanford’s groundbreaking framework that treats language model calls as modules in a larger program. Instead of manually crafting prompts, you declare what you want your AI system to do, and Desiru handles the optimization automatically.
Why This Release Matters
Version 0.2.0 represents intensive development focused on building the core infrastructure needed for production-ready AI applications. We’ve implemented five major DSPy features that work together to create a complete optimization pipeline:
1. Core Data Containers: The Foundation
The new Example and Prediction classes provide structured data handling throughout the DSPy pipeline:
# Examples represent training data
example = Desiru::Core::Example.new(
question: "What is the capital of France?",
answer: "Paris"
)
# Predictions carry model outputs with metadata
prediction = Desiru::Core::Prediction.from_completions(
{"answer" => "Paris"},
completions: {"answer" => completion_object}
)These containers aren’t just data holders — they integrate seamlessly with the tracing and optimization systems, providing a consistent interface for all DSPy operations.
2. Trace Collection: Understanding Your AI
The new tracing infrastructure gives unprecedented visibility into how your AI programs execute:
traces = Desiru::Core::TraceCollector.collect_traces(program, dataset) do |example, prediction, trace|
# Access detailed execution information
puts "Input: #{example.question}"
puts "Output: #{prediction.answer}"
puts "Modules called: #{trace.module_calls.map(&:module_name)}"
endThis isn’t just logging — it’s a complete execution history that optimizers use to understand what works and what doesn’t, enabling automatic improvement of your programs.
3. Compilation Infrastructure: From Code to Optimized AI
The compilation pipeline transforms your declarative programs into optimized implementations:
compiler = Desiru::Core::CompilerBuilder.new
.with_program(my_qa_program)
.with_dataset(training_data)
.with_metric(accuracy_metric)
.for_module(:answer_generator)
.with_strategy(:bootstrap_fewshot)
.build
optimized = compiler.compile
# Your program now includes optimized prompts and demonstrations4. ProgramOfThought: When AI Needs to Calculate
One of the most exciting additions is the ProgramOfThought module, which generates and executes code to solve complex problems:
pot = Desiru::Modules::ProgramOfThought.new(
signature: "question -> reasoning: str, code: str, answer: float",
max_iterations: 3
)
result = pot.forward(
question: "If a train travels 120 km in 1.5 hours, what's its speed in m/s?"
)
# The module automatically:
# 1. Reasons about the problem
# 2. Generates Ruby code: speed_kmh = 120 / 1.5; speed_ms = speed_kmh * 1000 / 3600
# 3. Executes safely in a sandbox
# 4. Returns the answer: 22.22 m/s5. MIPROv2: State-of-the-Art Optimization
The crown jewel of this release is the MIPROv2 optimizer, implementing the latest Bayesian optimization techniques for automatic prompt engineering:
optimizer = Desiru::Optimizers::MIPROv2.new(
program: your_program,
metric: f1_score,
max_bootstrapped_demos: 8,
max_labeled_demos: 16,
num_trials: 30
)
optimized_program = optimizer.compile(train_set, eval_set)
# Your program now has optimized instructions and carefully selected examplesMIPROv2 doesn’t just randomly try different prompts — it uses sophisticated Bayesian optimization to efficiently explore the space of possible instructions and demonstrations, often achieving significant performance improvements with minimal trials.
Real-World Impact
These features combine to enable powerful applications:
Automated Customer Support
support_agent = Desiru::Program.new do
analyze = Desiru::ChainOfThought.new("ticket -> category, urgency, suggested_action")
respond = Desiru::Modules::BestOfN.new(
module: Desiru::Generate.new("context, category, urgency -> response"),
n: 3,
selection_strategy: :llm_judge
)
end
# Optimize for customer satisfaction
optimized = MIPROv2.new(program: support_agent, metric: satisfaction_score).compile(historical_tickets)Code Analysis and Generation
code_reviewer = Desiru::Program.new do
understand = ProgramOfThought.new("code -> analysis, potential_issues")
suggest = ChainOfThought.new("code, issues -> improvements, refactored_code")
endEducational Content Generation
lesson_creator = Desiru::Program.new do
explain = ChainOfThought.new("concept -> explanation, examples")
verify = BestOfN.new(
module: Generate.new("explanation -> quiz_questions"),
selection_strategy: :diversity
)
endPerformance and Reliability
This release includes comprehensive testing with over 859 tests passing, ensuring reliability across all components. The integration test suite validates that all features work together seamlessly, from data collection through optimization to deployment.
What’s Next?
My Claude Swarm Desiru development team is already working on the next wave of features:
- MultiChainComparison: Compare multiple reasoning paths to find the best approach
- COPRO: Collaborative prompt optimization using multiple LLMs
- Streaming Support: Real-time token generation for interactive applications
- Multi-provider Abstractions: Seamless switching between OpenAI, Anthropic, and other providers
Getting Started
gem install desiruCheck out our examples directory for complete working programs, or dive into the documentation to learn more.
Join the Community
Desiru is open source and we welcome contributions! Whether you’re fixing bugs, adding features, or improving documentation, there’s a place for you in our community.
- GitHub: github.com/obie/desiru
- Issues: github.com/obie/desiru/issues
- Ruby+AI Discord #desiru channel: https://discord.gg/TGTWeh4krV
Desiru v0.2.0 is more than just a release — it’s a foundation for building the next generation of AI applications in Ruby. By bringing declarative, self-improving AI programming to Ruby developers, we’re opening new possibilities for creating intelligent systems that are both powerful and maintainable.
Ready to build something amazing? Try Desiru today and join us in shaping the future of AI development in Ruby!
