Implementation:AISecurityLab Hackagent Model Protocols
| Knowledge Sources | |
|---|---|
| Domains | Contracts, Model_Adapter |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete runtime-checkable protocols defining the callable model interfaces (LLM, LLMFactory, CompletionResult, CompletionModel) that all model backends must implement, provided by the HackAgent core contracts package.
Description
LLM is the primary protocol: complete() / acomplete() return a Completion, with_params() returns a pre-configured copy, and describe() returns a ModelSpec. Calls never raise for provider errors — errors are returned as values in the Completion. LLMFactory builds an LLM for a role model spec. CompletionResult is a minimal structural protocol (text, ok, error). CompletionModel is the minimal capability used by domain-independent evaluation.
Usage
- Model backends: Every model adapter implements LLM.
- Dependency injection: Attacks receive Completion (a callable matching CompletionModel) as role parameters.
Code Reference
Source Location
- Repository: AISecurityLab_Hackagent
- File: hackagent/core/contracts/protocols.py
Signature
@runtime_checkable
class LLM(Protocol):
def complete(self, messages, **params) -> Completion: ...
async def acomplete(self, messages, **params) -> Completion: ...
def with_params(self, **params) -> "LLM": ...
def describe(self) -> ModelSpec: ...
@runtime_checkable
class LLMFactory(Protocol):
def for_role(self, spec: ModelSpec) -> LLM: ...
class CompletionResult(Protocol):
@property
def text(self) -> Optional[str]: ...
@property
def ok(self) -> bool: ...
@property
def error(self) -> Optional[LLMError]: ...
class CompletionModel(Protocol):
def complete(self, messages, **params) -> CompletionResult: ...
Import
from hackagent.core.contracts.protocols import LLM, LLMFactory, CompletionResult, CompletionModel
Usage Examples
Check Protocol Compliance
from hackagent.core.contracts.protocols import LLM
from hackagent.models.model import Model
model = Model(...)
is_llm = isinstance(model, LLM) # runtime check