Module: RubyLLM::Agents::Execution::Replayable
- Extended by:
- ActiveSupport::Concern
- Included in:
- RubyLLM::Agents::Execution
- Defined in:
- app/models/ruby_llm/agents/execution/replayable.rb
Overview
Adds replay capability to execution records.
Allows re-executing a previous run with the same inputs, or with tweaked parameters for A/B testing and debugging.
Instance Method Summary collapse
-
#replay(model: nil, temperature: nil, **overrides) ⇒ Object
Re-executes this agent run with the same (or overridden) inputs.
-
#replay? ⇒ Boolean
Returns whether this execution is a replay of another.
-
#replay_source ⇒ RubyLLM::Agents::Execution?
Returns the original execution this was replayed from.
-
#replayable? ⇒ Boolean
Returns whether this execution can be replayed.
-
#replays ⇒ ActiveRecord::Relation
Returns all executions that are replays of this one.
Instance Method Details
#replay(model: nil, temperature: nil, **overrides) ⇒ Object
Re-executes this agent run with the same (or overridden) inputs.
Loads the original agent class, reconstructs its parameters from the execution detail record, and executes through the full pipeline. The new execution is tracked separately and linked via metadata.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/ruby_llm/agents/execution/replayable.rb', line 39 def replay(model: nil, temperature: nil, **overrides) validate_replayable! agent_klass = resolve_agent_class params = build_replay_params(overrides) opts = params.merge(_replay_source_id: id) opts[:model] = model if model opts[:temperature] = temperature if temperature agent_klass.call(**opts) end |
#replay? ⇒ Boolean
Returns whether this execution is a replay of another.
88 89 90 |
# File 'app/models/ruby_llm/agents/execution/replayable.rb', line 88 def replay? &.dig("replay_source_id").present? end |
#replay_source ⇒ RubyLLM::Agents::Execution?
Returns the original execution this was replayed from.
77 78 79 80 81 82 |
# File 'app/models/ruby_llm/agents/execution/replayable.rb', line 77 def replay_source source_id = &.dig("replay_source_id") return nil unless source_id self.class.find_by(id: source_id) end |
#replayable? ⇒ Boolean
Returns whether this execution can be replayed.
55 56 57 58 59 60 61 62 63 |
# File 'app/models/ruby_llm/agents/execution/replayable.rb', line 55 def replayable? return false if agent_type.blank? return false if detail.nil? resolve_agent_class true rescue false end |
#replays ⇒ ActiveRecord::Relation
Returns all executions that are replays of this one.
69 70 71 |
# File 'app/models/ruby_llm/agents/execution/replayable.rb', line 69 def replays self.class.replays_of(id) end |