Implementation:AISecurityLab Hackagent ModelSpec
| Knowledge Sources | |
|---|---|
| Domains | Contracts, Model_Adapter |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete frozen pydantic model describing how to reach one model — the target or any role model — with identifier, endpoint, agent type, API key, sampling, and capabilities, provided by the HackAgent core contracts package.
Description
ModelSpec is a frozen pydantic model with fields: identifier (model name), endpoint (base URL), agent_type (AgentType enum), api_key / api_key_env, sampling params (max_tokens, temperature, top_p, timeout, thinking), capabilities (frozenset of strings), and extra (passthrough dict). JudgeSpec extends it with type (judge format, default "harmbench"), range (binary/decimal), and system_prompt.
Usage
- Role resolution: resolve_campaign builds ModelSpecs from campaign model configs.
- Model factory: LLMFactory.for_role(spec) creates an LLM from a ModelSpec.
Code Reference
Source Location
- Repository: AISecurityLab_Hackagent
- File: hackagent/core/contracts/specs.py
Signature
class ModelSpec(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
identifier: str
endpoint: Optional[str] = None
agent_type: AgentType = AgentType.OPENAI
api_key: Optional[str] = None
api_key_env: Optional[str] = None
max_tokens: Optional[int] = None
temperature: Optional[float] = None
top_p: Optional[float] = None
timeout: Optional[float] = None
thinking: Optional[bool] = None
capabilities: frozenset[str] = frozenset
extra: Dict[str, Any] = {}
class JudgeSpec(ModelSpec):
type: str = "harmbench"
range: Optional[Literal["binary", "decimal"]] = None
system_prompt: Optional[str] = None
Import
from hackagent.core.contracts.specs import ModelSpec, JudgeSpec
Usage Examples
Build a ModelSpec
from hackagent.core.contracts.specs import ModelSpec
from hackagent.core.contracts.enums import AgentType
spec = ModelSpec(
identifier="gpt-4o",
agent_type=AgentType.LITELLM,
api_key_env="OPENAI_API_KEY",
temperature=0.0,
)
llm = factory.for_role(spec)