Agentix.Provider behaviour (Agentix v0.1.0)

Copy Markdown View Source

Behaviour for streaming an LLM completion, plus the normalized stream handle the agent consumes.

Two implementations: a ReqLLM-backed adapter (the default, added with the agent loop) and the scriptable Agentix.Test.MockProvider for deterministic, key-free tests. The handle is defined from the ReqLLM StreamResponse shape so the real adapter is a thin wrapper: a lazy stream of chunks, a cancel closure, and a finalizer for the assembled message + usage (available only after the stream is fully consumed).

Configure with config :agentix, :provider, MyProvider.

Summary

Callbacks

Starts a streaming completion for model over context. Returns {:ok, %Stream{}} or {:error, reason}. The caller consumes chunks fully, may call cancel.() to abort, and calls finalize.() after consumption.

Functions

The configured provider implementation.

Streams a completion via the configured provider.

Callbacks

stream(model, context, opts)

@callback stream(model :: term(), context :: ReqLLM.Context.t(), opts :: keyword()) ::
  {:ok, Agentix.Provider.Stream.t()} | {:error, term()}

Starts a streaming completion for model over context. Returns {:ok, %Stream{}} or {:error, reason}. The caller consumes chunks fully, may call cancel.() to abort, and calls finalize.() after consumption.

Functions

impl()

@spec impl() :: module()

The configured provider implementation.

stream(model, context, opts \\ [])

@spec stream(term(), ReqLLM.Context.t(), keyword()) ::
  {:ok, Agentix.Provider.Stream.t()} | {:error, term()}

Streams a completion via the configured provider.