Fix LLM model env override for agents and tools

This commit is contained in:
Daniel Eder 2026-02-10 20:08:26 +01:00
parent 5c4d00fb2a
commit 1f3e152fa9
No known key found for this signature in database
GPG key ID: CE7446DFCE599F32
2 changed files with 15 additions and 6 deletions

View file

@ -1,6 +1,7 @@
from __future__ import annotations
import itertools
import os
import sys
from abc import ABC, abstractmethod
from dataclasses import dataclass
@ -129,6 +130,10 @@ def build_agent(
name: description
for name, description in (allowed_tools or {}).items()
}
if model is None:
env_model = os.environ.get("MISTLE_LLM_MODEL", "").strip()
if env_model:
model = env_model
agent = IntelligentAgent(instruction=instruction, allowed_tools=tool_map)
if model:
agent.model = model

View file

@ -7,6 +7,10 @@ from typing import Optional, Type
from tools import Tool
DEFAULT_LLM_MODEL = "mistral/mistral-small"
LLM_MODEL_ENV = "MISTLE_LLM_MODEL"
TOOL_REGISTRY = {
"look": {
"module": "tools",
@ -50,17 +54,13 @@ TOOL_REGISTRY = {
"intelligent": {
"module": "intelligent_tool",
"class": "IntelligentCommunicationTool",
"kwargs": {
"model": os.environ.get("MISTLE_LLM_MODEL", "mistral/mistral-small")
},
"kwargs": {},
"description": "Uses an LLM to craft a polite reply to private tells.",
},
"intelligentcommunication": {
"module": "intelligent_tool",
"class": "IntelligentCommunicationTool",
"kwargs": {
"model": os.environ.get("MISTLE_LLM_MODEL", "mistral/mistral-small")
},
"kwargs": {},
"description": "Alias of 'intelligent'. Uses an LLM to craft a polite reply to private tells.",
},
}
@ -81,6 +81,10 @@ def build_tool(spec: str) -> Tool:
class_name = meta["class"]
kwargs = dict(meta.get("kwargs", {}))
kwargs = _apply_builtin_args(key, args, kwargs)
if key in {"intelligent", "intelligentcommunication"}:
default_model = kwargs.get("model", DEFAULT_LLM_MODEL)
env_model = os.environ.get(LLM_MODEL_ENV, "").strip()
kwargs["model"] = env_model or default_model
try:
module = import_module(module_name)
tool_cls = getattr(module, class_name)