MingaAgent.Providers.Native.ReqLLMAdapter (Minga v0.1.0)

Copy Markdown View Source

ReqLLM-specific adapter helpers for the native provider.

MingaAgent.Providers.Native owns orchestration policy: turn flow, retry, cost, compaction, approvals, tool coordination, context updates, and event normalization. This module owns the ReqLLM-shaped details needed to make one provider request and decode one provider response.

Summary

Types

Streaming LLM client compatible with ReqLLM.stream_text/3.

Raw ReqLLM usage payload before Native normalizes it into TurnUsage.

Callbacks used while streaming a provider response.

Neutralized tool-call payload emitted by ReqLLM streaming.

Decoded result from one provider response.

Functions

Returns true when the exact route's source model provider is Anthropic.

Creates a ReqLLM tool-call value for assistant messages.

Returns the default ReqLLM streaming client.

Processes a ReqLLM stream response into a neutral turn result.

Runs one ReqLLM streaming request attempt. Retry ownership stays in Native.

Builds request-local options from one immutable resolved selection.

Builds the summary callback expected by the compaction subsystem.

Builds the provider-specific tool value for a canonical tool declaration.

Validates an already-resolved model selection before ReqLLM sees it.

Types

llm_client()

@type llm_client() :: (LLMDB.Model.t(), [ReqLLM.Message.t()], keyword() ->
                   {:ok, ReqLLM.StreamResponse.t()} | {:error, term()})

Streaming LLM client compatible with ReqLLM.stream_text/3.

raw_usage()

@type raw_usage() :: %{
  optional(:input_tokens) => non_neg_integer(),
  optional(:output_tokens) => non_neg_integer(),
  optional(:input) => non_neg_integer(),
  optional(:output) => non_neg_integer(),
  optional(:cache_read_input_tokens) => non_neg_integer(),
  optional(:cache_creation_input_tokens) => non_neg_integer(),
  optional(:cached_input) => non_neg_integer(),
  optional(:cached_tokens) => non_neg_integer(),
  optional(:cache_creation) => non_neg_integer(),
  optional(:cache_creation_tokens) => non_neg_integer(),
  optional(:cache_read) => non_neg_integer(),
  optional(:cache_write) => non_neg_integer(),
  optional(:total_cost) => number(),
  optional(:cost) => number()
}

Raw ReqLLM usage payload before Native normalizes it into TurnUsage.

stream_callbacks()

@type stream_callbacks() :: [
  on_text: (String.t() -> term()),
  on_thinking: (String.t() -> term()),
  on_tool_call: (tool_call() -> term())
]

Callbacks used while streaming a provider response.

tool_call()

Neutralized tool-call payload emitted by ReqLLM streaming.

turn_result()

Decoded result from one provider response.

Functions

anthropic_model?(model_selection)

@spec anthropic_model?(MingaAgent.ModelSelection.t()) :: boolean()

Returns true when the exact route's source model provider is Anthropic.

assistant_tool_call(id, name, arguments)

@spec assistant_tool_call(String.t(), String.t(), map()) :: ReqLLM.ToolCall.t()

Creates a ReqLLM tool-call value for assistant messages.

default_client()

@spec default_client() :: llm_client()

Returns the default ReqLLM streaming client.

process_stream(stream_response, callbacks \\ [])

@spec process_stream(ReqLLM.StreamResponse.t(), stream_callbacks()) ::
  {:ok, turn_result()} | {:error, term(), String.t()}

Processes a ReqLLM stream response into a neutral turn result.

stream(llm_client, model, messages, opts)

@spec stream(llm_client(), LLMDB.Model.t(), [ReqLLM.Message.t()], keyword()) ::
  {:ok, ReqLLM.StreamResponse.t()} | {:error, term()}

Runs one ReqLLM streaming request attempt. Retry ownership stays in Native.

stream_opts(selection, tools, config, credential_opts \\ [])

@spec stream_opts(
  MingaAgent.ModelSelection.t(),
  [ReqLLM.Tool.t()],
  MingaAgent.Config.t(),
  keyword()
) ::
  {:ok, keyword()} | {:error, {:credential_unavailable, String.t()}}

Builds request-local options from one immutable resolved selection.

summary_client(llm_client, selection, config, credential_opts \\ [])

Builds the summary callback expected by the compaction subsystem.

tool(spec, callback, provider_options \\ %{})

Builds the provider-specific tool value for a canonical tool declaration.

validate_selection(model_selection)

@spec validate_selection(MingaAgent.ModelSelection.t()) ::
  :ok | {:error, String.t(), :invalid_selection}

Validates an already-resolved model selection before ReqLLM sees it.