Module: RubyLLM::Agents::Routing::ClassMethods
- Defined in:
- lib/ruby_llm/agents/routing/class_methods.rb
Overview
Class-level DSL for defining routes and classification categories.
Extended into any BaseAgent subclass that includes the Routing concern. Provides ‘route`, `default_route`, and accessor methods for route definitions.
Instance Method Summary collapse
-
#agent_type ⇒ Symbol
Returns :router for instrumentation/tracking.
-
#call(message: nil, **kwargs, &block) ⇒ RoutingResult
Override call to accept message: as a named param.
-
#default_route(name, agent: nil) ⇒ Object
Set the default route for unmatched classifications.
-
#default_route_name ⇒ Symbol
Returns the default route name (including inherited).
-
#route(name, description, agent: nil) ⇒ Object
Define a classification route.
-
#routes ⇒ Hash{Symbol => Hash}
Returns all defined routes (including inherited).
Instance Method Details
#agent_type ⇒ Symbol
Returns :router for instrumentation/tracking.
73 74 75 |
# File 'lib/ruby_llm/agents/routing/class_methods.rb', line 73 def agent_type :router end |
#call(message: nil, **kwargs, &block) ⇒ RoutingResult
Override call to accept message: as a named param.
82 83 84 85 86 87 88 |
# File 'lib/ruby_llm/agents/routing/class_methods.rb', line 82 def call(message: nil, **kwargs, &block) if super(**kwargs.merge(message: ), &block) else super(**kwargs, &block) end end |
#default_route(name, agent: nil) ⇒ Object
Set the default route for unmatched classifications.
46 47 48 49 50 51 52 53 |
# File 'lib/ruby_llm/agents/routing/class_methods.rb', line 46 def default_route(name, agent: nil) @default_route_name = name.to_sym @routes ||= {} @routes[name.to_sym] ||= { description: "Default / general category", agent: agent } end |
#default_route_name ⇒ Symbol
Returns the default route name (including inherited).
66 67 68 |
# File 'lib/ruby_llm/agents/routing/class_methods.rb', line 66 def default_route_name @default_route_name || (superclass.respond_to?(:default_route_name) ? superclass.default_route_name : :general) end |
#route(name, description, agent: nil) ⇒ Object
Define a classification route.
33 34 35 36 37 38 39 |
# File 'lib/ruby_llm/agents/routing/class_methods.rb', line 33 def route(name, description, agent: nil) @routes ||= {} @routes[name.to_sym] = { description: description, agent: agent } end |
#routes ⇒ Hash{Symbol => Hash}
Returns all defined routes (including inherited).
58 59 60 61 |
# File 'lib/ruby_llm/agents/routing/class_methods.rb', line 58 def routes parent = superclass.respond_to?(:routes) ? superclass.routes : {} parent.merge(@routes || {}) end |