Overview
Concrete declarative description of a model — its name, how to reach it (connection), and how to sample from it (generation) — used everywhere a campaign names a model: the target, attack roles, judges, guardrails, and goal classifier.
Description
ModelConfig is a frozen pydantic model combining a ConnectionSpec (provider, type, endpoint, api_key_env, headers, timeout) and a GenerationSpec (max_tokens, temperature, top_p, etc.) plus an options mapping for agent-specific settings. The same shape describes every model in a campaign. ModelConnection resolves the connection into LiteLLM arguments (resolving api_key from environment), and ModelGeneration resolves the generation spec into non-null kwargs for a completion call, validating that protected LiteLLM fields are not passed through extra_kwargs.
Usage
- Campaign target: The target field of a CampaignSpec is a ModelConfig.
- Judge / guardrail models: Judge and guardrail specs also use ModelConfig.
- Resolved transport: ModelConnection.to_litellm() and ModelGeneration.to_kwargs() produce the actual call arguments.
Code Reference
Source Location
Signature
class ConnectionSpec(BaseModel):
model_config = ConfigDict(extra="forbid", frozen=True)
provider: str
type: AgentType
endpoint: Optional[str] = None
api_key_env: Optional[str] = None
headers: Mapping[str, str] = {}
timeout: PositiveFloat = 120.0
class GenerationSpec(BaseModel):
model_config = ConfigDict(extra="forbid", frozen=True)
max_tokens: Optional[int] = None
temperature: Optional[float] = None
top_p: Optional[float] = None
frequency_penalty: Optional[float] = None
presence_penalty: Optional[float] = None
seed: Optional[int] = None
stop: Optional[str | tuple[str, ...]] = None
reasoning_effort: Optional[str] = None
response_format: Optional[Dict[str, Any]] = None
extra_body: Dict[str, Any] = {}
thinking: Optional[bool] = None
class ModelConfig(BaseModel):
model_config = ConfigDict(extra="forbid", frozen=True)
name: str
connection: ConnectionSpec
generation: GenerationSpec = GenerationSpec()
options: Mapping[str, Any] = {}
class ModelGeneration(GenerationSpec):
thinking: Optional[Any] = None
extra_kwargs: Mapping[str, Any] = {}
def to_kwargs(self) -> Dict[str, Any]: ...
class ModelConnection(BaseModel):
model_config = ConfigDict(extra="forbid", frozen=True)
api_base: Optional[str] = None
api_key: Optional[SecretStr] = None
api_key_env: Optional[str] = None
timeout: Optional[PositiveFloat] = 120.0
extra_headers: Mapping[str, str] = {}
def to_litellm(self) -> Dict[str, Any]: ...
Import
from hackagent.models.config import (
ConnectionSpec, GenerationSpec, ModelConfig,
ModelConnection, ModelGeneration,
)
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| name |
str |
Yes |
Model name as the provider names it
|
| connection |
ConnectionSpec |
Yes |
Transport/provider settings
|
| generation |
GenerationSpec |
No |
Sampling defaults
|
| options |
Mapping[str, Any] |
No |
Agent-specific settings
|
Outputs
| Name |
Type |
Description
|
| ModelConnection.to_litellm() |
Dict[str, Any] |
LiteLLM connection kwargs (api_key resolved)
|
| ModelGeneration.to_kwargs() |
Dict[str, Any] |
Non-null generation kwargs for completion
|
Usage Examples
Define a Target Model
from hackagent.models.config import ModelConfig, ConnectionSpec, GenerationSpec
target = ModelConfig(
name="gpt-4o-mini",
connection=ConnectionSpec(
provider="openai",
type="LITELLM",
api_key_env="OPENAI_API_KEY",
),
generation=GenerationSpec(temperature=0.0, max_tokens=512),
)
Resolve Connection to LiteLLM kwargs
from hackagent.models.config import ModelConnection
conn = ModelConnection(api_key_env="OPENAI_API_KEY")
litellm_kwargs = conn.to_litellm() # {"api_key": "<from env>", "timeout": 120.0}
Resolve Generation to kwargs
from hackagent.models.config import ModelGeneration
gen = ModelGeneration(temperature=0.7, max_tokens=256)
call_kwargs = gen.to_kwargs() # {"temperature": 0.7, "max_tokens": 256}
Related Pages
Implements Principle