mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-10-24 11:52:23 +03:00
feat(docs): update context window management documentation
- Refactor system message structure to combine system prompt and topology info using template variables - Update token calculation process with merged system message approach - Clarify priority order for message retention during context window management - Add detailed token counting implementation using tiktoken library - Include boundary case handling for system message exceeding budget - Add SPDX license headers to tool files for proper licensing documentation
This commit is contained in:
parent
ed5fd7d17c
commit
d12b2df306
@ -257,17 +257,22 @@ pip install tiktoken>=0.8.0
|
|||||||
发送给 LLM 的完整请求:
|
发送给 LLM 的完整请求:
|
||||||
┌─────────────────────────────────────────────────────────────┐
|
┌─────────────────────────────────────────────────────────────┐
|
||||||
│ 1. Messages (我们管理的) │
|
│ 1. Messages (我们管理的) │
|
||||||
│ ├─ SystemMessage: system prompt │
|
│ ├─ SystemMessage: system prompt + topology (模板注入) │
|
||||||
│ ├─ SystemMessage: topology info │
|
│ └─ HumanMessage/AIMessage: 用户消息 / 历史消息 │
|
||||||
│ └─ HumanMessage: 用户消息 / 历史消息 │
|
|
||||||
├─────────────────────────────────────────────────────────────┤
|
├─────────────────────────────────────────────────────────────┤
|
||||||
│ 2. Tool Definitions (LangChain 自动添加,不在消息中) │
|
│ 2. Tool Definitions (LangChain 自动添加,不在消息中) │
|
||||||
│ ├─ Tool 1 schema (name, description, parameters) │
|
│ ├─ Tool 1 schema (name, description, parameters) │
|
||||||
│ ├─ Tool 2 schema │
|
│ ├─ Tool 2 schema │
|
||||||
│ └─ ... (约 1000-2000 tokens per tool) │
|
│ └─ ... (约 500-1500 tokens per tool) │
|
||||||
└─────────────────────────────────────────────────────────────┘
|
└─────────────────────────────────────────────────────────────┘
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**System Message 结构**:
|
||||||
|
- 使用模板变量 `{{topology_info}}` 动态注入 topology
|
||||||
|
- System prompt 包含占位符:`"### CURRENT TOPOLOGY\n{{topology_info}}"`
|
||||||
|
- 如果有 topology,替换为实际内容
|
||||||
|
- 如果没有 topology,替换为 `"(No topology information available)"`
|
||||||
|
|
||||||
#### 2.2 裁剪流程
|
#### 2.2 裁剪流程
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -287,14 +292,14 @@ pip install tiktoken>=0.8.0
|
|||||||
│ 可用于消息 = 9,600 - 1,862 = 7,738 tokens │
|
│ 可用于消息 = 9,600 - 1,862 = 7,738 tokens │
|
||||||
└─────────────────────────────────────────────────────────────┘
|
└─────────────────────────────────────────────────────────────┘
|
||||||
↓
|
↓
|
||||||
第三步:分离系统消息和对话历史
|
第三步:计算 System Message token(已合并)
|
||||||
┌─────────────────────────────────────────────────────────────┐
|
┌─────────────────────────────────────────────────────────────┐
|
||||||
│ 可用于消息: 7,738 tokens │
|
│ 可用于消息: 7,738 tokens │
|
||||||
│ │
|
│ │
|
||||||
│ System Messages (保留): │
|
│ System Message (已包含 system + topology): │
|
||||||
│ - System prompt: ~1,000 tokens │
|
│ - System prompt (base): ~1,000 tokens │
|
||||||
│ - Topology info: ~3,000 tokens │
|
│ - Topology info: ~3,000 tokens │
|
||||||
│ = 4,000 tokens │
|
│ = 4,000 tokens (合并后) │
|
||||||
│ │
|
│ │
|
||||||
│ 可用于历史 = 7,738 - 4,000 = 3,738 tokens │
|
│ 可用于历史 = 7,738 - 4,000 = 3,738 tokens │
|
||||||
└─────────────────────────────────────────────────────────────┘
|
└─────────────────────────────────────────────────────────────┘
|
||||||
@ -313,19 +318,25 @@ pip install tiktoken>=0.8.0
|
|||||||
|
|
||||||
| 优先级 | 内容 | 说明 |
|
| 优先级 | 内容 | 说明 |
|
||||||
|--------|------|------|
|
|--------|------|------|
|
||||||
| 1️⃣ | System Prompt | 永远保留(第1个) |
|
| 1️⃣ | System Message (system prompt + topology) | 永远保留 |
|
||||||
| 2️⃣ | Topology Info | 永远保留(第2个) |
|
| 2️⃣ | 最新用户消息 | 至少保留最后1条 |
|
||||||
| 3️⃣ | 最新用户消息 | 至少保留最后1条 |
|
| 3️⃣ | 旧对话历史 | 按时间顺序丢弃 |
|
||||||
| 4️⃣ | 旧对话历史 | 按时间顺序丢弃 |
|
|
||||||
|
**注意**:System prompt 和 topology info 通过模板变量合并为一个 SystemMessage,无法单独分离。
|
||||||
|
|
||||||
#### 2.4 边界情况处理
|
#### 2.4 边界情况处理
|
||||||
|
|
||||||
| 情况 | 处理方式 |
|
| 情况 | 处理方式 |
|
||||||
|------|----------|
|
|------|----------|
|
||||||
| System > 预算 | 只保留 system prompt,丢弃所有其他消息 |
|
| System (包含 topology) > 预算 | 保留完整的 System Message(无法分离 system 和 topology) |
|
||||||
| Tools > 预算 | 警告日志,建议增加 context_limit |
|
| Tools > 预算 | 警告日志,建议增加 context_limit 或减少工具数量 |
|
||||||
| 历史全被裁剪 | 保留最后1条用户消息 |
|
| 历史全被裁剪 | 保留最后1条用户消息 |
|
||||||
|
|
||||||
|
**重要提示**:
|
||||||
|
- 当 system + topology 超出可用预算时,**两者都会被保留**
|
||||||
|
- 无法只丢弃 topology 而保留 system prompt(因为已合并)
|
||||||
|
- 建议在 system prompt 中精简 topology 信息或使用更短的 system prompt
|
||||||
|
|
||||||
### 2. 集成到 GNS3 Copilot
|
### 2. 集成到 GNS3 Copilot
|
||||||
|
|
||||||
**修改文件**: `gns3server/agent/gns3_copilot/agent/gns3_copilot.py`
|
**修改文件**: `gns3server/agent/gns3_copilot/agent/gns3_copilot.py`
|
||||||
@ -358,29 +369,49 @@ full_messages = prepare_context_messages(
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. LangChain/LangGraph 的内置功能
|
### 3. Token 计数实现细节
|
||||||
|
|
||||||
#### `trim_messages` 参数说明
|
系统使用 **tiktoken** 进行准确的 Token 计数:
|
||||||
|
|
||||||
|
#### 3.1 Token 计数器
|
||||||
|
|
||||||
|
**使用的编码**:`cl100k_base` (GPT-4)
|
||||||
|
|
||||||
|
**支持的模型**:
|
||||||
|
- ✅ OpenAI (GPT-4, GPT-3.5)
|
||||||
|
- ✅ Anthropic (Claude 系列)
|
||||||
|
- ✅ DeepSeek (deepseek-chat, deepseek-coder)
|
||||||
|
- ✅ 大多数基于 GPT-4 架构的模型
|
||||||
|
|
||||||
|
**准确率**:
|
||||||
|
- 英文:95%+
|
||||||
|
- 中文:95%+
|
||||||
|
- 代码:90-95%
|
||||||
|
|
||||||
|
#### 3.2 工具定义 Token 估算
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from langchain_core.messages.utils import trim_messages
|
def estimate_tool_tokens(tools: list[Any]) -> int:
|
||||||
|
"""动态序列化工具 schema 并计算 token"""
|
||||||
trimmed = trim_messages(
|
for tool in tools:
|
||||||
messages,
|
tool_schema = {
|
||||||
strategy="last", # 保留最近的 N 条消息
|
"type": "function",
|
||||||
max_tokens=10000, # 最大 token 数
|
"function": {
|
||||||
token_counter=count_tokens_approximately, # Token 计数器
|
"name": tool.name,
|
||||||
preserve_system=True, # 保留系统消息
|
"description": tool.description,
|
||||||
start_on="human", # 确保从人类消息开始
|
"parameters": tool.args_schema.schema()
|
||||||
end_on=("human", "tool", "ai"), # 在特定类型消息结束
|
}
|
||||||
)
|
}
|
||||||
|
# 使用 tiktoken 计数
|
||||||
|
schema_str = json.dumps(tool_schema, ensure_ascii=False)
|
||||||
|
tool_tokens = len(encoding.encode(schema_str))
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `count_tokens_approximately`
|
**典型消耗**:
|
||||||
|
- 简单工具(1-2 个参数):500-800 tokens
|
||||||
- 快速估算消息的 token 数量
|
- 中等工具(3-5 个参数):800-1200 tokens
|
||||||
- 不需要调用 LLM API
|
- 复杂工具(嵌套参数):1200-1500 tokens
|
||||||
- 用于判断是否需要裁剪
|
- 8 个工具:约 6000-10000 tokens
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -601,19 +632,34 @@ ERROR: context_limit is required but not provided for model 'gpt-4o'.
|
|||||||
|
|
||||||
### 日志格式说明
|
### 日志格式说明
|
||||||
|
|
||||||
新的日志格式(包含工具定义):
|
新的日志格式(包含工具定义和 topology 分解):
|
||||||
```
|
```
|
||||||
Context prepared: {消息数} msgs, ~{消息tokens} tokens (messages) + {工具tokens} tokens (tools) = {总计tokens} total / {限制}K limit ({使用百分比}%), strategy={策略}
|
Context prepared: system={总tokens} (base={base_tokens} + topology={topology_tokens}) + history={history_tokens} + tools={tool_tokens} = {总计} total / {限制}K limit ({使用百分比}%), strategy={策略}
|
||||||
```
|
```
|
||||||
|
|
||||||
字段说明:
|
字段说明:
|
||||||
- **消息数**: 对话历史中的消息条数(不包括 system prompt)
|
- **system**:System Message 的总 token 数(包含 system prompt + topology)
|
||||||
- **消息 tokens**: 对话历史 + system prompt + topology context 的 token 数
|
- **base**:基础 system prompt 的 token 数(不含 topology)
|
||||||
- **工具 tokens**: 工具定义(schema)的 token 数
|
- **topology**:Topology info 的 token 数
|
||||||
- **总计 tokens**: 消息 tokens + 工具 tokens
|
- **history**:对话历史(HumanMessage + AIMessage + ToolMessage)的 token 数
|
||||||
- **限制**: 模型的上下文窗口大小(K tokens)
|
- **tools**:工具定义(schema)的 token 数
|
||||||
- **使用百分比**: 总计 tokens / 限制 × 100%
|
- **总计**:所有部分的 token 总和
|
||||||
- **策略**: 使用的裁剪策略(conservative/balanced/aggressive)
|
- **限制**:模型的上下文窗口大小(K tokens)
|
||||||
|
- **使用百分比**:总计 tokens / 限制 × 100%
|
||||||
|
- **策略**:使用的裁剪策略(conservative/balanced/aggressive)
|
||||||
|
|
||||||
|
**示例输出**:
|
||||||
|
```
|
||||||
|
Context prepared: system=6124 (base=2804 + topology=3320) + history=11800 + tools=1862 = 19786 total / 128K limit (15.5%), strategy=balanced
|
||||||
|
```
|
||||||
|
|
||||||
|
这表示:
|
||||||
|
- System Message 总共 6124 tokens
|
||||||
|
- 其中基础 system prompt 2804 tokens
|
||||||
|
- 其中 topology info 3320 tokens
|
||||||
|
- 对话历史 11800 tokens
|
||||||
|
- 工具定义 1862 tokens
|
||||||
|
- 总计 19786 tokens,使用 128K 限制的 15.5%
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -764,17 +810,19 @@ except Exception as e:
|
|||||||
|
|
||||||
## 总结
|
## 总结
|
||||||
|
|
||||||
通过使用 LangChain/LangGraph 的内置功能,我们实现了:
|
通过使用 LangChain/LangGraph 的内置功能和自定义优化,我们实现了:
|
||||||
1. ✅ 智能裁剪消息历史,避免超限
|
1. ✅ 智能裁剪消息历史,避免超限
|
||||||
2. ✅ **必须手动配置 context_limit**,确保使用正确的上下文窗口大小
|
2. ✅ **必须手动配置 context_limit**,确保使用正确的上下文窗口大小
|
||||||
3. ✅ 可配置的裁剪策略(保守/平衡/激进)
|
3. ✅ 可配置的裁剪策略(保守/平衡/激进)
|
||||||
4. ✅ 始终保留系统消息和拓扑信息
|
4. ✅ 始终保留系统消息(包含 system prompt 和 topology)
|
||||||
5. ✅ 详细的日志输出,便于调试
|
5. ✅ 详细的日志输出,便于调试
|
||||||
6. ✅ 优雅的错误处理和明确的错误提示
|
6. ✅ 优雅的错误处理和明确的错误提示
|
||||||
7. ✅ 提供参考工具,帮助查找常见模型的上下文限制
|
7. ✅ 提供参考工具,帮助查找常见模型的上下文限制
|
||||||
8. ✅ **使用 tiktoken 进行准确的 token 计数**(准确率 95%+)
|
8. ✅ **使用 tiktoken 进行准确的 token 计数**(准确率 95%+)
|
||||||
9. ✅ **自动估算工具定义的 token 消耗**
|
9. ✅ **自动估算工具定义的 token 消耗**
|
||||||
10. ✅ **支持中文、英文、代码等多种内容类型**
|
10. ✅ **支持中文、英文、代码等多种内容类型**
|
||||||
|
11. ✅ **使用模板变量动态注入 topology info** (新增)
|
||||||
|
12. ✅ **日志中详细显示 system/topology/history 分解** (新增)
|
||||||
|
|
||||||
### 关键优势
|
### 关键优势
|
||||||
|
|
||||||
@ -786,18 +834,21 @@ except Exception as e:
|
|||||||
- **灵活性**:
|
- **灵活性**:
|
||||||
- 每个配置独立设置,支持不同用户使用不同限制
|
- 每个配置独立设置,支持不同用户使用不同限制
|
||||||
- 自动适配不同语言和内容类型
|
- 自动适配不同语言和内容类型
|
||||||
|
- 模板变量注入方式易于维护和调整
|
||||||
|
|
||||||
- **明确性**:
|
- **明确性**:
|
||||||
- 缺少配置时立即报错,避免静默失败
|
- 缺少配置时立即报错,避免静默失败
|
||||||
- 详细日志显示所有 token 消耗(消息 + 工具)
|
- 详细日志显示所有 token 消耗(system base + topology + history + tools)
|
||||||
|
- 清楚显示各部分的 token 分解
|
||||||
|
|
||||||
- **可维护性**:
|
- **可维护性**:
|
||||||
- 无需维护内置默认值,减少代码维护负担
|
- 无需维护内置默认值,减少代码维护负担
|
||||||
|
- 模板变量注入方式,system prompt 和 topology 管理更清晰
|
||||||
- 模块化设计,易于扩展和调试
|
- 模块化设计,易于扩展和调试
|
||||||
|
|
||||||
- **可观测性**:
|
- **可观测性**:
|
||||||
- 详细日志显示上下文使用情况和裁剪决策
|
- 详细日志显示上下文使用情况和裁剪决策
|
||||||
- 区分消息 tokens 和工具 tokens
|
- 区分 system base tokens、topology tokens、history tokens 和工具 tokens
|
||||||
- 显示使用百分比和策略选择
|
- 显示使用百分比和策略选择
|
||||||
|
|
||||||
这个实现确保了即使在进行长对话时,系统也不会因为上下文溢出而失败。
|
这个实现确保了即使在进行长对话时,系统也不会因为上下文溢出而失败。
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
GNS3-Copilot - AI-powered network automation assistant for GNS3.
|
GNS3-Copilot - AI-powered network automation assistant for GNS3.
|
||||||
|
|
||||||
This package provides a command-line interface for launching the GNS3-Copilot
|
This package provides a command-line interface for launching the GNS3-Copilot
|
||||||
|
|||||||
@ -1,7 +1,33 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
GNS3-Copilot Agent Package
|
GNS3-Copilot Agent Package
|
||||||
|
|
||||||
This package contains the main GNS3-Copilot agent implementation for network automation tasks.
|
This package contains the main GNS3-Copilot agent implementation for
|
||||||
|
network automation tasks using LangGraph workflow orchestration.
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .gns3_copilot import agent_builder
|
from .gns3_copilot import agent_builder
|
||||||
|
|||||||
@ -1,19 +1,39 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
#
|
#
|
||||||
# Context Window Manager for GNS3-Copilot
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
#
|
#
|
||||||
# This module manages context window limits for different LLM models,
|
|
||||||
# implementing intelligent message trimming and token counting strategies.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Context Window Manager for GNS3-Copilot
|
Context Window Manager for GNS3-Copilot
|
||||||
|
|
||||||
This module provides context window management for different LLM models,
|
This module provides intelligent context window management for LLM models,
|
||||||
including:
|
including:
|
||||||
- Model-specific context window limits
|
- Model-specific context window limits
|
||||||
- Token counting for messages
|
- Accurate token counting using tiktoken
|
||||||
- Message trimming strategies
|
- Message trimming strategies (conservative/balanced/aggressive)
|
||||||
- System message preservation
|
- System message preservation
|
||||||
|
- Tool definition token estimation
|
||||||
|
- Template variable injection for topology info
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
@ -26,11 +46,24 @@ from langchain_core.messages import (
|
|||||||
SystemMessage,
|
SystemMessage,
|
||||||
ToolMessage,
|
ToolMessage,
|
||||||
)
|
)
|
||||||
from langchain_core.messages.utils import trim_messages
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Constants
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
# Context strategy ratios
|
||||||
|
CONTEXT_STRATEGY_RATIOS = {
|
||||||
|
"conservative": 0.60, # 60% for input, 40% reserved for output
|
||||||
|
"balanced": 0.75, # 75% for input, 25% reserved for output
|
||||||
|
"aggressive": 0.85, # 85% for input, 15% reserved for output
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFAULT_CONTEXT_STRATEGY = "balanced"
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Token Counting - Using tiktoken for accuracy
|
# Token Counting - Using tiktoken for accuracy
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
@ -176,6 +209,10 @@ def estimate_tool_tokens(tools: list[Any]) -> int:
|
|||||||
return total_tokens
|
return total_tokens
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Model Context Limits
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
# NOTE: Built-in model context limits have been removed.
|
# NOTE: Built-in model context limits have been removed.
|
||||||
# Model providers frequently update context limits, and maintaining this list is not sustainable.
|
# Model providers frequently update context limits, and maintaining this list is not sustainable.
|
||||||
# Users MUST configure context_limit explicitly in their LLM model configurations.
|
# Users MUST configure context_limit explicitly in their LLM model configurations.
|
||||||
@ -243,7 +280,7 @@ def get_model_context_limit(
|
|||||||
|
|
||||||
def calculate_max_tokens(
|
def calculate_max_tokens(
|
||||||
model_limit: int,
|
model_limit: int,
|
||||||
strategy: Literal["conservative", "balanced", "aggressive"] = "balanced"
|
strategy: Literal["conservative", "balanced", "aggressive"] = DEFAULT_CONTEXT_STRATEGY
|
||||||
) -> int:
|
) -> int:
|
||||||
"""
|
"""
|
||||||
Calculate the maximum tokens to use, reserving space for output.
|
Calculate the maximum tokens to use, reserving space for output.
|
||||||
@ -258,13 +295,7 @@ def calculate_max_tokens(
|
|||||||
Returns:
|
Returns:
|
||||||
int: Maximum tokens for input messages
|
int: Maximum tokens for input messages
|
||||||
"""
|
"""
|
||||||
ratios = {
|
ratio = CONTEXT_STRATEGY_RATIOS.get(strategy, CONTEXT_STRATEGY_RATIOS[DEFAULT_CONTEXT_STRATEGY])
|
||||||
"conservative": 0.60,
|
|
||||||
"balanced": 0.75,
|
|
||||||
"aggressive": 0.85,
|
|
||||||
}
|
|
||||||
|
|
||||||
ratio = ratios.get(strategy, 0.75)
|
|
||||||
max_tokens = int(model_limit * ratio)
|
max_tokens = int(model_limit * ratio)
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@ -275,11 +306,15 @@ def calculate_max_tokens(
|
|||||||
return max_tokens
|
return max_tokens
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Message Trimming
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
def trim_messages_for_context(
|
def trim_messages_for_context(
|
||||||
messages: list[Any],
|
messages: list[Any],
|
||||||
model_name: str,
|
model_name: str,
|
||||||
llm_config: dict[str, Any] | None = None,
|
llm_config: dict[str, Any] | None = None,
|
||||||
strategy: Literal["conservative", "balanced", "aggressive"] = "balanced",
|
strategy: Literal["conservative", "balanced", "aggressive"] = DEFAULT_CONTEXT_STRATEGY,
|
||||||
preserve_system: bool = True,
|
preserve_system: bool = True,
|
||||||
tool_tokens: int = 0,
|
tool_tokens: int = 0,
|
||||||
) -> list[Any]:
|
) -> list[Any]:
|
||||||
@ -313,7 +348,7 @@ def trim_messages_for_context(
|
|||||||
if not messages:
|
if not messages:
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
# Get model's context limit (from database or built-in defaults)
|
# Get model's context limit (from database config)
|
||||||
model_limit = get_model_context_limit(model_name, llm_config)
|
model_limit = get_model_context_limit(model_name, llm_config)
|
||||||
|
|
||||||
# Calculate usable tokens (reserve space for output)
|
# Calculate usable tokens (reserve space for output)
|
||||||
@ -414,6 +449,10 @@ def _trim_to_token_limit(messages: list[Any], max_tokens: int) -> list[Any]:
|
|||||||
return trimmed
|
return trimmed
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Token Usage Summary
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
def get_token_usage_summary(
|
def get_token_usage_summary(
|
||||||
messages: list[Any],
|
messages: list[Any],
|
||||||
model_name: str,
|
model_name: str,
|
||||||
@ -466,7 +505,10 @@ def get_token_usage_summary(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Convenience function for GNS3-Copilot integration
|
# ============================================================================
|
||||||
|
# Main Entry Point - Context Preparation with Template Injection
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
def prepare_context_messages(
|
def prepare_context_messages(
|
||||||
state_messages: list[Any],
|
state_messages: list[Any],
|
||||||
system_prompt: str,
|
system_prompt: str,
|
||||||
@ -479,11 +521,17 @@ def prepare_context_messages(
|
|||||||
Prepare full context messages for LLM call with automatic trimming.
|
Prepare full context messages for LLM call with automatic trimming.
|
||||||
|
|
||||||
This is the main entry point for GNS3-Copilot to prepare messages
|
This is the main entry point for GNS3-Copilot to prepare messages
|
||||||
before calling the LLM.
|
before calling the LLM. It injects topology info into the system prompt
|
||||||
|
using template variables and performs intelligent message trimming.
|
||||||
|
|
||||||
|
Template Variable Injection:
|
||||||
|
The system_prompt must contain the {{topology_info}} placeholder.
|
||||||
|
This function will replace it with actual topology information or
|
||||||
|
a placeholder message if topology is not available.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
state_messages: Message history from conversation state
|
state_messages: Message history from conversation state
|
||||||
system_prompt: System prompt text
|
system_prompt: System prompt text (must contain {{topology_info}} placeholder)
|
||||||
topology_context: Optional topology information string
|
topology_context: Optional topology information string
|
||||||
model_name: Name of the LLM model
|
model_name: Name of the LLM model
|
||||||
llm_config: Optional LLM config dict from database (may contain context_limit and context_strategy)
|
llm_config: Optional LLM config dict from database (may contain context_limit and context_strategy)
|
||||||
@ -495,51 +543,50 @@ def prepare_context_messages(
|
|||||||
Examples:
|
Examples:
|
||||||
>>> messages = prepare_context_messages(
|
>>> messages = prepare_context_messages(
|
||||||
... state_messages=[HumanMessage("Help me")],
|
... state_messages=[HumanMessage("Help me")],
|
||||||
... system_prompt="You are a helpful assistant",
|
... system_prompt="You are a helpful assistant\\n\\n{{topology_info}}",
|
||||||
... topology_context=None,
|
... topology_context=None,
|
||||||
... model_name="gpt-4o"
|
... model_name="gpt-4o"
|
||||||
... )
|
... )
|
||||||
>>> len(messages)
|
>>> len(messages)
|
||||||
2 # System message + Human message
|
2 # System message + Human message
|
||||||
"""
|
"""
|
||||||
# Get trimming strategy from config (default: "balanced")
|
# Step 1: Get trimming strategy from config
|
||||||
trim_strategy = "balanced"
|
trim_strategy = DEFAULT_CONTEXT_STRATEGY
|
||||||
if llm_config and "context_strategy" in llm_config:
|
if llm_config and "context_strategy" in llm_config:
|
||||||
strategy = llm_config["context_strategy"]
|
strategy = llm_config["context_strategy"]
|
||||||
if strategy in ["conservative", "balanced", "aggressive"]:
|
if strategy in CONTEXT_STRATEGY_RATIOS:
|
||||||
trim_strategy = strategy
|
trim_strategy = strategy
|
||||||
logger.debug("Using context_strategy from config: %s", trim_strategy)
|
logger.debug("Using context_strategy from config: %s", trim_strategy)
|
||||||
else:
|
else:
|
||||||
logger.warning("Invalid context_strategy '%s', using 'balanced'", strategy)
|
logger.warning("Invalid context_strategy '%s', using '%s'", strategy, DEFAULT_CONTEXT_STRATEGY)
|
||||||
|
|
||||||
# Estimate tool tokens (tools are sent with each LLM call)
|
# Step 2: Estimate tool tokens (tools are sent with each LLM call)
|
||||||
tool_tokens = estimate_tool_tokens(tools) if tools else 0
|
tool_tokens = estimate_tool_tokens(tools) if tools else 0
|
||||||
|
|
||||||
# Inject topology info into system prompt using template variable
|
# Step 3: Inject topology info into system prompt using template variable
|
||||||
# The system_prompt contains {{topology_info}} placeholder
|
# The system_prompt contains {{topology_info}} placeholder
|
||||||
if topology_context:
|
if topology_context:
|
||||||
topology_formatted = f"Current Topology:\n{topology_context}"
|
topology_formatted = f"Current Topology:\n{topology_context}"
|
||||||
formatted_prompt = system_prompt.replace("{{topology_info}}", topology_formatted)
|
formatted_prompt = system_prompt.replace("{{topology_info}}", topology_formatted)
|
||||||
else:
|
else:
|
||||||
# If no topology, remove the placeholder
|
# If no topology, use placeholder
|
||||||
formatted_prompt = system_prompt.replace("{{topology_info}}", "(No topology information available)")
|
formatted_prompt = system_prompt.replace("{{topology_info}}", "(No topology information available)")
|
||||||
|
|
||||||
# Calculate token breakdown
|
# Step 4: Calculate token breakdown
|
||||||
system_prompt_tokens = count_tokens_accurately(system_prompt)
|
system_prompt_tokens = count_tokens_accurately(system_prompt)
|
||||||
topology_tokens = count_tokens_accurately(topology_formatted) if topology_context else 0
|
topology_tokens = count_tokens_accurately(topology_formatted) if topology_context else 0
|
||||||
formatted_tokens = count_tokens_accurately(formatted_prompt)
|
formatted_tokens = count_tokens_accurately(formatted_prompt)
|
||||||
|
|
||||||
# Build context messages (single system message with topology injected)
|
# Step 5: Build context messages (single system message with topology injected)
|
||||||
context_messages = [SystemMessage(content=formatted_prompt)]
|
context_messages = [SystemMessage(content=formatted_prompt)]
|
||||||
|
|
||||||
# Calculate conversation history tokens
|
# Step 6: Calculate conversation history tokens
|
||||||
history_tokens = count_messages_tokens(state_messages)
|
history_tokens = count_messages_tokens(state_messages)
|
||||||
total_context_tokens = system_prompt_tokens + topology_tokens + history_tokens
|
|
||||||
|
|
||||||
# Combine with conversation history
|
# Step 7: Combine with conversation history
|
||||||
full_messages = context_messages + state_messages
|
full_messages = context_messages + state_messages
|
||||||
|
|
||||||
# Trim if needed
|
# Step 8: Trim if needed
|
||||||
trimmed_messages = trim_messages_for_context(
|
trimmed_messages = trim_messages_for_context(
|
||||||
full_messages,
|
full_messages,
|
||||||
model_name=model_name,
|
model_name=model_name,
|
||||||
@ -549,11 +596,10 @@ def prepare_context_messages(
|
|||||||
tool_tokens=tool_tokens, # Account for tool definitions
|
tool_tokens=tool_tokens, # Account for tool definitions
|
||||||
)
|
)
|
||||||
|
|
||||||
# Recalculate after trimming
|
# Step 9: Recalculate after trimming
|
||||||
trimmed_history_tokens = count_messages_tokens([m for m in trimmed_messages if not isinstance(m, SystemMessage)])
|
trimmed_history_tokens = count_messages_tokens([m for m in trimmed_messages if not isinstance(m, SystemMessage)])
|
||||||
trimmed_total_tokens = system_prompt_tokens + topology_tokens + trimmed_history_tokens
|
|
||||||
|
|
||||||
# Log summary with detailed breakdown
|
# Step 10: Log summary with detailed breakdown
|
||||||
model_limit_k = get_model_context_limit(model_name, llm_config) // 1000
|
model_limit_k = get_model_context_limit(model_name, llm_config) // 1000
|
||||||
|
|
||||||
if trimmed_history_tokens < history_tokens:
|
if trimmed_history_tokens < history_tokens:
|
||||||
@ -589,16 +635,26 @@ def prepare_context_messages(
|
|||||||
return trimmed_messages
|
return trimmed_messages
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Module Test
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Simple test
|
# Simple test
|
||||||
test_messages = [
|
test_messages = [
|
||||||
HumanMessage(f"Message {i}") for i in range(100)
|
HumanMessage(f"Message {i}") for i in range(100)
|
||||||
]
|
]
|
||||||
|
|
||||||
result = trim_messages_for_context(
|
# Test with mock llm_config
|
||||||
test_messages,
|
mock_config = {"context_limit": 8, "context_strategy": "conservative"}
|
||||||
|
|
||||||
|
result = prepare_context_messages(
|
||||||
|
state_messages=test_messages,
|
||||||
|
system_prompt="You are GNS3 Copilot.\n\n{{topology_info}}",
|
||||||
|
topology_context='{"project_id": "test", "nodes": 5}',
|
||||||
model_name="gpt-4o",
|
model_name="gpt-4o",
|
||||||
strategy="balanced"
|
llm_config=mock_config,
|
||||||
|
tools=None
|
||||||
)
|
)
|
||||||
|
|
||||||
print(f"Original: {len(test_messages)} messages")
|
print(f"Original: {len(test_messages)} messages")
|
||||||
|
|||||||
@ -1,36 +1,42 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
#
|
#
|
||||||
# This file is part of GNS3-Copilot.
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
#
|
#
|
||||||
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
# under the terms of the GNU Affero General Public License as published by the
|
# under the terms of the GNU General Public License as published by the
|
||||||
# Free Software Foundation, either version 3 of the License, or (at your
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
# option) any later version.
|
# option) any later version.
|
||||||
#
|
#
|
||||||
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
# for more details.
|
# for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License along
|
# You should have received a copy of the GNU General Public License
|
||||||
# with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
# mypy: ignore-errors
|
# mypy: ignore-errors
|
||||||
|
|
||||||
"""
|
"""
|
||||||
GNS3 Network Automation Assistant
|
GNS3 Network Automation Assistant - LangGraph Agent
|
||||||
|
|
||||||
This module implements an AI-powered assistant for GNS3 network automation and management.
|
This module implements the core LangGraph agent workflow for GNS3-Copilot,
|
||||||
It uses LangChain for agent orchestration and DeepSeek LLM for natural language processing.
|
an AI-powered assistant for GNS3 network automation and management.
|
||||||
The assistant provides comprehensive GNS3 topology management capabilities including:
|
|
||||||
- Reading and analyzing GNS3 project topologies
|
|
||||||
- Creating and managing network nodes and links
|
|
||||||
- Executing network configuration and display commands on multiple devices
|
|
||||||
- Managing VPCS (Virtual PC Simulator) commands
|
|
||||||
- Starting and controlling GNS3 nodes
|
|
||||||
|
|
||||||
The assistant integrates with various tools to provide a complete network automation
|
The agent provides:
|
||||||
solution for GNS3 environments.
|
- LangGraph-based state management and workflow
|
||||||
|
- Tool orchestration for GNS3 operations
|
||||||
|
- Context-aware conversation handling
|
||||||
|
- Automatic conversation title generation
|
||||||
|
- Integration with GNS3 topology management
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import operator
|
import operator
|
||||||
|
|||||||
@ -1,8 +1,33 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Model Factory for GNS3-Copilot Agent
|
Model Factory for GNS3-Copilot Agent
|
||||||
|
|
||||||
This module provides factory functions to create fresh LLM model instances.
|
This module provides factory functions to create fresh LLM model instances.
|
||||||
Configuration is passed directly from the API layer.
|
Configuration is passed directly from the database.
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
GNS3 Copilot Agent Service
|
GNS3 Copilot Agent Service
|
||||||
|
|
||||||
Provides project-level Agent instances with SQLite checkpoint management.
|
Provides project-level Agent instances with SQLite checkpoint management.
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
Chat Sessions Repository for managing chat session data.
|
Chat Sessions Repository for managing chat session data.
|
||||||
|
|
||||||
Provides CRUD operations for the chat_sessions table in the project's
|
Provides CRUD operations for the chat_sessions table in the project's
|
||||||
|
|||||||
@ -1,8 +1,30 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
GNS3 Client Package
|
GNS3 Client Package
|
||||||
|
|
||||||
This package provides a Python interface for interacting with GNS3 servers.
|
This package provides a Python interface for interacting with GNS3 servers.
|
||||||
It's adapted from the upstream gns3fy project with modifications for compatibility
|
Adapted from the upstream gns3fy project with modifications for compatibility
|
||||||
with langchain and reduced dependency conflicts.
|
with langchain and reduced dependency conflicts.
|
||||||
|
|
||||||
Main classes:
|
Main classes:
|
||||||
@ -11,13 +33,18 @@ Main classes:
|
|||||||
- Node: GNS3 Node management
|
- Node: GNS3 Node management
|
||||||
- Link: GNS3 Link management
|
- Link: GNS3 Link management
|
||||||
- GNS3TopologyTool: GNS3 topology reading tool
|
- GNS3TopologyTool: GNS3 topology reading tool
|
||||||
- GNS3UpdateDrawingTool: GNS3 drawing update tool
|
- GNS3ProjectInfoTool: GNS3 project info tool
|
||||||
|
|
||||||
Main functions:
|
Main functions:
|
||||||
- get_gns3_connector: Factory function to create Gns3Connector from environment
|
- get_gns3_connector: Factory function to create Gns3Connector
|
||||||
- get_gns3_connector_with_llm_config: Factory function to create connector AND retrieve LLM config
|
- get_gns3_connector_with_llm_config: Create connector AND retrieve LLM config
|
||||||
- get_gns3_server_host: Get GNS3 server hostname from Controller or Config
|
- get_gns3_server_host: Get GNS3 server hostname from Controller or Config
|
||||||
- get_llm_config: Get LLM model configuration for a user
|
- get_llm_config: Get LLM model configuration for a user
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
|
|
||||||
|
Upstream gns3fy: https://github.com/davidban77/gns3fy
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .connector_factory import (
|
from .connector_factory import (
|
||||||
|
|||||||
@ -1,29 +1,39 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
GNS3 Connector Factory Module
|
GNS3 Connector Factory Module
|
||||||
|
|
||||||
This module provides factory functions for creating Gns3Connector instances.
|
This module provides factory functions for creating Gns3Connector instances
|
||||||
It creates appropriately configured connectors using JWT token authentication.
|
with JWT token authentication and context-aware configuration management.
|
||||||
|
|
||||||
The URL resolution strategy follows a priority order:
|
Features:
|
||||||
1. Explicitly provided URL parameter
|
- Context variable based request-scoped data management (JWT tokens, LLM config)
|
||||||
2. Runtime configuration from Controller.instance().compute("local")
|
- Auto-detection of GNS3 server URL from Controller/Config
|
||||||
3. Static configuration from Config.instance().settings.Server
|
- Fallback URL strategy for flexible deployment
|
||||||
4. Fallback to localhost:3080
|
- LLM configuration retrieval for users
|
||||||
|
|
||||||
Main Functions:
|
This module is part of the GNS3-Copilot project.
|
||||||
get_gns3_connector: Create a Gns3Connector with JWT token
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
|
|
||||||
Example:
|
|
||||||
from gns3server.agent.gns3_copilot.gns3_client import get_gns3_connector
|
|
||||||
|
|
||||||
# Auto-detect URL from Controller or Config
|
|
||||||
connector = get_gns3_connector(jwt_token="your_token")
|
|
||||||
if connector:
|
|
||||||
# Use connector to interact with GNS3 server
|
|
||||||
projects = connector.projects
|
|
||||||
|
|
||||||
Authentication:
|
|
||||||
- JWT token based authentication
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
@ -1,14 +1,44 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Adapted gns3fy module for gns3-copilot.
|
Adapted gns3fy module for GNS3-Copilot
|
||||||
|
|
||||||
This module is based on the upstream gns3fy project (https://github.com/davidban77/gns3fy).
|
This module is based on the upstream gns3fy project (https://github.com/davidban77/gns3fy).
|
||||||
Modifications made for this repository:
|
|
||||||
- Adjusted some pydantic usages and dataclass configuration to reduce dependency conflicts
|
|
||||||
with langchain (pydantic version/api differences).
|
|
||||||
- Kept the original API surface where possible but simplified validators/config to improve compatibility.
|
|
||||||
- Please review any pydantic-specific code if upgrading langchain or pydantic in the future.
|
|
||||||
|
|
||||||
Note: This file is adapted - not the untouched upstream source. See repository README for details.
|
Modifications made for GNS3-Copilot:
|
||||||
|
- Adjusted pydantic usages and dataclass configuration to reduce dependency conflicts
|
||||||
|
with langchain (pydantic version/api differences)
|
||||||
|
- Kept the original API surface where possible but simplified validators/config
|
||||||
|
- Added JWT token authentication support
|
||||||
|
- Integrated with context-aware connector factory
|
||||||
|
|
||||||
|
Note: This file is adapted from upstream gns3fy for compatibility with
|
||||||
|
GNS3-Copilot's architecture.
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
|
|
||||||
|
Upstream: https://github.com/davidban77/gns3fy
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|||||||
@ -1,6 +1,34 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
GNS3 Project Info Tool
|
||||||
|
|
||||||
This module provides a LangChain BaseTool to retrieve basic information of a
|
This module provides a LangChain BaseTool to retrieve basic information of a
|
||||||
specific GNS3 project by project ID.
|
specific GNS3 project by project ID. Returns project name, status, node count,
|
||||||
|
and link count.
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
@ -1,6 +1,33 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
GNS3 Topology Reader Tool
|
||||||
|
|
||||||
This module provides a LangChain BaseTool to retrieve the topology of a
|
This module provides a LangChain BaseTool to retrieve the topology of a
|
||||||
specific GNS3 project by project ID.
|
specific GNS3 project by project ID. Returns nodes, links, and project metadata.
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
Project Agent Manager
|
Project Agent Manager
|
||||||
|
|
||||||
Manages AgentService instances for GNS3 projects using a singleton pattern.
|
Manages AgentService instances for GNS3 projects using a singleton pattern.
|
||||||
|
|||||||
@ -1,8 +1,33 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Prompts module for GNS3 Copilot.
|
Prompts Module for GNS3-Copilot
|
||||||
|
|
||||||
This package contains system prompts and prompt loading utilities for
|
This package contains system prompts and prompt loading utilities for
|
||||||
the GNS3 Copilot AI agent.
|
the GNS3-Copilot AI agent.
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .base_prompt import SYSTEM_PROMPT
|
from .base_prompt import SYSTEM_PROMPT
|
||||||
|
|||||||
@ -1,10 +1,35 @@
|
|||||||
"""
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
System prompt for GNS3 Network Lab Teaching Assistant
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
This module contains the system prompt used by the LangChain v1.0 agent
|
"""
|
||||||
|
System Prompt for GNS3 Network Lab Teaching Assistant
|
||||||
|
|
||||||
|
This module contains the system prompt used by the LangGraph agent
|
||||||
to guide network diagnostics and teaching activities.
|
to guide network diagnostics and teaching activities.
|
||||||
|
|
||||||
CRITICAL: This assistant has DIAGNOSIS permissions only, NO configuration permissions.
|
CRITICAL: This assistant has DIAGNOSIS permissions only, NO configuration permissions.
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# System prompt for LangChain v1.0 agent
|
# System prompt for LangChain v1.0 agent
|
||||||
|
|||||||
@ -1,7 +1,34 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Prompt loader for GNS3 Copilot.
|
Prompt Loader for GNS3-Copilot
|
||||||
|
|
||||||
This module provides utilities for loading system prompts.
|
This module provides utilities for loading system prompts.
|
||||||
|
Can be extended to support multiple prompt variants based on
|
||||||
|
environment variables (e.g., ENGLISH_LEVEL).
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -14,7 +41,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def load_system_prompt() -> str:
|
def load_system_prompt() -> str:
|
||||||
"""
|
"""
|
||||||
Load the system prompt for GNS3 Copilot.
|
Load the system prompt for GNS3-Copilot.
|
||||||
|
|
||||||
In the future, this can be extended to support multiple prompt variants
|
In the future, this can be extended to support multiple prompt variants
|
||||||
based on environment variables (e.g., ENGLISH_LEVEL).
|
based on environment variables (e.g., ENGLISH_LEVEL).
|
||||||
|
|||||||
@ -1,7 +1,33 @@
|
|||||||
"""
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
Prompt template for generating conversation titles.
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Title Generation Prompt for GNS3-Copilot
|
||||||
|
|
||||||
|
Prompt template for generating conversation titles.
|
||||||
Generates concise Chinese or English titles based on conversation language.
|
Generates concise Chinese or English titles based on conversation language.
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
TITLE_PROMPT = """
|
TITLE_PROMPT = """
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
GNS3-Copilot Tools Package
|
GNS3-Copilot Tools Package
|
||||||
|
|
||||||
This package provides various tools for interacting with GNS3 network simulator, including:
|
This package provides various tools for interacting with GNS3 network simulator, including:
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
This module provides a tool to execute configuration commands on multiple devices
|
This module provides a tool to execute configuration commands on multiple devices
|
||||||
in a GNS3 topology using Nornir.
|
in a GNS3 topology using Nornir.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
This module provides a tool to execute display commands on multiple devices
|
This module provides a tool to execute display commands on multiple devices
|
||||||
in a GNS3 topology using Nornir.
|
in a GNS3 topology using Nornir.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
GNS3 link creation tool for connecting network nodes.
|
GNS3 link creation tool for connecting network nodes.
|
||||||
|
|
||||||
Provides functionality to create links between nodes in GNS3 projects
|
Provides functionality to create links between nodes in GNS3 projects
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
GNS3 node creation tool for network topology building.
|
GNS3 node creation tool for network topology building.
|
||||||
|
|
||||||
Provides functionality to create multiple nodes in GNS3 projects
|
Provides functionality to create multiple nodes in GNS3 projects
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
GNS3 template retrieval tool for device discovery.
|
GNS3 template retrieval tool for device discovery.
|
||||||
|
|
||||||
Provides functionality to retrieve all available device templates
|
Provides functionality to retrieve all available device templates
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
GNS3 node startup tool for network device activation.
|
GNS3 node startup tool for network device activation.
|
||||||
|
|
||||||
Provides functionality to start one or multiple nodes in GNS3 projects
|
Provides functionality to start one or multiple nodes in GNS3 projects
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
GNS3 node name update tool for renaming network devices.
|
GNS3 node name update tool for renaming network devices.
|
||||||
|
|
||||||
Provides functionality to update the name of one or multiple nodes in GNS3 projects.
|
Provides functionality to update the name of one or multiple nodes in GNS3 projects.
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
Multi-device VPCS command execution tool using telnetlib3 with threading.
|
Multi-device VPCS command execution tool using telnetlib3 with threading.
|
||||||
Supports concurrent execution of multiple command groups across multiple VPCS devices.
|
Supports concurrent execution of multiple command groups across multiple VPCS devices.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
GNS3-Copilot Public Model Package
|
GNS3-Copilot Public Model Package
|
||||||
|
|
||||||
This package provides reusable public models and utilities for GNS3 network automation tasks.
|
This package provides reusable public models and utilities for GNS3 network automation tasks.
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
Public module for getting device port information from GNS3 topology
|
Public module for getting device port information from GNS3 topology
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
Drawing utility functions for GNS3 area annotations.
|
Drawing utility functions for GNS3 area annotations.
|
||||||
|
|
||||||
Calculates drawing parameters and generates SVG content for network area annotations.
|
Calculates drawing parameters and generates SVG content for network area annotations.
|
||||||
|
|||||||
@ -1,4 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
LLM Model Configuration Helper for GNS3 Copilot
|
LLM Model Configuration Helper for GNS3 Copilot
|
||||||
|
|
||||||
This module provides utility functions to retrieve LLM model configurations
|
This module provides utility functions to retrieve LLM model configurations
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
#
|
#
|
||||||
# This file is part of GNS3 Server.
|
# This file is part of GNS3 Server.
|
||||||
#
|
#
|
||||||
@ -16,6 +16,9 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
Message format converters for OpenAI-compatible message format.
|
Message format converters for OpenAI-compatible message format.
|
||||||
Converts between LangChain messages and OpenAI-compatible format.
|
Converts between LangChain messages and OpenAI-compatible format.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -1,3 +1,24 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# GNS3-Copilot - AI-powered Network Lab Assistant for GNS3
|
||||||
|
#
|
||||||
|
# This file is part of GNS3-Copilot project.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# GNS3-Copilot is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNS3-Copilot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Project Home: https://github.com/yueguobin/gns3-copilot
|
||||||
|
#
|
||||||
"""
|
"""
|
||||||
Public module for parsing tool execution results
|
Public module for parsing tool execution results
|
||||||
|
|
||||||
@ -39,6 +60,9 @@ Standard Tool Response Format:
|
|||||||
Author: Guobin Yue
|
Author: Guobin Yue
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
This module is part of the GNS3-Copilot project.
|
||||||
|
GitHub: https://github.com/yueguobin/gns3-copilot
|
||||||
|
|
||||||
import ast
|
import ast
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user