hackagent.models.factory
Build role-model LLMs, with credentials from :class:Settings.
:class:ModelFactory implements the LLMFactory protocol. A role model
uses the key its spec names. The only credential the factory adds is the
HackAgent API key, and only for a spec whose endpoint is the configured HackAgent LLM
gateway; it is never sent to any other provider.
:func:spec_from_config reads the role-model dicts attack configs still
use (identifier, endpoint, agent_type, api_key as a secret
value or explicit ${VARIABLE} reference, ...).
PASSTHROUGH_REQUEST_KEYS
Provider request parameters a role config may set.
passthrough_params
def passthrough_params(config: Mapping[str, Any]) -> Dict[str, Any]
Return the provider request parameters set in config.
spec_from_config
def spec_from_config(
config: Mapping[str, Any],
*,
spec_type: Type[SpecT] = ModelSpec,
default_agent_type: AgentType = AgentType.OPENAI) -> SpecT
Build a spec from a role-model config dict.
A missing or invalid agent_type becomes default_agent_type.
model overrides identifier as the model name; request_timeout
is accepted for timeout; keys under agent_metadata fill any the
config leaves unset. thinking is kept only for Ollama, which is the
only role-model type that has ever honoured it. Fields of spec_type
beyond :class:ModelSpec (e.g. system_prompt) are read too.
Raises:
ValueError- If the config has noidentifier.
ModelFactory Objects
class ModelFactory()
Builds the LLM for a role model. Implements LLMFactory.
is_gateway
def is_gateway(endpoint: Optional[str]) -> bool
Whether endpoint is the configured LLM gateway and a platform key is set.
with_credentials
def with_credentials(spec: SpecT) -> SpecT
Add the gateway key to a gateway spec that names no key.
with_model_credentials
def with_model_credentials(config: ModelConfig) -> ModelConfig
Bind only this settings instance's gateway credential to a model.