-
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)
- Workflow orchestration
- 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
# Environment variables (recommended)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=...
# Or Rails credentials
rails credentials:edit# config/initializers/ruby_llm_agents.rb
RubyLLM::Agents.configure do |config|
config.default_model = "gpt-4o"
endmodule LLM
class MyAgent < ApplicationAgent
cache 1.hour # Cache for 1 hour
end
endconfig.dashboard_auth = ->(controller) {
controller.current_user&.admin?
}result = LLM::MyAgent.call(query: "test")
result.content # The response
result.total_cost # Cost in USDmodule LLM
class StreamingAgent < ApplicationAgent
streaming true
end
end
LLM::StreamingAgent.call(prompt: "Write a story") do |chunk|
print chunk
endresult = LLM::VisionAgent.call(
question: "Describe this image",
with: "photo.jpg"
)def schema
@schema ||= RubyLLM::Schema.create do
string :title
array :tags, of: :string
end
endresult = LLM::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 (redacted)
- Prompts (optional)
- Responses (optional)
config.redaction = {
fields: %w[ssn credit_card],
patterns: [/\d{3}-\d{2}-\d{4}/]
}config.persist_prompts = false
config.persist_responses = falseconfig.retention_period = 30.daysRun cleanup regularly to delete old data.
workflow = RubyLLM::Agents::Workflow.pipeline(
Agent1, Agent2, Agent3
)
result = workflow.call(input: data)workflow = RubyLLM::Agents::Workflow.parallel(
a: AgentA,
b: AgentB
)
result = workflow.call(input: data)workflow = RubyLLM::Agents::Workflow.router(
classifier: IntentClassifier,
routes: {
"support" => SupportAgent,
"sales" => SalesAgent
}
)- 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