Class: SolidAgents::Runs::Dispatch

Inherits:
Object
  • Object
show all
Defined in:
app/services/solid_agents/runs/dispatch.rb

Class Method Summary collapse

Class Method Details

.call(source:, agent_key:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/solid_agents/runs/dispatch.rb', line 6

def self.call(source:, agent_key:)
  environment = Rails.env
  agent = SolidAgents::Agent.enabled.for_environment(environment).find_by!(key: agent_key)

  run = SolidAgents::Run.create!(
    agent: agent,
    source_type: source.class.name,
    source_id: source.respond_to?(:id) ? source.id : nil,
    runtime: agent.runtime,
    environment: environment,
    external_key: "#{source.class.name}-#{source.respond_to?(:id) ? source.id : source.object_id}-#{Time.current.to_i}",
    repo_path: agent.working_directory,
    base_branch: "main",
    max_iterations: agent.max_iterations,
    stage: "received",
    stage_owner: "alex"
  )

  context = ContextBuilder.call(source: source)
  run.update!(prompt_payload: context)
  run.append_event!("run_received", message: "Run received from source", payload: {"agent_key" => agent.key, "source_type" => run.source_type}, actor: "alex")
  run.create_work_item!(column_key: run.stage, title: "Fix #{run.source_type}##{run.source_id || "n/a"}", summary: "Automated error-fixing pipeline", metadata_json: {"agent_key" => agent.key})

  SolidAgents::ExecuteRunJob.perform_later(run.id)
  run
end