Implementation:AISecurityLab Hackagent ModelFactory
| 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
- Repository: AISecurityLab_Hackagent
- File: hackagent/models/factory.py
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": "..."}])