module RubyLLM::AgUI::Protocol

The few AG-UI 1.0 wire shapes the community Ruby SDK does not yet model.

The protocol SDK owns event models and wire encoding, and this gem reuses them for everything else. Two 1.0 shapes are missing from ‘ag-ui-protocol` 0.2.0:

  1. ‘RunFinishedCancelledOutcome` — 0.2.0 has success and interrupt outcomes only. A cancellation reported as success is exactly the bug this gem exists to prevent, so the gem emits a schema-valid cancelled outcome and offers the model upstream.

  2. ‘RUN_STARTED.protocolVersion` — 1.0 lets a producer declare the version it speaks so a consumer can see a downgrade. 0.2.0’s RunStartedEvent has no such field.

Both classes subclass the SDK’s own models, so the SDK encoder serializes them unchanged. They define no top-level ‘AgUi` constant.

Constants

PROTOCOL_VERSION

The AG-UI protocol version this producer speaks.

SCHEMA_COMMIT

The pinned upstream commit of docs/spec/1.0/schema.json.

Public Instance Methods

cancelled_outcome() click to toggle source

The 1.0 cancelled outcome 0.2.0 cannot express.

# File lib/ruby_llm/ag_ui/protocol.rb, line 113
def cancelled_outcome
  CancelledOutcome.new
end
interrupt_outcome(interrupts) click to toggle source

The outcome of a run that paused, carrying the interrupts that still wait for an answer. The schema requires at least one, so a run whose interrupts were all answered is not closed with this outcome.

# File lib/ruby_llm/ag_ui/protocol.rb, line 120
def interrupt_outcome(interrupts)
  ::AgUiProtocol::Core::Events::RunFinishedInterruptOutcome.new(interrupts: interrupts.map(&:to_protocol))
end
run_finished(thread_id:, run_id:, outcome:) click to toggle source

A RUN_FINISHED carrying outcome.

# File lib/ruby_llm/ag_ui/protocol.rb, line 103
def run_finished(thread_id:, run_id:, outcome:)
  RunFinishedEvent.new(thread_id: thread_id, run_id: run_id, outcome: outcome)
end
run_started(thread_id:, run_id:, parent_run_id: nil, input: nil) click to toggle source

The RUN_STARTED this producer emits: the SDK’s shape plus the protocol version only 1.0 carries.

# File lib/ruby_llm/ag_ui/protocol.rb, line 98
def run_started(thread_id:, run_id:, parent_run_id: nil, input: nil)
  RunStartedEvent.new(thread_id: thread_id, run_id: run_id, parent_run_id: parent_run_id, input: input)
end
state_snapshot(state) click to toggle source

The complete state a reconnect serves instead of replaying deltas.

# File lib/ruby_llm/ag_ui/protocol.rb, line 125
def state_snapshot(state)
  ::AgUiProtocol::Core::Events::StateSnapshotEvent.new(snapshot: state)
end
success_outcome() click to toggle source

The outcome of a run that ended without a human in the loop.

# File lib/ruby_llm/ag_ui/protocol.rb, line 108
def success_outcome
  ::AgUiProtocol::Core::Events::RunFinishedSuccessOutcome.new
end