Refactor configuration around a single adapter interface (v0.2.0) - #2
Open
arunkumarry wants to merge 1 commit into
Open
Refactor configuration around a single adapter interface (v0.2.0)#2arunkumarry wants to merge 1 commit into
arunkumarry wants to merge 1 commit into
Conversation
Replaces the four hand-written caller lambdas (llm_caller, messages_caller, embedding_caller, classifier_caller) with one config.adapter integration point, restructures configuration into validated groups, and shrinks the Rails initializer template to a minimal working config. - Add adapter layer: built-in :ruby_llm, :open_ai, :anthropic adapters (lazily required with actionable errors), Adapters::Custom for any provider, and an internal Legacy adapter so 0.1.x caller lambdas keep working unchanged - Add Invoker: user lambdas only receive the keyword arguments their signature accepts, fixing the 0.1.6 regression where the documented ->(prompt, model:) signature crashed with unknown keyword: :tools - Group configuration (routing/cache/compression/history/conversation) with flat 0.1.x keys kept as delegating aliases, including per-call overrides - Add fail-fast validation: configure validates values, optimize validates cross-field consistency, LlmOptimizer.validate! checks everything at boot (replaces silent warn-and-disable) - Route the classifier through the adapter via routing.classifier_model - Wire the schema option through to adapters (declared but unused since 0.1.7) - Fix history summarization injecting [content, token_info] as message content; stop connecting to localhost Redis when redis_url is unset - Rewrite initializer template (~25-line working config + commented appendix) and README; bump version to 0.2.0 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changed
Phase 1 of the ease-of-use refactor: the four hand-written caller lambdas (
llm_caller,messages_caller,embedding_caller,classifier_caller) are replaced by a single adapter interface, configuration is restructured into validated groups, and the Rails initializer template shrinks from ~120 lines of mixed provider examples to a ~25-line working config.Adapter interface
config.adapter = :ruby_llm/:open_ai/:anthropic— built-in adapters that lazily require their provider gem and raise an actionable error ("addgem \"ruby_llm\"to your Gemfile") if it's missingLlmOptimizer::Adapters::Custom.new(chat:, embed:)— escape hatch for any other providerLegacyadapter wraps the deprecated 0.1.x caller lambdas automatically, so existing initializers keep working unchangedconfig.routing.classifier_model— no more hand-written classification lambdaDefensive lambda invocation (
Invoker)User lambdas only receive the keyword arguments their signature accepts. This fixes a real regression: since 0.1.6 the gem passed
tools:unconditionally, so the documented->(prompt, model:)signature crashed withunknown keyword: :toolson every call.Grouped, validated configuration
config.routing.*,config.cache.*,config.compression.*,config.history.*,config.conversation.*route_to:)configurevalidates values immediately; eachoptimizevalidates cross-field consistency;LlmOptimizer.validate!(added to the generated initializer) fails fast at boot with messages that say exactly what to set — replacing the old silent warn-and-disable behaviorFixed in passing
schemaconfig (added in 0.1.7) is now actually passed through to adapters — it was declared but never used[content, token_info]array as the summary message content instead of the summary stringredis_urlno longer silently connects to localhost Redis; the cache is skipped with a warningtools/with_toolsare now true aliases of one value; removed deadtools_callerkey and the never-assigned@_current_llm_callerWhy
The initializer required writing 3–4 lambdas with subtly different signatures that drifted between releases — the README's own quick-start example crashed on 0.1.6+. Misconfigurations surfaced as silently degraded behavior at request time instead of clear errors. This PR fixes the root cause rather than patching the old shape (breaking changes are acceptable pre-1.0; version bumped to 0.2.0).
Reviewer notes
claude-3-5-sonnet-20241022→claude-sonnet-4-5;embedding_modeldefault is nownil(adapter picks its own)redis_url/embedding support now raisesConfigurationErrorinstead of warning and disabling — intentional behavior change, noted in CHANGELOG and READMEOpenAI/Anthropicadapters accept aclient:injection for apps that already build their own clientPhase 2 (conversation/cache interaction, system-prompt seeding, dead
EmbeddingClientremoval, timeout enforcement) will follow separately.🤖 Generated with Claude Code