Skip to content

Fix agent not propagating assume_model_exists from class config#680

Merged
crmne merged 2 commits intocrmne:mainfrom
jeffmcfadden:679-fix-assume-exists-when-reloading-agent-chat
Mar 16, 2026
Merged

Fix agent not propagating assume_model_exists from class config#680
crmne merged 2 commits intocrmne:mainfrom
jeffmcfadden:679-fix-assume-exists-when-reloading-agent-chat

Conversation

@jeffmcfadden
Copy link
Contributor

What this does

Fixes #679

Fix Agent.find not propagating assume_model_exists from class-level config.

This is most likely to be encountered when attempting to "continue" a previous chat with an Agent.

Agent.find loads a chat record from the database and then calls apply_configuration, which triggers to_llm. to_llm creates a new RubyLLM::Chat using the record's assume_model_exists attribute — but since this is a transient attr_accessor, it defaults to nil/false after an ActiveRecord load. This causes Models.resolve to raise ModelNotFoundError for models not in the registry, even when the agent class declares assume_model_exists: true.

with_rails_chat_record (used by create/create!) doesn't have this problem because it spreads **chat_kwargs into the record constructor, which includes assume_model_exists: true:

record = resolved_chat_model.public_send(method_name, **chat_kwargs, **chat_options)

The find path was missing the equivalent propagation. This fix adds it by setting assume_model_exists from chat_kwargs on the loaded record before apply_configuration runs.

Type of change

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

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Required for new features

  • I opened an issue before writing code and received maintainer approval
  • Linked issue: #___

PRs for new features or enhancements without a prior approved issue will be closed.

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
    • [-] For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • [-] I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

AI-generated code

  • I used AI tools to help write this code
  • I have reviewed and understand all generated code (required if above is checked)

API changes

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

@crmne crmne merged commit 404a270 into crmne:main Mar 16, 2026
2 checks passed
@crmne
Copy link
Owner

crmne commented Mar 16, 2026

Thanks for catching and fixing this.

I added a small follow-up to cover the remaining reload paths where assume_model_exists could still be dropped, plus regression specs so those paths stay protected.

Really appreciate the original report and fix.

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.

[BUG] Agent.find not propagating assume_model_exists from class-level config

2 participants