Class: AgentRequestJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/agent_request_job.rb

Overview

Executes an LLM agent loop as a background job with retry logic for transient failures (network errors, rate limits, server errors).

Emits events via Events::Bus as it progresses, making results visible to any subscriber (TUI, WebSocket clients). All retry and failure notifications are emitted as Events::SystemMessage to avoid polluting the LLM context window.

Examples:

Inline execution (TUI)

AgentRequestJob.perform_now(session.id)

Background execution (future Brain/TUI separation)

AgentRequestJob.perform_later(session.id)

Instance Method Summary collapse

Instance Method Details

#perform(session_id) ⇒ Object

Parameters:

  • session_id (Integer)

    ID of the session to process



36
37
38
39
40
41
42
# File 'app/jobs/agent_request_job.rb', line 36

def perform(session_id)
  session = Session.find(session_id)
  agent_loop = AgentLoop.new(session: session)
  agent_loop.run
ensure
  agent_loop&.finalize
end