-
Notifications
You must be signed in to change notification settings - Fork 4
FAQ
Common questions about RubyLLM::Agents.
RubyLLM::Agents is a Rails engine for building, managing, and monitoring LLM-powered AI agents. It provides:
- Clean DSL for agent configuration
- Automatic execution tracking
- Cost analytics and budget controls
- Reliability features (retries, fallbacks, circuit breakers)
- Real-time dashboard
| Aspect | RubyLLM::Agents | LangChain |
|---|---|---|
| Language | Ruby/Rails | Python/JS |
| Integration | Rails-native | Framework-agnostic |
| Focus | Production operations | Rapid prototyping |
| Observability | Built-in dashboard | Requires add-ons |
| Cost tracking | Automatic | Manual |
Through RubyLLM, we support:
- OpenAI (GPT-4, GPT-4o, GPT-3.5)
- Anthropic (Claude 3.5, Claude 3)
- Google (Gemini 2.0, Gemini 1.5)
- And more via RubyLLM
- Ruby >= 3.1.0
- Rails >= 7.0
Unified configuration (recommended, v2.1+):
# config/initializers/ruby_llm_agents.rb
RubyLLM::Agents.configure do |config|
config.openai_api_key = ENV["OPENAI_API_KEY"]
config.anthropic_api_key = ENV["ANTHROPIC_API_KEY"]
config.gemini_api_key = ENV["GOOGLE_API_KEY"]
endOr use environment variables (auto-detected by RubyLLM):
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=...No. As of v2.1.0, all RubyLLM provider settings (API keys, custom endpoints, Bedrock credentials, etc.) can be configured directly in RubyLLM::Agents.configure. They are automatically forwarded to RubyLLM.config. See Configuration for the full list of forwarded attributes.
# config/initializers/ruby_llm_agents.rb
RubyLLM::Agents.configure do |config|
config.default_model = "gpt-4o"
endclass MyAgent < ApplicationAgent
cache 1.hour # Cache for 1 hour
endconfig.dashboard_auth = ->(controller) {
controller.current_user&.admin?
}result = MyAgent.call(query: "test")
result.content # The response
result.total_cost # Cost in USDclass StreamingAgent < ApplicationAgent
streaming true
end
StreamingAgent.call(user: "Write a story") do |chunk|
print chunk
endresult = VisionAgent.call(
question: "Describe this image",
with: "photo.jpg"
)def schema
@schema ||= RubyLLM::Schema.create do
string :title
array :tags, of: :string
end
endresult = MyAgent.call(query: "test", dry_run: true)
# Shows prompts without making API callCosts are calculated based on:
- Input tokens × model input price
- Output tokens × model output price
Prices are from RubyLLM's model pricing data.
config.budgets = {
global_daily: 100.0, # $100/day
global_monthly: 2000.0, # $2000/month
enforcement: :hard # Block when exceeded
}RubyLLM::Agents::BudgetTracker.status
# => { global_daily: { limit: 100, current: 45.50, ... } }Check if budget is exceeded:
RubyLLM::Agents::BudgetTracker.exceeded?(:global, :daily)retries max: 3, backoff: :exponentialFailed requests are automatically retried with increasing delays.
model "gpt-4o"
fallback_models "gpt-4o-mini", "claude-3-haiku"If the primary model fails, fallbacks are tried in order.
Circuit breakers prevent cascading failures by temporarily blocking requests to failing services.
circuit_breaker errors: 10, within: 60, cooldown: 300After 10 errors in 60 seconds, requests are blocked for 5 minutes.
- Enable caching:
cache 1.hour - Use streaming:
streaming true - Use faster models:
model "gpt-4o-mini" - Enable async logging:
config.async_logging = true
- Enable caching
- Use cheaper models for simple tasks
- Set budget limits
- Optimize prompts (shorter = cheaper)
- Too much data: Set
config.retention_period = 30.days - Missing indexes: Run
rails generate ruby_llm_agents:upgrade - Complex queries: Reduce
config.dashboard_per_page
By default:
- Agent type, model, status
- Token counts, costs, duration
- Parameters
- Prompts (optional)
- Responses (optional)
config.persist_prompts = false
config.persist_responses = falseconfig.retention_period = 30.daysRun cleanup regularly to delete old data.
Compose agents by calling one from another's result:
# Sequential composition
intent_result = IntentAgent.call(query: user_input)
response_result = ResponseAgent.call(
query: user_input,
intent: intent_result.content[:intent]
)For complex orchestration patterns (pipelines, parallel execution, routing), use a dedicated workflow library like Temporal or Sidekiq.
- Check for errors:
result.success? - Check schema matches response
- Try dry_run to see prompts
- Check async logging: Is job processor running?
- Try sync:
config.async_logging = false - Check for database errors
- Add retries with backoff
- Add fallback models
- Implement request queuing
- Disable response storage
- Set retention period
- Use streaming for large responses
GitHub Issues: https://github.com/adham90/ruby_llm-agents/issues
GitHub Discussions: https://github.com/adham90/ruby_llm-agents/discussions
See Contributing guide.
- Troubleshooting - Detailed solutions
- Configuration - Full config reference
- API Reference - Class documentation