Module: LLM::ActiveRecord::ActsAsAgent

Defined in:
lib/llm/active_record/acts_as_agent.rb

Overview

ActiveRecord integration for persisting LLM::Agent state.

This wrapper reuses the same record-backed runtime surface as ActsAsLLM, but builds an LLM::Agent instead of an LLM::Context. Agent defaults such as model, tools, schema, instructions, and concurrency are configured on the model class and forwarded to an internal agent subclass.

Defined Under Namespace

Modules: ClassMethods, Hooks, InstanceMethods

Constant Summary collapse

EMPTY_HASH =
LLM::ActiveRecord::ActsAsLLM::EMPTY_HASH
DEFAULT_USAGE_COLUMNS =
LLM::ActiveRecord::ActsAsLLM::DEFAULT_USAGE_COLUMNS
DEFAULTS =
LLM::ActiveRecord::ActsAsLLM::DEFAULTS

Instance Method Summary collapse

Instance Method Details

#acts_as_agent(options = EMPTY_HASH) ⇒ void

This method returns an undefined value.

Installs the ‘acts_as_agent` wrapper on an ActiveRecord model.

Parameters:

  • options (Hash) (defaults to: EMPTY_HASH)

Options Hash (options):

  • :format (Symbol)

    Storage format for the serialized agent state. Use ‘:string` for text columns, or `:json` / `:jsonb` for structured JSON columns with ActiveRecord JSON typecasting enabled.

  • :tracer (Proc, LLM::Tracer, nil)

    Optional tracer or proc that resolves to one and is assigned through ‘llm.tracer = …` on the resolved provider.



75
76
77
78
79
80
81
# File 'lib/llm/active_record/acts_as_agent.rb', line 75

def acts_as_agent(options = EMPTY_HASH)
  options = DEFAULTS.merge(options)
  usage_columns = DEFAULT_USAGE_COLUMNS.merge(options[:usage_columns] || EMPTY_HASH)
  class_attribute :llm_agent_options, instance_accessor: false, default: DEFAULTS unless respond_to?(:llm_agent_options)
  self.llm_agent_options = options.merge(usage_columns: usage_columns.freeze).freeze
  extend Hooks
end