Skip to content

search_space

search_space

Search space builder and default search space for configuration optimization.

Classes

Functions

build_search_space

build_search_space(config: Dict[str, Any]) -> SearchSpace

Build a SearchSpace from a TOML-style config dict.

Expected format::

{
    "optimize": {
        "search": [
            {
                "name": "agent.type",
                "type": "categorical",
                "values": ["orchestrator", "native_react"],
                "description": "Agent architecture",
            },
            {
                "name": "intelligence.temperature",
                "type": "continuous",
                "low": 0.0,
                "high": 1.0,
                "description": "Generation temperature",
            },
        ],
        "fixed": {"engine": "ollama", "model": "qwen3:8b"},
        "constraints": {
            "rules": ["SimpleAgent should only have max_turns = 1"],
        },
    }
}
Source code in src/openjarvis/learning/optimize/search_space.py
def build_search_space(config: Dict[str, Any]) -> SearchSpace:
    """Build a SearchSpace from a TOML-style config dict.

    Expected format::

        {
            "optimize": {
                "search": [
                    {
                        "name": "agent.type",
                        "type": "categorical",
                        "values": ["orchestrator", "native_react"],
                        "description": "Agent architecture",
                    },
                    {
                        "name": "intelligence.temperature",
                        "type": "continuous",
                        "low": 0.0,
                        "high": 1.0,
                        "description": "Generation temperature",
                    },
                ],
                "fixed": {"engine": "ollama", "model": "qwen3:8b"},
                "constraints": {
                    "rules": ["SimpleAgent should only have max_turns = 1"],
                },
            }
        }
    """
    opt = config.get("optimize", {})
    search_entries: List[Dict[str, Any]] = opt.get("search", [])
    fixed: Dict[str, Any] = dict(opt.get("fixed", {}))
    constraints_sec = opt.get("constraints", {})
    constraints: List[str] = list(constraints_sec.get("rules", []))

    dimensions: List[SearchDimension] = []
    for entry in search_entries:
        # Infer primitive from the first segment of the dotted name
        name = entry.get("name", "")
        primitive = name.split(".")[0] if "." in name else ""

        dimensions.append(
            SearchDimension(
                name=name,
                dim_type=entry.get("type", "categorical"),
                values=list(entry.get("values", [])),
                low=entry.get("low"),
                high=entry.get("high"),
                description=entry.get("description", ""),
                primitive=primitive,
            )
        )

    return SearchSpace(
        dimensions=dimensions,
        fixed=fixed,
        constraints=constraints,
    )