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 Model Connect

From Leeroopedia
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

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"}])

Related Pages

Implements Principle

Page Connections

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