Feature Request
Allow the model class method in RubyLLM::Agent to accept a block for dynamic model selection at runtime, consistent with how tools, params, headers, and schema already support blocks.
Use case
Selecting a model based on runtime context — e.g., routing simple tasks to a cheaper model:
class CardAgent < RubyLLM::Agent
inputs :card
model { card.special_type? ? 'gpt-4.1-mini' : 'gpt-4.1-nano' }
instructions 'You are helpful.'
end
CardAgent.chat(card: @card)
Current behavior
model only accepts a string:
Proposed behavior
model also accepts a block, evaluated in the same runtime context as other block-based DSLs (tools, params, etc.), with access to declared inputs:
inputs :quality
model { quality == :high ? 'gpt-4.1-mini' : 'gpt-4.1-nano' }
Implementation
I have a working implementation ready (~13 lines of production code) that follows the existing apply_* pattern. Happy to open a PR if this aligns with the project's direction.
Feature Request
Allow the
modelclass method inRubyLLM::Agentto accept a block for dynamic model selection at runtime, consistent with howtools,params,headers, andschemaalready support blocks.Use case
Selecting a model based on runtime context — e.g., routing simple tasks to a cheaper model:
Current behavior
modelonly accepts a string:Proposed behavior
modelalso accepts a block, evaluated in the same runtime context as other block-based DSLs (tools,params, etc.), with access to declaredinputs:Implementation
I have a working implementation ready (~13 lines of production code) that follows the existing
apply_*pattern. Happy to open a PR if this aligns with the project's direction.