Skip to content

Start from the new provider's options when a subclass switches embed_with - #756

Open
yorzi wants to merge 2 commits into
activeagents:mainfrom
yorzi:fix/embedding-provider-inheritance
Open

yorzi wants to merge 2 commits into
activeagents:mainfrom
yorzi:fix/embedding-provider-inheritance

Conversation

@yorzi

@yorzi yorzi commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What this does

embed_with always merged the parent's embed_options over the new provider's configuration:

class ParentAgent < ActiveAgent::Base
  embed_with :openai, model: "parent-model", dimensions: 9
end

class ChildAgent < ParentAgent
  embed_with :mock, dimensions: 3
end

ChildAgent.embed_options[:model]  # => "parent-model" on main

So a child that switched services kept the parent's model, dimensions and any credentials from the parent's provider config, and sent them to the new provider. generate_with already discards inherited options when the service changes ("Different Service, different APIs").

embed_with now keeps inherited options only when the resolved provider class is unchanged. A child that names another configuration of the same provider (an alias with service: "OpenAI") still inherits the parent's options, with its own on top.

Decision for the maintainer

The check compares resolved provider classes, where generate_with compares the configs' service: strings. The class works when no config exists and the provider is inferred from its key (embed_with :openai then embed_with :mock with an empty active_agent.yml), where both service: values are nil and the string check would keep the parent's options; the last test covers that case. If you'd rather the two methods share one rule, I can move generate_with to the class comparison in a separate PR.

Tests

test/features/embedding_provider_inheritance_test.rb:

  • a child switching from :openai to :mock embeds with the mock and does not carry the parent's model, and the parent is unchanged;
  • a child using an alias for the same service inherits the parent's model and overrides dimensions (guard; passes before too);
  • with no configuration, a switch inferred from the provider keys drops the parent's dimensions.

The first and third fail on main and pass with the change.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the contributing guide
  • This fits activeagent's stated focus
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my use case

Related issue

Fixes #752

Quality check

  • The project's hooks and linters pass (bin/rubocop on the changed files)
  • The new tests fail before this change and pass after it
  • The full test suite passes (run in full, Ruby 3.3.5, gemfiles/rails8.gemfile: 4729 runs, 0 failures, 11 errors, 66 skips. The 11 errors are all in actionagent/test/cli_contract_test.rb and are the same on unmodified main in my environment (NoMethodError: undefined method id' for an instance of Hashin rack-session under WebMock'sto_rack`), so they are unrelated to this change)
  • I updated documentation where needed (CHANGELOG entry)
  • I didn't edit generated files by hand

Ownership

  • I understand every line of this change and can answer questions about it

API changes

  • Breaking change
  • New public methods or classes
  • Changed method signatures
  • No API changes

Not changed: with an alias for the same service, the parent's options still win over the alias's own configuration (for example its access_token), as they do in generate_with.

yorzi added 2 commits December 3, 2026 22:24
The embedding provider class changed but the parent options still won
the configuration merge. Compare the resolved classes so aliases
inherit and different services start with their own settings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A subclass that switches embed_with keeps the parent provider's options

1 participant