From 1f3e152fa97c5f1557d9b08be88c7f9ddf62409c Mon Sep 17 00:00:00 2001 From: Daniel Eder Date: Tue, 10 Feb 2026 20:08:26 +0100 Subject: [PATCH] Fix LLM model env override for agents and tools --- agents.py | 5 +++++ mud_tools.py | 16 ++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/agents.py b/agents.py index 135cd06..3468db1 100644 --- a/agents.py +++ b/agents.py @@ -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 diff --git a/mud_tools.py b/mud_tools.py index 557e6a3..590663e 100644 --- a/mud_tools.py +++ b/mud_tools.py @@ -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)