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 ModelFactory

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

Overview

Concrete LLM factory implementing the LLMFactory protocol, building role-model LLMs from ModelSpec objects with credentials from Settings, provided by the HackAgent models package.

Description

'ModelFactory implements for_role(spec) from the LLMFactory protocol. A role model uses the API key its spec names. The only credential the factory adds is the HackAgent API key, and only for specs whose endpoint is the hosted LLM gateway — it is never sent to other providers. spec_from_config() reads the legacy role-model dicts (identifier, endpoint, agent_type, api_key as literal or env var name) and builds a ModelSpec.

Usage

  • Campaign resolution: resolve_campaign uses the factory to build role models (attacker, judge, embedder) from specs.

Code Reference

Source Location

Signature

class ModelFactory:
    def for_role(self, spec: ModelSpec) -> LLM: ...

def spec_from_config(config: Dict[str, Any]) -> ModelSpec: ...

Import

from hackagent.models.factory import ModelFactory, spec_from_config

Usage Examples

Build a Role Model

from hackagent.models.factory import ModelFactory

factory = ModelFactory(settings)
attacker = factory.for_role(attacker_spec)
result = await attacker.acomplete([{"role": "user", "content": "..."}])

Related Pages

Implements Principle

Page Connections

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