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

Implementation:AISecurityLab Hackagent Model acomplete

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

Overview

Concrete tool for the abstract model completion interface that every backend (LiteLLM, Ollama, ADK, etc.) implements, provided by the HackAgent models framework.

Description

Model is the abstract base class implemented by every model backend in HackAgent. It defines the common interface for sending chat messages to a model and receiving a normalized ModelResponse. The two core methods are:

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

Both accept a sequence of chat messages plus keyword overrides that the model layer understands (tools, tool_choice, sampling parameters). The result is a ModelResponse with text, error, guardrail, latency_ms, metadata — a provider error or guardrail block comes back as a response that is not ok, never as an exception.

The class also provides is_reachable() — sends a minimal PING request and reports whether a usable reply came back — used by preflight. Batch helpers (complete_batch, acomplete_batch) provide concurrent completion of multiple requests.

This is a Pattern Doc: it documents the interface that all concrete model adapters implement.

Usage

  • Implementing a model backend: Subclass Model, implement complete and acomplete, and optionally override is_reachable.
  • Sending to a target: The runner calls target.acomplete(messages) through _AttackRunner._complete, which adds latency measurement and concurrency limiting.

Code Reference

Source Location

Signature

class Model(ABC):
    """Common interface implemented by every model backend."""

    async def is_reachable(self) -> Reachability: ...

    @abstractmethod
    def complete(self, messages: Sequence[Mapping[str, Any]], **overrides: Any) -> ModelResponse: ...

    @abstractmethod
    async def acomplete(self, messages: Sequence[Mapping[str, Any]], **overrides: Any) -> ModelResponse: ...

    async def acomplete_batch(self, requests, *, max_concurrency=1, on_complete=None, **overrides) -> list[ModelResponse]: ...

@dataclass(frozen=True)
class Reachability:
    ok: bool
    detail: str = ""
    latency_s: Optional[float] = None

Import

from hackagent.models.model import Model, Reachability

I/O Contract

Inputs

Name Type Required Description
messages Sequence[Mapping[str, Any]] Yes Chat messages (role + content)
overrides Any No Model-layer kwargs: tools, tool_choice, sampling

Outputs

Name Type Description
acomplete return ModelResponse text, error, guardrail, latency_ms, metadata
is_reachable return Reachability ok, detail, latency_s

Usage Examples

Calling a Target Model

from hackagent.models import build_model

# Build a model from a config (e.g., LiteLLM, Ollama)
model = build_model(config)

# Send a chat request
response = await model.acomplete([
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Tell me about AI safety."},
])

if response.error is not None:
    print(f"Error: {response.error.message}")
else:
    print(f"Reply: {response.text}")
    print(f"Latency: {response.latency_ms}ms")

Checking Reachability

reachability = await model.is_reachable()
if reachability:
    print(f"Model reachable ({reachability.latency_s:.2f}s)")
else:
    print(f"Unreachable: {reachability.detail}")

Related Pages

Implements Principle

Page Connections

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