-
-
Notifications
You must be signed in to change notification settings - Fork 79
Add RubyLLM provider for unified multi-provider LLM access #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| --- | ||
| title: RubyLLM Provider | ||
| description: Unified access to 15+ LLM providers through the RubyLLM gem. Use OpenAI, Anthropic, Gemini, Bedrock, Azure, Ollama, and more with a single provider configuration. | ||
| --- | ||
| # {{ $frontmatter.title }} | ||
|
|
||
| The RubyLLM provider gives your agents access to 15+ LLM providers through [RubyLLM](https://rubyllm.com)'s unified API. Switch between OpenAI, Anthropic, Gemini, Bedrock, Azure, Ollama, and more by changing the model parameter. | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Basic Setup | ||
|
|
||
| Configure RubyLLM in your agent: | ||
|
|
||
| ```ruby | ||
| class MyAgent < ApplicationAgent | ||
| generate_with :ruby_llm, model: "gpt-4o-mini" | ||
| end | ||
| ``` | ||
|
|
||
| ### RubyLLM API Keys | ||
|
|
||
| RubyLLM manages its own API keys. Configure them in an initializer: | ||
|
|
||
| ```ruby | ||
| # config/initializers/ruby_llm.rb | ||
| RubyLLM.configure do |config| | ||
| config.openai_api_key = Rails.application.credentials.dig(:openai, :api_key) | ||
| config.anthropic_api_key = Rails.application.credentials.dig(:anthropic, :api_key) | ||
| config.gemini_api_key = Rails.application.credentials.dig(:gemini, :api_key) | ||
| # Add keys for any providers you want to use | ||
| end | ||
| ``` | ||
|
|
||
| ### Configuration File | ||
|
|
||
| Set up RubyLLM in `config/active_agent.yml`: | ||
|
|
||
| ```yaml | ||
| ruby_llm: &ruby_llm | ||
| service: "RubyLLM" | ||
|
|
||
| development: | ||
| ruby_llm: | ||
| <<: *ruby_llm | ||
|
|
||
| production: | ||
| ruby_llm: | ||
| <<: *ruby_llm | ||
| ``` | ||
|
|
||
| ## Supported Models | ||
|
|
||
| RubyLLM automatically resolves which provider to use based on the model ID. Any model supported by RubyLLM works with this provider. For the complete list, see [RubyLLM's documentation](https://rubyllm.com). | ||
|
|
||
| ### Examples by Provider | ||
|
|
||
| | Provider | Example Models | | ||
| |----------|---------------| | ||
| | **OpenAI** | `gpt-4o`, `gpt-4o-mini`, `gpt-4.1` | | ||
| | **Anthropic** | `claude-sonnet-4-5-20250929`, `claude-haiku-4-5` | | ||
| | **Google Gemini** | `gemini-2.0-flash`, `gemini-1.5-pro` | | ||
| | **AWS Bedrock** | Bedrock-hosted models | | ||
| | **Azure OpenAI** | Azure-hosted OpenAI models | | ||
| | **Ollama** | `llama3`, `mistral`, locally-hosted models | | ||
|
|
||
| Switch providers by changing the model: | ||
|
|
||
| ```ruby | ||
| class FlexibleAgent < ApplicationAgent | ||
| # Any of these work with the same provider config: | ||
| generate_with :ruby_llm, model: "gpt-4o-mini" | ||
| # generate_with :ruby_llm, model: "claude-sonnet-4-5-20250929" | ||
| # generate_with :ruby_llm, model: "gemini-2.0-flash" | ||
| end | ||
| ``` | ||
|
|
||
| ## Provider-Specific Parameters | ||
|
|
||
| ### Required Parameters | ||
|
|
||
| - **`model`** - Model identifier (e.g., "gpt-4o-mini", "claude-sonnet-4-5-20250929") | ||
|
|
||
| ### Sampling Parameters | ||
|
|
||
| - **`temperature`** - Controls randomness (0.0 to 1.0) | ||
| - **`max_tokens`** - Maximum number of tokens to generate (passed via RubyLLM's `params:` merge) | ||
|
|
||
| ### Client Configuration | ||
|
|
||
| Configure timeouts and other settings through RubyLLM directly: | ||
|
|
||
| ```ruby | ||
| RubyLLM.configure do |config| | ||
| config.request_timeout = 120 | ||
| end | ||
| ``` | ||
|
|
||
| ## Tool Calling | ||
|
|
||
| RubyLLM supports tool/function calling for models that support it. Use the standard ActiveAgent tool format: | ||
|
|
||
| ```ruby | ||
| class WeatherAgent < ApplicationAgent | ||
| generate_with :ruby_llm, model: "gpt-4o-mini" | ||
|
|
||
| def forecast | ||
| prompt( | ||
| message: "What's the weather in Boston?", | ||
| tools: [{ | ||
| name: "get_weather", | ||
| description: "Get weather for a location", | ||
| parameters: { | ||
| type: "object", | ||
| properties: { | ||
| location: { type: "string", description: "City name" } | ||
| }, | ||
| required: ["location"] | ||
| } | ||
| }] | ||
| ) | ||
| end | ||
|
|
||
| def get_weather(location:) | ||
| WeatherService.fetch(location) | ||
| end | ||
| end | ||
| ``` | ||
|
|
||
| ## Embeddings | ||
|
|
||
| Generate embeddings through RubyLLM's unified embedding API: | ||
|
|
||
| ```ruby | ||
| class SearchAgent < ApplicationAgent | ||
| generate_with :ruby_llm, model: "gpt-4o-mini" | ||
| embed_with :ruby_llm, model: "text-embedding-3-small" | ||
|
|
||
| def index_document | ||
| embed(input: "Document text to embed") | ||
| end | ||
| end | ||
| ``` | ||
|
|
||
| ## Streaming | ||
|
|
||
| Streaming is supported for models that support it: | ||
|
|
||
| ```ruby | ||
| class StreamingAgent < ApplicationAgent | ||
| generate_with :ruby_llm, model: "gpt-4o-mini", stream: true | ||
| end | ||
| ``` | ||
|
|
||
| See [Streaming](/agents/streaming) for ActionCable integration and real-time updates. | ||
|
|
||
| ## When to Use RubyLLM vs Direct Providers | ||
|
|
||
| **Use RubyLLM when:** | ||
| - You want to switch between providers without changing configuration | ||
| - You prefer RubyLLM's key management via `RubyLLM.configure` | ||
| - You want access to providers that ActiveAgent doesn't have a dedicated implementation for (e.g., Gemini, Bedrock) | ||
| - You want a single gem dependency for multi-provider support | ||
|
|
||
| **Use a direct provider (OpenAI, Anthropic) when:** | ||
| - You need provider-specific features (MCP servers, extended thinking, JSON schema mode) | ||
| - You want the tightest integration with a provider's gem SDK | ||
| - You need provider-specific error handling classes | ||
|
|
||
| ## Related Documentation | ||
|
|
||
| - [Providers Overview](/providers) - Compare all available providers | ||
| - [Getting Started](/getting_started) - Complete setup guide | ||
| - [Configuration](/framework/configuration) - Environment-specific settings | ||
| - [Tools](/actions/tools) - Function calling | ||
| - [Embeddings](/actions/embeddings) - Vector generation | ||
| - [Streaming](/agents/streaming) - Real-time response updates | ||
| - [RubyLLM Documentation](https://rubyllm.com) - Official RubyLLM docs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.