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 ModelSpec

From Leeroopedia
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

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)

Related Pages

Implements Principle

Page Connections

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