Class: Phronomy::Agent::LLMCallRecord
- Inherits:
-
Object
- Object
- Phronomy::Agent::LLMCallRecord
- Defined in:
- lib/phronomy/agent/llm_call_record.rb
Constant Summary collapse
- STATUSES =
%i[completed failed cancelled].freeze
- ATTRIBUTES =
%i[ llm_call_id execution_id sequence status manifest_ref output_ref error_ref usage_ref started_at completed_at metadata ].freeze
Class Method Summary collapse
-
.from_h(hash) ⇒ LLMCallRecord
Restores an LLM Call record from its canonical durable representation.
Instance Method Summary collapse
-
#initialize(execution_id:, sequence:, status:, manifest_ref:, llm_call_id: SecureRandom.uuid, output_ref: nil, error_ref: nil, usage_ref: nil, started_at: Time.now.utc.iso8601(6), completed_at: nil, metadata: {}) ⇒ LLMCallRecord
constructor
A new instance of LLMCallRecord.
-
#to_h ⇒ Hash{String => Object}
Returns the canonical durable representation of this LLM Call record.
Constructor Details
#initialize(execution_id:, sequence:, status:, manifest_ref:, llm_call_id: SecureRandom.uuid, output_ref: nil, error_ref: nil, usage_ref: nil, started_at: Time.now.utc.iso8601(6), completed_at: nil, metadata: {}) ⇒ LLMCallRecord
Returns a new instance of LLMCallRecord.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/phronomy/agent/llm_call_record.rb', line 17 def initialize( execution_id:, sequence:, status:, manifest_ref:, llm_call_id: SecureRandom.uuid, output_ref: nil, error_ref: nil, usage_ref: nil, started_at: Time.now.utc.iso8601(6), completed_at: nil, metadata: {} ) values = binding.local_variables.to_h { |name| [name, binding.local_variable_get(name)] } ATTRIBUTES.each do |name| value = values.fetch(name) value = value.to_sym if name == :status instance_variable_set("@#{name}", Immutable.copy(value)) end raise ArgumentError, "unknown LLM Call status: #{status.inspect}" unless STATUSES.include?(status) raise ArgumentError, "LLM Call sequence must be positive" unless sequence.positive? Immutable.validate_canonical_json!(, label: "LLM Call metadata") freeze end |
Class Method Details
.from_h(hash) ⇒ LLMCallRecord
Restores an LLM Call record from its canonical durable representation. String and Symbol top-level keys are accepted so database adapters may pass either a parsed JSON object or a Ruby-native Hash.
61 62 63 64 65 66 67 68 |
# File 'lib/phronomy/agent/llm_call_record.rb', line 61 def self.from_h(hash) attributes = ATTRIBUTES.to_h do |name| key = hash.key?(name.to_s) ? name.to_s : name [name, hash.fetch(key)] end attributes[:status] = attributes.fetch(:status).to_sym new(**attributes) end |
Instance Method Details
#to_h ⇒ Hash{String => Object}
Returns the canonical durable representation of this LLM Call record.
46 47 48 49 50 51 52 |
# File 'lib/phronomy/agent/llm_call_record.rb', line 46 def to_h ATTRIBUTES.to_h do |name| value = public_send(name) value = value.to_s if name == :status [name.to_s, value] end end |