Fix LLM model env override for agents and tools
This commit is contained in:
parent
5c4d00fb2a
commit
1f3e152fa9
2 changed files with 15 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
@ -129,6 +130,10 @@ def build_agent(
|
||||||
name: description
|
name: description
|
||||||
for name, description in (allowed_tools or {}).items()
|
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)
|
agent = IntelligentAgent(instruction=instruction, allowed_tools=tool_map)
|
||||||
if model:
|
if model:
|
||||||
agent.model = model
|
agent.model = model
|
||||||
|
|
|
||||||
16
mud_tools.py
16
mud_tools.py
|
|
@ -7,6 +7,10 @@ from typing import Optional, Type
|
||||||
from tools import Tool
|
from tools import Tool
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_LLM_MODEL = "mistral/mistral-small"
|
||||||
|
LLM_MODEL_ENV = "MISTLE_LLM_MODEL"
|
||||||
|
|
||||||
|
|
||||||
TOOL_REGISTRY = {
|
TOOL_REGISTRY = {
|
||||||
"look": {
|
"look": {
|
||||||
"module": "tools",
|
"module": "tools",
|
||||||
|
|
@ -50,17 +54,13 @@ TOOL_REGISTRY = {
|
||||||
"intelligent": {
|
"intelligent": {
|
||||||
"module": "intelligent_tool",
|
"module": "intelligent_tool",
|
||||||
"class": "IntelligentCommunicationTool",
|
"class": "IntelligentCommunicationTool",
|
||||||
"kwargs": {
|
"kwargs": {},
|
||||||
"model": os.environ.get("MISTLE_LLM_MODEL", "mistral/mistral-small")
|
|
||||||
},
|
|
||||||
"description": "Uses an LLM to craft a polite reply to private tells.",
|
"description": "Uses an LLM to craft a polite reply to private tells.",
|
||||||
},
|
},
|
||||||
"intelligentcommunication": {
|
"intelligentcommunication": {
|
||||||
"module": "intelligent_tool",
|
"module": "intelligent_tool",
|
||||||
"class": "IntelligentCommunicationTool",
|
"class": "IntelligentCommunicationTool",
|
||||||
"kwargs": {
|
"kwargs": {},
|
||||||
"model": os.environ.get("MISTLE_LLM_MODEL", "mistral/mistral-small")
|
|
||||||
},
|
|
||||||
"description": "Alias of 'intelligent'. Uses an LLM to craft a polite reply to private tells.",
|
"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"]
|
class_name = meta["class"]
|
||||||
kwargs = dict(meta.get("kwargs", {}))
|
kwargs = dict(meta.get("kwargs", {}))
|
||||||
kwargs = _apply_builtin_args(key, args, 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:
|
try:
|
||||||
module = import_module(module_name)
|
module = import_module(module_name)
|
||||||
tool_cls = getattr(module, class_name)
|
tool_cls = getattr(module, class_name)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue