agents-go
Reference

Transport

AudioInput/Output, TextOutput, and the transport seam.

The transport package defines the I/O seam an AgentSession binds to. A transport implements these interfaces; the session drives them without knowing which concrete transport it's talking to.

Binding

Transports are bound via SessionInput / SessionOutput on the session (or on StartOptions):

type SessionInput struct {
    Audio transport.AudioInput
    Video transport.VideoInput
}
type SessionOutput struct {
    Audio transport.AudioOutput
    Text  transport.TextOutput
}

Audio and text I/O are wired by every transport; video input is currently carried only by the WebRTC (roomio) transport — the console and WebSocket transports are audio-only.

AudioInput

type AudioInput interface {
    Stream(ctx context.Context) <-chan stream.Result[*audio.AudioFrame]
    Close() error
    OnAttached()
    OnDetached()
}

Stream yields audio frames until the input is closed or ctx is cancelled. OnAttached/OnDetached fire as the input is bound/unbound.

AudioOutput

type AudioOutput interface {
    CaptureFrame(ctx context.Context, frame *audio.AudioFrame, opts ...PlaybackOption) error
    Flush(opts ...PlaybackOption)
    ClearBuffer(opts ...PlaybackOption)
    WaitForPlayout(ctx context.Context, opts ...PlaybackOption) (PlaybackFinishedEvent, error)
    CanPause() bool
    Pause()
    Resume()
    // OnAttached / OnDetached / OnPlaybackStarted / OnPlaybackFinished
}
  • CaptureFrame pushes audio for playback (frames may arrive faster than real-time); Flush closes a segment; ClearBuffer stops immediately and discards — the interruption path.
  • WaitForPlayout blocks until captured segments finish — this is what RunContext.WaitForPlayout and SpeechHandle.WaitForPlayout sit on.
  • CanPause / Pause / Resume back false-interruption resume: it only works when the output chain reports CanPause.

TextOutput

type TextOutput interface {
    CaptureText(ctx context.Context, text TextPayload) error
    Flush()
    OnAttached()
    OnDetached()
}

Receives assistant transcription (plain or word-aligned) for surfaces that show text alongside audio.

Binding: connecting a transport in Start

A Binding lets a transport connect and hand its I/O to AgentSession.Start, rather than the caller wiring SessionInput/SessionOutput by hand:

type Binding interface {
    Connect(ctx context.Context) (SessionInput, SessionOutput, error)
}
// Optional, for transports that run post-start work (state mirroring, disconnects):
type StartedBinding interface {
    Binding
    Started(s *AgentSession)
}

Start calls Connect first; explicit StartOptions.Input/Output override the binding per field; a binding implementing io.Closer is closed if Start fails after connecting. roomio.Bind(connectOpts, opts) is the built-in binding.

Concrete transports

TransportPackageEntry point
Consoletransport/consoleconsole.Run (PCM stdin/stdout).
WebSockettransport/websocketwebsocket.Handler / NewSessionHandoff (telephony seam).
RoomIO (WebRTC)plugins/livekit/roomioroomio.Bind or NewRoomIO().Start; -tags livekit.

Console and WebSocket keep their own Run/Handler entrypoints; roomio also offers the Binding form. See the guide: Transports.

On this page