Implementation:AISecurityLab Hackagent Model Connect
| Knowledge Sources | |
|---|---|
| Domains | Model_Adapter |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete function connecting a ModelSpec to a Model instance, building native agent types directly and LiteLLM chat providers via a ModelConfig projection, with no network I/O, provided by the HackAgent models package.
Description
connect() takes a ModelSpec and returns a Model. For native agent types (CLI agents, ADK, web), it builds the model directly from the spec so extra options (binary, url, user_id) survive. For LiteLLM chat providers, it projects the spec onto a ModelConfig and calls build_model(). No network I/O happens — an unset api_key_env fails when the model is built, so config errors surface before a run. check_supported() validates the agent type.
Usage
- Model connection: The factory and preflight use connect() to build models from specs.
Code Reference
Source Location
- Repository: AISecurityLab_Hackagent
- File: hackagent/models/connect.py
Signature
def check_supported(agent_type: AgentType) -> None: ...
def connect(spec: ModelSpec, *, instance_id: Optional[str] = None) -> Model: ...
Import
from hackagent.models.connect import connect, check_supported
Usage Examples
Connect a Model from a Spec
from hackagent.models.connect import connect
from hackagent.core.contracts.specs import ModelSpec
spec = ModelSpec(identifier="gpt-4o", agent_type="LITELLM", api_key_env="OPENAI_API_KEY")
model = connect(spec) # No network I/O yet
result = await model.acomplete([{"role": "user", "content": "Hi"}])