class LittleGhost::AGUI::Adapter

Adapter turns a LittleGhost stream into AG-UI event hashes. It lets a Ruby agent drive compatible chat interfaces without changing the agent itself.

events = CustomerSupportAgent.stream_ask("Where is my order?")
adapter = LittleGhost::AGUI::Adapter.new
adapter.stream(events, thread_id: "thread-1", run_id: "run-1").each do |event|
  websocket.write(JSON.generate(event))
end

The adapter has no state between stream calls, so one instance can translate independent runs.

Progress comes from the Run’s native :agent_stream events. By default, only the top-level Agent’s progress reaches the interface: its AgentStreamSource has agent_path /root and an empty assembly_path. A composite run’s final response arrives in RUN_FINISHED independently of participant progress. Unwrapped progress and wrapped invocation usage or terminal events are ignored; run lifecycle and aggregate usage remain separate.

Choose what the interface receives

Pass a source_filter callable to select a participant whose progress is intended for the destination. The callable receives an AgentStreamSource and replaces the default root selection. Choose it in trusted application code, not from request or model values.

adapter = LittleGhost::AGUI::Adapter.new(source_filter: lambda { |source|
  step = source.assembly_path.first
  source.agent_path == "/root" && source.assembly_path.length == 1 &&
    step.assembly_id == "response_workflow" && step.participant == "response"
})

Provider plaintext reasoning becomes AG-UI reasoning events. Tool arguments and results, invocation metadata, subagent events, trace context, and selected error text also pass through without redaction. Authorize and filter the complete stream before transport, and send it only to an interface intended to display that data. Encrypted reasoning and provider continuity artifacts are never exposed here.