CommBus.Protocol.Pipeline (CommBus v0.1.0)

Copy Markdown View Source

ALF pipeline that assembles a conversation and adapts it into a protocol packet.

Summary

Functions

Pipeline stage that runs prompt assembly on the context's conversation and entries, attaching the assembly result to the context.

Pipeline stage that invokes the protocol adapter to convert the assembled context into a protocol packet.

Pipeline stage that extracts the final result from the pipeline state, returning either the assembled packet or an error.

Executes the ALF assembly pipeline: validates the context, assembles the prompt, builds a protocol packet, validates it, and returns the result.

Pipeline stage that validates the context has a valid conversation and entry list. Returns the state unchanged if valid, or sets an error result if invalid.

Pipeline stage that validates the assembled packet's structure, checking message format, sections, and token usage.

Functions

alf_components()

assemble_prompt(state, opts)

@spec assemble_prompt(
  CommBus.Protocol.Pipeline.State.t(),
  keyword()
) :: CommBus.Protocol.Pipeline.State.t()

Pipeline stage that runs prompt assembly on the context's conversation and entries, attaching the assembly result to the context.

build_packet(state, opts)

@spec build_packet(
  CommBus.Protocol.Pipeline.State.t(),
  keyword()
) :: CommBus.Protocol.Pipeline.State.t()

Pipeline stage that invokes the protocol adapter to convert the assembled context into a protocol packet.

call(event, opts \\ [debug: false])

@spec call(any(), Keyword.t()) :: any() | [any()] | nil
@spec call(any(), Keyword.t()) :: reference()

cast(event, opts \\ [debug: false, send_result: false])

components()

@spec components() :: [map()]

finalize_result(state, opts)

@spec finalize_result(
  CommBus.Protocol.Pipeline.State.t(),
  keyword()
) :: {:ok, CommBus.Protocol.Packet.t()} | {:error, term()}

Pipeline stage that extracts the final result from the pipeline state, returning either the assembled packet or an error.

flow(flow, names, opts \\ [debug: false])

@spec flow(map(), list(), Keyword.t()) :: Enumerable.t()

run(input, opts \\ [])

@spec run(
  CommBus.Protocol.Context.t() | tuple(),
  keyword()
) :: {:ok, CommBus.Protocol.Packet.t()} | {:error, term()}

Executes the ALF assembly pipeline: validates the context, assembles the prompt, builds a protocol packet, validates it, and returns the result.

Parameters

  • input — A %CommBus.Protocol.Context{} struct, or a tuple of {conversation, entries} or {conversation, entries, opts}.
  • opts — Keyword options: :adapter (protocol adapter module, defaults to CommBus.Protocol.LlmCoreAdapter).

Returns

{:ok, %CommBus.Protocol.Packet{}} on success or {:error, reason} on failure.

start()

@spec start() :: :ok

start(opts)

@spec start(list()) :: :ok

started?()

@spec started?() :: true | false

stop()

@spec stop() :: :ok | {:exit, {atom(), any()}}

stream(stream, opts \\ [debug: false])

@spec stream(Enumerable.t(), Keyword.t()) :: Enumerable.t()

validate_context(state, opts)

@spec validate_context(
  CommBus.Protocol.Pipeline.State.t(),
  keyword()
) :: CommBus.Protocol.Pipeline.State.t()

Pipeline stage that validates the context has a valid conversation and entry list. Returns the state unchanged if valid, or sets an error result if invalid.

validate_packet(state, opts)

@spec validate_packet(
  CommBus.Protocol.Pipeline.State.t(),
  keyword()
) :: CommBus.Protocol.Pipeline.State.t()

Pipeline stage that validates the assembled packet's structure, checking message format, sections, and token usage.