feat(agent): refactor LLM configuration to support new llm_model_configs system

- Remove direct logging of LLM config from gns3_copilot.py
- Update model_factory to accept configuration from llm_model_configs dictionary
- Add fallback to environment variables for backward compatibility
- Centralize configuration loading in _load_llm_config function
This commit is contained in:
YueGuobin committed 2026-03-03 23:26:20 +08:00
1 parent 3c54a7d90a
commit 4857cff59c
10 files changed
+77 -305

No files matched your search

@@ -5,6 +5,7 @@ This module provides a tool to execute configuration commands on multiple device
import json
import logging
import os
from typing import Any
from langchain.tools import BaseTool
@@ -15,10 +16,7 @@ from nornir.core import Nornir
from nornir.core.task import AggregatedResult, Result, Task
from nornir_netmiko.tasks import netmiko_send_config
from gns3_copilot.utils import (
get_config,
get_device_ports_from_topology,
)
from gns3_copilot.utils import get_device_ports_from_topology
# config log
logger = logging.getLogger(__name__)
@@ -35,10 +33,10 @@ def _get_nornir_groups_config() -> dict[str, dict[str, Any]]:
return {
"cisco_IOSv_telnet": {
"platform": "cisco_ios",
"hostname": get_config("GNS3_SERVER_HOST"),
"hostname": os.getenv("GNS3_SERVER_HOST", "127.0.0.1"),
"timeout": 120,
"username": get_config("GNS3_SERVER_USERNAME"),
"password": get_config("GNS3_SERVER_PASSWORD"),
"username": os.getenv("GNS3_SERVER_USERNAME", ""),
"password": os.getenv("GNS3_SERVER_PASSWORD", ""),
"connection_options": {
"netmiko": {"extras": {"device_type": "cisco_ios_telnet"}}
},
@@ -373,7 +371,7 @@ class ExecuteMultipleDeviceConfigCommands(BaseTool):
defaults = _get_nornir_defaults()
# Log nornir account information
gns3_host = get_config("GNS3_SERVER_HOST")
gns3_host = os.getenv("GNS3_SERVER_HOST", "127.0.0.1")
logger.info(
"Initializing Nornir with account: host=%s, platform=%s, timeout=%d",
@@ -5,6 +5,7 @@ This module provides a tool to execute display commands on multiple devices
import json
import logging
import os
import re
from typing import Any
@@ -16,10 +17,7 @@ from nornir.core import Nornir
from nornir.core.task import AggregatedResult, Result, Task
from nornir_netmiko.tasks import netmiko_multiline
from gns3_copilot.utils import (
get_config,
get_device_ports_from_topology,
)
from gns3_copilot.utils import get_device_ports_from_topology
# config log
logger = logging.getLogger(__name__)
@@ -36,10 +34,10 @@ def _get_nornir_groups_config() -> dict[str, dict[str, Any]]:
return {
"cisco_IOSv_telnet": {
"platform": "cisco_ios",
"hostname": get_config("GNS3_SERVER_HOST"),
"hostname": os.getenv("GNS3_SERVER_HOST", "127.0.0.1"),
"timeout": 120,
"username": get_config("GNS3_SERVER_USERNAME"),
"password": get_config("GNS3_SERVER_PASSWORD"),
"username": os.getenv("GNS3_SERVER_USERNAME", ""),
"password": os.getenv("GNS3_SERVER_PASSWORD", ""),
"connection_options": {
"netmiko": {"extras": {"device_type": "cisco_ios_telnet"}}
},
@@ -387,7 +385,7 @@ class ExecuteMultipleDeviceCommands(BaseTool):
defaults = _get_nornir_defaults()
# Log nornir account information
gns3_host = get_config("GNS3_SERVER_HOST")
gns3_host = os.getenv("GNS3_SERVER_HOST", "127.0.0.1")
logger.info(
"Initializing Nornir with account: host=%s, platform=%s, timeout=%d",
@@ -5,6 +5,7 @@ via Telnet console.
import json
import logging
import os
import re
import time
from typing import Any
@@ -16,10 +17,7 @@ from nornir.core import Nornir
from nornir.core.task import AggregatedResult, Result, Task
from nornir_netmiko.tasks import netmiko_send_command
from gns3_copilot.utils import (
get_config,
get_device_ports_from_topology,
)
from gns3_copilot.utils import get_device_ports_from_topology
# config log
logger = logging.getLogger(__name__)
@@ -36,10 +34,10 @@ def _get_nornir_groups_config() -> dict[str, dict[str, Any]]:
return {
"linux_telnet": {
"platform": "linux",
"hostname": get_config("GNS3_SERVER_HOST"),
"hostname": os.getenv("GNS3_SERVER_HOST", "127.0.0.1"),
"timeout": 120,
"username": get_config("LINUX_TELNET_USERNAME"),
"password": get_config("LINUX_TELNET_PASSWORD"),
"username": os.getenv("LINUX_TELNET_USERNAME", ""),
"password": os.getenv("LINUX_TELNET_PASSWORD", ""),
"connection_options": {
"netmiko": {
"platform": "linux",
@@ -172,8 +170,8 @@ class LinuxTelnetBatchTool(BaseTool):
return device_configs_list
# Check credentials only for valid inputs
linux_username = get_config("LINUX_TELNET_USERNAME")
linux_password = get_config("LINUX_TELNET_PASSWORD")
linux_username = os.getenv("LINUX_TELNET_USERNAME", "")
linux_password = os.getenv("LINUX_TELNET_PASSWORD", "")
if not linux_username or not linux_password:
user_message = (
@@ -5,6 +5,7 @@ Supports concurrent execution of multiple command groups across multiple VPCS de
import json
import logging
import os
import re
import threading
from time import sleep
@@ -14,7 +15,7 @@ from langchain.tools import BaseTool
from langchain_core.callbacks import CallbackManagerForToolRun
from telnetlib3 import Telnet
from gns3_copilot.utils import get_config, get_device_ports_from_topology
from gns3_copilot.utils import get_device_ports_from_topology
logger = logging.getLogger(__name__)
@@ -357,8 +358,8 @@ class VPCSMultiCommands(BaseTool):
list(device_ports.keys()),
)
# Get host IP from database
gns3_host = get_config("GNS3_SERVER_HOST", "127.0.0.1")
# Get host IP from environment variable
gns3_host = os.getenv("GNS3_SERVER_HOST", "127.0.0.1")
logger.info("Using GNS3 server host: %s", gns3_host)
# Initialize results list (pre-allocate space for concurrent writes)