Adapters

ractogateway.adapters — LLM Provider Adapters.

Implements the Adapter Design Pattern to normalize API differences across LLM providers. Each adapter translates tool schemas, handles request formatting, and standardizes response parsing.

class ractogateway.adapters.BaseLLMAdapter(model, *, api_key=None, **kwargs)[source]

Bases: ABC

Abstract base class that every provider adapter must implement.

Parameters:
  • model (str) – The model identifier (e.g. "gpt-4o", "gemini-2.0-flash").

  • api_key (str | None) – Provider API key. When None, each concrete adapter should fall back to an environment variable.

abstractmethod async arun(prompt, user_message, *, tools=None, temperature=0.0, max_tokens=4096, **kwargs)[source]

Async variant of run().

Return type:

LLMResponse

provider: str = 'base'
abstractmethod run(prompt, user_message, *, tools=None, temperature=0.0, max_tokens=4096, **kwargs)[source]

Execute a prompt against the provider and return a normalised response.

Return type:

LLMResponse

abstractmethod translate_tools(registry)[source]

Convert canonical ToolSchema objects into the provider’s native tool/function-calling format.

Return type:

list[dict[str, Any]]

class ractogateway.adapters.FinishReason(*values)[source]

Bases: str, Enum

Why the model stopped generating.

CONTENT_FILTER = 'content_filter'
ERROR = 'error'
LENGTH = 'length'
STOP = 'stop'
TOOL_CALL = 'tool_call'
class ractogateway.adapters.LLMResponse(**data)[source]

Bases: BaseModel

Unified, provider-agnostic response envelope.

Every adapter’s run() method returns one of these, regardless of whether the underlying provider is OpenAI, Gemini, or Anthropic.

content: str | None
finish_reason: FinishReason
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

parsed: dict[str, Any] | list[Any] | None
raw: Any
tool_calls: list[ToolCallResult]
usage: dict[str, int]
class ractogateway.adapters.ToolCallResult(**data)[source]

Bases: BaseModel

A single tool/function call returned by the model.

arguments: dict[str, Any]
id: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str