class LittleGhost::Run

Observe one top-level assembly execution from start to finish. A run records its response, outcome, usage, error, and owned resources.

run = CustomerSupportAgent.ask("Why is transfer 481 pending?")

run.completed? # => true
run.outcome    # => "completed"
run.response   # => "Transfer 481 is waiting for the receiving bank."

ask returns the Run after work finishes. stream_ask yields StreamEvent objects as work happens, then returns the same finished Run. A Run executes only once.

stream = CustomerSupportAgent.stream_ask("Where is transfer 481?")
run = stream.each do |event|
  next unless event.type == :agent_stream

  source = event.data.fetch(:source)
  next unless source.agent_path == "/root" && source.assembly_path.empty?

  progress = event.data.fetch(:event)
  publish(progress) if progress.type == :text_delta
end

run.completed? # => true
run.response

Outcomes

Completion, failure, deadline, and cancellation become the completed, failed, partial, and cancelled outcomes. Ordinary execution failures are available through error and the terminal stream event. Failures while closing resources, delivering events, or reporting instrumentation may still raise because LittleGhost cannot report a reliable ending.

Tool validation and ToolError failures return safe Tool results to the model, which may recover and complete the Run. Input, configuration, or resource construction can raise before a Run exists. Once execution begins, terminal events are run_stop, run_error, run_partial, and run_cancel.

Owned resources

The Run opens its workspace, sandbox, Session, and Assembly entrypoint, then closes registered resources in reverse order. register adds application resources to that cleanup sequence. Interjection is available only while one Agent entrypoint is active.

Source-tagged progress

Every Run observes all participating Agents, including a root Agent’s subagents and Agents nested in Workflow, Swarm, or Graph steps. Each :agent_stream event carries an AgentStreamSource in data[:source] and a copied, frozen Agent StreamEvent in data[:event]. An inner :invocation_start also includes the copied, frozen Message sent to that Agent in data[:input]. Event consumers cannot change the running work.

Agent progress appears only through these wrappers, not as duplicate raw events. Lifecycle events and terminal RunResults are separate. Selecting a child result or computing an assembly answer does not replay text deltas.

Parallel Agents may interleave, but the Run invokes the stream consumer serially. Wrappers can contain inputs, reasoning, Tool arguments and results, and private participant output. Applications must filter sources and fields before sending them to destinations that may see less than the complete Run. Set include_agent_events: false to omit all Agent progress; execution, lifecycle events, and final results remain unchanged.