Module: Observ::ChatEnhancements
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/observ/chat_enhancements.rb
Overview
Concern for enhancing Chat models with observability and agent support This provides the integration between your Chat model and the Observ system
Usage:
class Chat < ApplicationRecord
include Observ::ChatEnhancements
# Optional: Define agent_class method if using agents
def agent_class
return BaseAgent if agent_class_name.blank?
agent_class_name.constantize
end
end
Instance Method Summary collapse
-
#ensure_agent_configured ⇒ Object
Ensure agent parameters are set when needed This is called lazily when the chat is actually used.
-
#setup_tools ⇒ Object
Setup tools for the chat session Override this in your Chat model if you need custom tool setup.
Instance Method Details
#ensure_agent_configured ⇒ Object
Ensure agent parameters are set when needed This is called lazily when the chat is actually used
Note: Instructions are already set in initialize_agent_on_create (after_create callback) and should NOT be re-applied on every message. Only parameters need to be re-set because they are lost when the chat is reloaded from the database.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/concerns/observ/chat_enhancements.rb', line 44 def ensure_agent_configured return unless respond_to?(:agent_class) && agent_class_name.present? return if @_agent_params_configured # Set prompt version override if specified if respond_to?(:prompt_version) && prompt_version.present? && agent_class.included_modules.include?(Observ::PromptManagement) Thread.current[:observ_prompt_version_override] = prompt_version end begin # Only re-apply parameters, not instructions # Instructions were already set at creation time agent_class.setup_parameters(self) @_agent_params_configured = true ensure Thread.current[:observ_prompt_version_override] = nil end end |
#setup_tools ⇒ Object
Setup tools for the chat session Override this in your Chat model if you need custom tool setup
33 34 35 36 |
# File 'app/models/concerns/observ/chat_enhancements.rb', line 33 def setup_tools return unless respond_to?(:agent_class) agent_class.setup_tools(self) end |