Skip to content

Commit c0d2ee4

Browse files
committed
expand the config and custom toolset path
1 parent bb7b57e commit c0d2ee4

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

src/aks-preview/azext_aks_preview/_consts.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,9 @@
373373
CONST_K8S_EXTENSION_NAME = "k8s-extension"
374374
CONST_K8S_EXTENSION_ACTION_MOD_NAME = "azext_k8s_extension.action"
375375
CONST_K8S_EXTENSION_FORMAT_MOD_NAME = "azext_k8s_extension._format"
376+
377+
# aks agent constants
378+
CONST_AGENT_CONFIG_PATH_DIR_ENV_KEY = "CONFIG_PATH_DIR"
379+
CONST_AGENT_NAME = "AKS AGENT"
380+
CONST_AGENT_NAME_ENV_KEY = "AGENT_NAME"
381+
CONST_AGENT_CONFIG_FILE_NAME = "aksAgent.config"

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2842,7 +2842,7 @@ def load_arguments(self, _):
28422842
action="store_true",
28432843
)
28442844
c.argument(
2845-
"custom-toolsets",
2845+
"custom_toolsets",
28462846
help="File path to a custom toolsets.",
28472847
validator=validate_agent_custom_toolsets,
28482848
required=False,

src/aks-preview/azext_aks_preview/_validators.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from math import isclose, isnan
1414

1515
from azure.cli.core import keys
16+
from azure.cli.core.api import get_config_dir
1617
from azure.cli.core.azclierror import (
1718
ArgumentUsageError,
1819
InvalidArgumentValueError,
@@ -36,6 +37,7 @@
3637
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK,
3738
CONST_NODEPOOL_MODE_GATEWAY,
3839
CONST_AZURE_SERVICE_MESH_MAX_EGRESS_NAME_LENGTH,
40+
CONST_AGENT_CONFIG_FILE_NAME,
3941
)
4042
from azext_aks_preview._helpers import _fuzzy_match
4143
from knack.log import get_logger
@@ -979,6 +981,7 @@ def validate_location_resource_group_cluster_parameters(namespace):
979981
"Cannot specify --location and --resource-group and --cluster at the same time."
980982
)
981983

984+
982985
def _validate_param_yaml_file(yaml_path, param_name):
983986
if not yaml_path:
984987
return
@@ -1007,6 +1010,9 @@ def validate_agent_config_file(namespace):
10071010
config_file = namespace.config_file
10081011
if not config_file:
10091012
return
1013+
default_config_path = os.path.join(get_config_dir(), CONST_AGENT_CONFIG_FILE_NAME)
1014+
if config_file == default_config_path and not os.path.exists(config_file):
1015+
return
10101016

10111017
_validate_param_yaml_file(config_file, "config-file")
10121018

@@ -1016,4 +1022,3 @@ def validate_agent_custom_toolsets(namespace):
10161022
if not custom_toolsets:
10171023
return
10181024
_validate_param_yaml_file(custom_toolsets, "custom-toolsets")
1019-

src/aks-preview/azext_aks_preview/agent/agent.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
import uuid
1111
from pathlib import Path
1212

13+
from azext_aks_preview._consts import (
14+
CONST_AGENT_CONFIG_FILE_NAME,
15+
CONST_AGENT_CONFIG_PATH_DIR_ENV_KEY,
16+
CONST_AGENT_NAME,
17+
CONST_AGENT_NAME_ENV_KEY,
18+
)
1319
from azure.cli.core.api import get_config_dir
1420
from azure.cli.core.commands.client_factory import get_subscription_id
1521
from knack.util import CLIError
@@ -87,9 +93,9 @@ def aks_agent(
8793

8894
console = init_log()
8995

90-
os.environ["CONFIG_PATH_DIR"] = get_config_dir()
96+
os.environ[CONST_AGENT_CONFIG_PATH_DIR_ENV_KEY] = get_config_dir()
9197
# Holmes library allows the user to specify the agent name through environment variable before loading the library.
92-
os.environ["AGENT_NAME"] = "AKS AGENT"
98+
os.environ[CONST_AGENT_NAME_ENV_KEY] = CONST_AGENT_NAME
9399

94100
from holmes.config import Config
95101
from holmes.core.prompt import build_initial_ask_messages
@@ -109,15 +115,19 @@ def aks_agent(
109115
)
110116
interactive = False
111117

112-
config_file = Path(config_file)
118+
expanded_config_file = Path(os.path.expanduser(config_file))
119+
expanded_custom_toolsets_list = (
120+
[Path(os.path.expanduser(custom_toolsets))]
121+
if custom_toolsets is not None
122+
else None
123+
)
124+
113125
config = Config.load_from_file(
114-
config_file,
126+
expanded_config_file,
115127
model=model,
116128
api_key=api_key,
117129
max_steps=max_steps,
118-
custom_toolsets_from_cli=(
119-
[custom_toolsets] if custom_toolsets is not None else None
120-
),
130+
custom_toolsets_from_cli=expanded_custom_toolsets_list,
121131
)
122132

123133
ai = config.create_console_toolcalling_llm(

0 commit comments

Comments
 (0)