Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AISecurityLab Hackagent Model Adapter Interface

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Model_Adapter
Last Updated 2026-10-29 00:00 GMT

Overview

An abstract interface pattern that normalizes chat completions across heterogeneous model backends (LiteLLM, Ollama, ADK, Claude, etc.) into a single uniform response type.

Description

A red-team toolkit must talk to many model providers — cloud APIs, local servers, agent frameworks. Each has its own SDK, request format, error model, and response shape. The Model abstract base class normalizes all of this behind two core methods:

  • complete: Synchronous completion.
  • acomplete: Async completion (the primary interface used throughout the pipeline).

Both accept a sequence of chat messages plus keyword overrides (tools, tool_choice, sampling) and return a ModelResponse — a uniform type with text, error, guardrail, latency_ms, metadata.

A critical design choice: a provider error or guardrail block comes back as a response that is not ok, never as an exception. This lets the runner record every attempt uniformly, whether it succeeded, failed, or was blocked — the error is data, not control flow. Transport failures (network down) are the exception, and the runner catches them and converts them to attempt errors.

The class also provides is_reachable() — a lightweight ping used by preflight — and batch helpers for concurrent completion.

Usage

Use this principle when a framework must support multiple model backends with different SDKs and error models. The adapter interface should normalize responses so the rest of the pipeline never needs to know which backend it is talking to.

Theoretical Basis

# Abstract algorithm (NOT real implementation)
class Model(ABC):
    @abstractmethod
    async def acomplete(self, messages, **overrides) -> ModelResponse:
        """Provider errors come back as response.error, not exceptions."""

# The runner does not know which backend it is talking to:
response = await target.acomplete(messages)
if response.error is not None:
    # Provider error — recorded as attempt error
    ...
elif response.guardrail is not None:
    # Guardrail block — recorded as defense stop
    ...
else:
    # Success — judge the reply
    ...

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment