Skip to content

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

Description

@jeffmcfadden

Basic checks

  • I searched existing issues - this hasn't been reported
  • I can reproduce this consistently
  • This is a RubyLLM bug, not my application code

What's broken?

When loading a RubyLLM::Agent to continue a conversation, assume_model_exists is not loaded from the class config.

How to reproduce

Let's say you have an Agent, and a Chat that already exists. If you want to "continue" that chat, you'd probably do something like this:

class MyAgent < RubyLLM::Agent
  model "gpt-6.7", provider: :openai, assume_model_exists: true
end
MyAgent.find(self.chat.id)

Expected behavior

The Chat loads fine, the configuration is applied, and assume_model_exists is passed through.

What actually happened

That will raise RubyLLM::ModelNotFoundError: Unknown model: gpt-6.7 for provider: openai, even though assume_model_exists is true.

Here's what's happening:

  1. MyAgent.find(chat_id) in loads the Chat record via ActiveRecord, then calls apply_configuration
  2. apply_configuration triggers to_llm, which creates a new RubyLLM::Chat with assume_model_exists: false (since the attr_accessor defaults to nil)
  3. That tries to resolve model gpt-6.7 in the model registry, fails with ModelNotFoundError

Environment

  • Ruby 3.4.5
  • RubyLLM 1.13.1
  • Rails 8.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions