Skip to main content

BaseClient

BaseClient is the abstract transport contract for prompt-driven modules in AutoPipeline. It is implemented in src/autopipeline/components/primitives/clients/base_client.py.

All concrete entries in CLIENT_REGISTRY inherit from this class.

Base
Overview

Role in the Stack

The client layer is intentionally narrow:

  • clients handle transport
  • prompt adapters format payloads
  • modules interpret responses

BaseClient exists to keep that separation explicit.

Signature

Class Signature

class BaseClient(ABC):
def __init__(self, model_name: str, **kwargs)
Constructor

Constructor Parameters

ParameterRequiredMeaning
model_nameYesModel identifier passed to the backend transport layer.
**kwargsNoBackend-specific config captured into self.config.

Stored attributes

The constructor stores:

  • self.model_name
  • self.config
Methods

Public Methods

MethodPurpose
call_model(messages)Abstract transport call implemented by subclasses.
parse_response_to_json(response)Shared JSON extraction and repair helper.
Methods

Method Reference

call_model(messages)

call_model(messages) -> str

This method is abstract. Concrete subclasses define:

  • accepted messages payload shape
  • network or SDK call behavior
  • retry logic
  • returned raw text format

parse_response_to_json(response)

parse_response_to_json(response: str) -> Any

Input

ParameterMeaning
responseRaw text returned by the model backend.

Output

Returns:

  • a parsed Python object on success
  • None if extraction and repair both fail

Internal behavior

The method:

  1. tries to extract a JSON block from the response
  2. repairs malformed JSON with json_repair
  3. falls back to repairing the full response when no explicit block is found
Config

Minimal Integration Example

BaseClient is not instantiated directly, but all concrete client configs eventually map into its constructor shape:

client_cfg:
backend: api
model_name: gpt-4o
base_url: https://...
api_key: ${client_config.api_key}
Failure Mode

Failure Semantics

BaseClient itself does not perform transport retries, but parse_response_to_json(...) is soft-fail by design:

  • malformed or missing JSON -> returns None
  • parse errors are logged rather than raised

This behavior is important because the judge and parser modules often prefer retrying over crashing.

Extension

Extension Notes

  • Subclass BaseClient when transport or authentication changes.
  • Do not move prompt serialization into this layer.
  • Keep output normalization above the client layer so transport code stays backend-specific and simple.