ractogateway.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.

provider: str = 'base'
abstractmethod translate_tools(registry)[source]

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

Return type:

list[dict[str, Any]]

abstractmethod run(prompt, user_message, *, history=None, 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 async arun(prompt, user_message, *, history=None, tools=None, temperature=0.0, max_tokens=4096, **kwargs)[source]

Async variant of run().

Return type:

LLMResponse

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

Bases: str, Enum

Why the model stopped generating.

STOP = 'stop'
TOOL_CALL = 'tool_call'
LENGTH = 'length'
CONTENT_FILTER = 'content_filter'
ERROR = 'error'
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.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

content: str | None
thinking: str | None
parsed: dict[str, Any] | list[Any] | None
tool_calls: list[ToolCallResult]
finish_reason: FinishReason
usage: dict[str, int]
raw: Any
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

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

class ractogateway.adapters.ToolCallResult(**data)[source]

Bases: BaseModel

A single tool/function call returned by the model.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

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

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