Class: Phronomy::Rails::AgentJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Phronomy::Rails::AgentJob
- Defined in:
- lib/phronomy/rails/agent_job.rb
Overview
ActiveJob-based job that runs a Phronomy agent in streaming mode and broadcasts each event to an ActionCable stream.
Enqueue with +perform_later+ to run the agent asynchronously in a background worker. Every streaming event is forwarded to ActionCable subscribers in real time.
Events broadcast to the ActionCable stream: { type: "token", content: "..." } — each content delta from the LLM { type: "done", output: "..." } — final complete output { type: "error", message: "..." } — when the agent or job raises
Instance Method Summary collapse
Instance Method Details
#perform(agent_class_name, input, channel:, stream:, config: {}) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/phronomy/rails/agent_job.rb', line 37 def perform(agent_class_name, input, channel:, stream:, config: {}) agent = Object.const_get(agent_class_name).new agent.stream(input, config: config.transform_keys(&:to_sym)) do |event| ActionCable.server.broadcast(stream, build_payload(event)) end rescue => e ActionCable.server.broadcast(stream, {type: "error", message: e.}) end |