Gateway

ractogateway.gateway — Unified Gateway Runner.

Orchestrates prompt compilation, adapter selection, tool injection, and response standardization into a single high-level interface.

class ractogateway.gateway.Gateway(adapter, *, tools=None, default_prompt=None)[source]

Bases: object

Unified entry point that wraps any BaseLLMAdapter.

Parameters:
  • adapter (BaseLLMAdapter) – A concrete adapter instance (OpenAILLMKit, GoogleLLMKit, AnthropicLLMKit).

  • tools (ToolRegistry | None) – An optional ToolRegistry containing registered tools that the LLM is allowed to call.

  • default_prompt (RactoPrompt | None) – An optional RactoPrompt to use when run() is called without an explicit prompt.

  • Usage::

    from ractogateway import RactoPrompt, Gateway from ractogateway.adapters import OpenAILLMKit

    adapter = OpenAILLMKit(model=”gpt-4o”, api_key=”sk-…”) prompt = RactoPrompt(…) gw = Gateway(adapter=adapter)

    response = gw.run(prompt, “Analyse this code for bugs.”) print(response.parsed) # auto-parsed JSON dict

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

Async variant of run().

Return type:

LLMResponse

run(prompt=None, user_message='', *, tools=None, temperature=0.0, max_tokens=4096, response_model=None, **kwargs)[source]

Execute a request and return a standardised LLMResponse.

Parameters:
  • prompt (RactoPrompt | None) – The RACTO prompt. Falls back to default_prompt.

  • user_message (str) – The end-user’s query.

  • tools (ToolRegistry | None) – Override the gateway-level tool registry for this call.

  • temperature (float) – Sampling temperature.

  • max_tokens (int) – Maximum tokens in the response.

  • response_model (type[BaseModel] | None) – Optional Pydantic model to validate parsed output against. If provided and the LLM returns valid JSON, it is validated through this model and attached to response.parsed.

  • **kwargs (Any) – Passed through to the adapter.

Return type:

LLMResponse