Class: ActiveAgent::Dashboard::AgentRun
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ActiveAgent::Dashboard::AgentRun
- Defined in:
- lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_run.rb
Overview
Tracks individual agent execution runs.
Each run captures input, output, timing, token usage, and any errors that occurred during execution.
Instance Method Summary collapse
-
#add_log(message, level: :info) ⇒ Object
Add a log entry.
-
#broadcast_update ⇒ Object
Stream output updates via ActionCable.
-
#calculated_duration_ms ⇒ Object
Calculate duration if not set.
-
#cancel! ⇒ Object
Cancel a running execution.
-
#finished? ⇒ Boolean
Check if run is finished.
-
#in_progress? ⇒ Boolean
Check if run is still in progress.
-
#summary ⇒ Object
Get a summary for display.
Methods inherited from ApplicationRecord
for_owner, owner_association, table_name
Instance Method Details
#add_log(message, level: :info) ⇒ Object
Add a log entry
39 40 41 42 43 44 45 46 47 |
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_run.rb', line 39 def add_log(, level: :info) new_logs = logs || [] new_logs << { timestamp: Time.current.iso8601, level: level.to_s, message: } update!(logs: new_logs) end |
#broadcast_update ⇒ Object
Stream output updates via ActionCable
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_run.rb', line 82 def broadcast_update return unless defined?(ActionCable) ActionCable.server.broadcast( "agent_run_#{id}", { type: "update", run: summary } ) end |
#calculated_duration_ms ⇒ Object
Calculate duration if not set
50 51 52 53 54 55 |
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_run.rb', line 50 def calculated_duration_ms return duration_ms if duration_ms.present? return nil unless started_at && completed_at ((completed_at - started_at) * 1000).to_i end |
#cancel! ⇒ Object
Cancel a running execution
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_run.rb', line 95 def cancel! return unless in_progress? update!( status: :cancelled, completed_at: Time.current, error_message: "Cancelled by user" ) broadcast_update end |
#finished? ⇒ Boolean
Check if run is finished
63 64 65 |
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_run.rb', line 63 def finished? complete? || failed? || cancelled? end |
#in_progress? ⇒ Boolean
Check if run is still in progress
58 59 60 |
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_run.rb', line 58 def in_progress? pending? || running? end |
#summary ⇒ Object
Get a summary for display
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_run.rb', line 68 def summary { id: id, status: status, input_preview: input_prompt&.truncate(100), output_preview: output&.truncate(200), duration_ms: calculated_duration_ms, tokens: total_tokens, created_at: created_at, error: } end |