class RubyLLM::AgUI::Run
Runs one RubyLLM 2.x chat turn as one AG-UI 1.0 run.
input = RubyLLM::AgUI::Input.parse(request_body) chat = host_chat_for(actor, input.thread_id) # host-owned RubyLLM::Chat RubyLLM::AgUI::Run.new(chat:, input:, scope: "tenant:#{actor.id}").stream(to: response.stream)
The host owns authentication, authorization, the chat, the tools a run may use and the transport. This class owns the run’s identity (reserved before any provider work), the ordering of the events, and the outcome: a cancelled run is never reported as success, a provider failure is a sanitized RUN_ERROR, a paused run is an interrupt rather than a success, and an identity that is already reserved is never executed a second time.
scope is the host’s tenant/actor boundary, built from authenticated identity. The gem takes it from the host rather than deriving it from the input, because a scope derived from anything the client sent would let one client attach to another’s run.
Attributes
The reserved record or final outcome observed by this run, including a reconnect. Nil before the run obtains its reservation.
Public Class Methods
# File lib/ruby_llm/ag_ui/run.rb, line 28 def initialize(chat:, input:, scope:, store: nil, logger: nil, redact: nil, clock: nil, expires_in: nil, state: nil, emit_tool_progress: RubyLLM::AgUI.config.emit_tool_progress) defaults = RubyLLM::AgUI.config @chat = chat @input = input @scope = scope @store = store || defaults.run_store! @logger = logger || defaults.logger @redact = redact @clock = clock || defaults.clock @expires_in = expires_in || defaults.interrupt_ttl @emit_tool_progress = emit_tool_progress @mutex = Mutex.new validate! @state = state.nil? ? @input.state : state end
rubocop:disable-next Metrics/ParameterLists – one keyword per host-supplied or overridable value
Public Instance Methods
Source
# File lib/ruby_llm/ag_ui/run.rb, line 53 def stream(to:) resume.plan(now: @clock.call) if resume.needed? reservation = reserve @record = reservation.record return execute(@record, to) if reservation.created? reconnect(@record, to) end
Reserves the run and streams it to to, an IO-like stream. Returns the run’s record, which carries the status the run ended with.
The reservation happens before any provider work: a request whose input digest matches an identity already reserved attaches instead of executing, and a changed input under the same key is refused by the store. A reserved run that already ended is served as a reconnect — its outcome and state snapshot — never as a second execution.