diff --git a/docs/gns3-copilot/context-window-management.md b/docs/gns3-copilot/context-window-management.md
index 69f5a8c7a..1453582e5 100644
--- a/docs/gns3-copilot/context-window-management.md
+++ b/docs/gns3-copilot/context-window-management.md
@@ -257,17 +257,22 @@ pip install tiktoken>=0.8.0
发送给 LLM 的完整请求:
┌─────────────────────────────────────────────────────────────┐
│ 1. Messages (我们管理的) │
-│ ├─ SystemMessage: system prompt │
-│ ├─ SystemMessage: topology info │
-│ └─ HumanMessage: 用户消息 / 历史消息 │
+│ ├─ SystemMessage: system prompt + topology (模板注入) │
+│ └─ HumanMessage/AIMessage: 用户消息 / 历史消息 │
├─────────────────────────────────────────────────────────────┤
│ 2. Tool Definitions (LangChain 自动添加,不在消息中) │
│ ├─ Tool 1 schema (name, description, parameters) │
│ ├─ 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 裁剪流程
```
@@ -287,14 +292,14 @@ pip install tiktoken>=0.8.0
│ 可用于消息 = 9,600 - 1,862 = 7,738 tokens │
└─────────────────────────────────────────────────────────────┘
↓
-第三步:分离系统消息和对话历史
+第三步:计算 System Message token(已合并)
┌─────────────────────────────────────────────────────────────┐
│ 可用于消息: 7,738 tokens │
│ │
-│ System Messages (保留): │
-│ - System prompt: ~1,000 tokens │
+│ System Message (已包含 system + topology): │
+│ - System prompt (base): ~1,000 tokens │
│ - Topology info: ~3,000 tokens │
-│ = 4,000 tokens │
+│ = 4,000 tokens (合并后) │
│ │
│ 可用于历史 = 7,738 - 4,000 = 3,738 tokens │
└─────────────────────────────────────────────────────────────┘
@@ -313,19 +318,25 @@ pip install tiktoken>=0.8.0
| 优先级 | 内容 | 说明 |
|--------|------|------|
-| 1️⃣ | System Prompt | 永远保留(第1个) |
-| 2️⃣ | Topology Info | 永远保留(第2个) |
-| 3️⃣ | 最新用户消息 | 至少保留最后1条 |
-| 4️⃣ | 旧对话历史 | 按时间顺序丢弃 |
+| 1️⃣ | System Message (system prompt + topology) | 永远保留 |
+| 2️⃣ | 最新用户消息 | 至少保留最后1条 |
+| 3️⃣ | 旧对话历史 | 按时间顺序丢弃 |
+
+**注意**:System prompt 和 topology info 通过模板变量合并为一个 SystemMessage,无法单独分离。
#### 2.4 边界情况处理
| 情况 | 处理方式 |
|------|----------|
-| System > 预算 | 只保留 system prompt,丢弃所有其他消息 |
-| Tools > 预算 | 警告日志,建议增加 context_limit |
+| System (包含 topology) > 预算 | 保留完整的 System Message(无法分离 system 和 topology) |
+| Tools > 预算 | 警告日志,建议增加 context_limit 或减少工具数量 |
| 历史全被裁剪 | 保留最后1条用户消息 |
+**重要提示**:
+- 当 system + topology 超出可用预算时,**两者都会被保留**
+- 无法只丢弃 topology 而保留 system prompt(因为已合并)
+- 建议在 system prompt 中精简 topology 信息或使用更短的 system prompt
+
### 2. 集成到 GNS3 Copilot
**修改文件**: `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
-from langchain_core.messages.utils import trim_messages
-
-trimmed = trim_messages(
- messages,
- strategy="last", # 保留最近的 N 条消息
- max_tokens=10000, # 最大 token 数
- token_counter=count_tokens_approximately, # Token 计数器
- preserve_system=True, # 保留系统消息
- start_on="human", # 确保从人类消息开始
- end_on=("human", "tool", "ai"), # 在特定类型消息结束
-)
+def estimate_tool_tokens(tools: list[Any]) -> int:
+ """动态序列化工具 schema 并计算 token"""
+ for tool in tools:
+ tool_schema = {
+ "type": "function",
+ "function": {
+ "name": tool.name,
+ "description": tool.description,
+ "parameters": tool.args_schema.schema()
+ }
+ }
+ # 使用 tiktoken 计数
+ schema_str = json.dumps(tool_schema, ensure_ascii=False)
+ tool_tokens = len(encoding.encode(schema_str))
```
-#### `count_tokens_approximately`
-
-- 快速估算消息的 token 数量
-- 不需要调用 LLM API
-- 用于判断是否需要裁剪
+**典型消耗**:
+- 简单工具(1-2 个参数):500-800 tokens
+- 中等工具(3-5 个参数):800-1200 tokens
+- 复杂工具(嵌套参数):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)
-- **消息 tokens**: 对话历史 + system prompt + topology context 的 token 数
-- **工具 tokens**: 工具定义(schema)的 token 数
-- **总计 tokens**: 消息 tokens + 工具 tokens
-- **限制**: 模型的上下文窗口大小(K tokens)
-- **使用百分比**: 总计 tokens / 限制 × 100%
-- **策略**: 使用的裁剪策略(conservative/balanced/aggressive)
+- **system**:System Message 的总 token 数(包含 system prompt + topology)
+- **base**:基础 system prompt 的 token 数(不含 topology)
+- **topology**:Topology info 的 token 数
+- **history**:对话历史(HumanMessage + AIMessage + ToolMessage)的 token 数
+- **tools**:工具定义(schema)的 token 数
+- **总计**:所有部分的 token 总和
+- **限制**:模型的上下文窗口大小(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. ✅ 智能裁剪消息历史,避免超限
2. ✅ **必须手动配置 context_limit**,确保使用正确的上下文窗口大小
3. ✅ 可配置的裁剪策略(保守/平衡/激进)
-4. ✅ 始终保留系统消息和拓扑信息
+4. ✅ 始终保留系统消息(包含 system prompt 和 topology)
5. ✅ 详细的日志输出,便于调试
6. ✅ 优雅的错误处理和明确的错误提示
7. ✅ 提供参考工具,帮助查找常见模型的上下文限制
8. ✅ **使用 tiktoken 进行准确的 token 计数**(准确率 95%+)
9. ✅ **自动估算工具定义的 token 消耗**
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
- 显示使用百分比和策略选择
这个实现确保了即使在进行长对话时,系统也不会因为上下文溢出而失败。
diff --git a/gns3server/agent/gns3_copilot/__init__.py b/gns3server/agent/gns3_copilot/__init__.py
index ae4b67126..ed68f154e 100644
--- a/gns3server/agent/gns3_copilot/__init__.py
+++ b/gns3server/agent/gns3_copilot/__init__.py
@@ -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 .
+#
+# 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.
This package provides a command-line interface for launching the GNS3-Copilot
diff --git a/gns3server/agent/gns3_copilot/agent/__init__.py b/gns3server/agent/gns3_copilot/agent/__init__.py
index 87bcccea3..3657e4208 100644
--- a/gns3server/agent/gns3_copilot/agent/__init__.py
+++ b/gns3server/agent/gns3_copilot/agent/__init__.py
@@ -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 .
+#
+# Project Home: https://github.com/yueguobin/gns3-copilot
+#
+
"""
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
diff --git a/gns3server/agent/gns3_copilot/agent/context_manager.py b/gns3server/agent/gns3_copilot/agent/context_manager.py
index e1261457f..a6f0c0349 100644
--- a/gns3server/agent/gns3_copilot/agent/context_manager.py
+++ b/gns3server/agent/gns3_copilot/agent/context_manager.py
@@ -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 .
+#
+# 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
-This module provides context window management for different LLM models,
+This module provides intelligent context window management for LLM models,
including:
- Model-specific context window limits
-- Token counting for messages
-- Message trimming strategies
+- Accurate token counting using tiktoken
+- Message trimming strategies (conservative/balanced/aggressive)
- 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
@@ -26,11 +46,24 @@ from langchain_core.messages import (
SystemMessage,
ToolMessage,
)
-from langchain_core.messages.utils import trim_messages
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
# ============================================================================
@@ -176,6 +209,10 @@ def estimate_tool_tokens(tools: list[Any]) -> int:
return total_tokens
+# ============================================================================
+# Model Context Limits
+# ============================================================================
+
# NOTE: Built-in model context limits have been removed.
# Model providers frequently update context limits, and maintaining this list is not sustainable.
# Users MUST configure context_limit explicitly in their LLM model configurations.
@@ -243,7 +280,7 @@ def get_model_context_limit(
def calculate_max_tokens(
model_limit: int,
- strategy: Literal["conservative", "balanced", "aggressive"] = "balanced"
+ strategy: Literal["conservative", "balanced", "aggressive"] = DEFAULT_CONTEXT_STRATEGY
) -> int:
"""
Calculate the maximum tokens to use, reserving space for output.
@@ -258,13 +295,7 @@ def calculate_max_tokens(
Returns:
int: Maximum tokens for input messages
"""
- ratios = {
- "conservative": 0.60,
- "balanced": 0.75,
- "aggressive": 0.85,
- }
-
- ratio = ratios.get(strategy, 0.75)
+ ratio = CONTEXT_STRATEGY_RATIOS.get(strategy, CONTEXT_STRATEGY_RATIOS[DEFAULT_CONTEXT_STRATEGY])
max_tokens = int(model_limit * ratio)
logger.debug(
@@ -275,11 +306,15 @@ def calculate_max_tokens(
return max_tokens
+# ============================================================================
+# Message Trimming
+# ============================================================================
+
def trim_messages_for_context(
messages: list[Any],
model_name: str,
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,
tool_tokens: int = 0,
) -> list[Any]:
@@ -313,7 +348,7 @@ def trim_messages_for_context(
if not 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)
# 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
+# ============================================================================
+# Token Usage Summary
+# ============================================================================
+
def get_token_usage_summary(
messages: list[Any],
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(
state_messages: list[Any],
system_prompt: str,
@@ -479,11 +521,17 @@ def prepare_context_messages(
Prepare full context messages for LLM call with automatic trimming.
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:
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
model_name: Name of the LLM model
llm_config: Optional LLM config dict from database (may contain context_limit and context_strategy)
@@ -495,51 +543,50 @@ def prepare_context_messages(
Examples:
>>> messages = prepare_context_messages(
... 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,
... model_name="gpt-4o"
... )
>>> len(messages)
2 # System message + Human message
"""
- # Get trimming strategy from config (default: "balanced")
- trim_strategy = "balanced"
+ # Step 1: Get trimming strategy from config
+ trim_strategy = DEFAULT_CONTEXT_STRATEGY
if llm_config and "context_strategy" in llm_config:
strategy = llm_config["context_strategy"]
- if strategy in ["conservative", "balanced", "aggressive"]:
+ if strategy in CONTEXT_STRATEGY_RATIOS:
trim_strategy = strategy
logger.debug("Using context_strategy from config: %s", trim_strategy)
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
- # 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
if topology_context:
topology_formatted = f"Current Topology:\n{topology_context}"
formatted_prompt = system_prompt.replace("{{topology_info}}", topology_formatted)
else:
- # If no topology, remove the placeholder
+ # If no topology, use placeholder
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)
topology_tokens = count_tokens_accurately(topology_formatted) if topology_context else 0
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)]
- # Calculate conversation history tokens
+ # Step 6: Calculate conversation history tokens
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
- # Trim if needed
+ # Step 8: Trim if needed
trimmed_messages = trim_messages_for_context(
full_messages,
model_name=model_name,
@@ -549,11 +596,10 @@ def prepare_context_messages(
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_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
if trimmed_history_tokens < history_tokens:
@@ -589,16 +635,26 @@ def prepare_context_messages(
return trimmed_messages
+# ============================================================================
+# Module Test
+# ============================================================================
+
if __name__ == "__main__":
# Simple test
test_messages = [
HumanMessage(f"Message {i}") for i in range(100)
]
- result = trim_messages_for_context(
- test_messages,
+ # Test with mock llm_config
+ 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",
- strategy="balanced"
+ llm_config=mock_config,
+ tools=None
)
print(f"Original: {len(test_messages)} messages")
diff --git a/gns3server/agent/gns3_copilot/agent/gns3_copilot.py b/gns3server/agent/gns3_copilot/agent/gns3_copilot.py
index 7ad55e63c..7a08fcbc1 100644
--- a/gns3server/agent/gns3_copilot/agent/gns3_copilot.py
+++ b/gns3server/agent/gns3_copilot/agent/gns3_copilot.py
@@ -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
-# 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
# 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 Affero General Public License
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
-# You should have received a copy of the GNU Affero General Public License along
-# with GNS3-Copilot. If not, see .
+# You should have received a copy of the GNU General Public License
+# along with GNS3-Copilot. If not, see .
+#
+# Project Home: https://github.com/yueguobin/gns3-copilot
+#
# 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.
-It uses LangChain for agent orchestration and DeepSeek LLM for natural language processing.
-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
+This module implements the core LangGraph agent workflow for GNS3-Copilot,
+an AI-powered assistant for GNS3 network automation and management.
-The assistant integrates with various tools to provide a complete network automation
-solution for GNS3 environments.
+The agent provides:
+- 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
diff --git a/gns3server/agent/gns3_copilot/agent/model_factory.py b/gns3server/agent/gns3_copilot/agent/model_factory.py
index 030800fd0..58a1fae4a 100644
--- a/gns3server/agent/gns3_copilot/agent/model_factory.py
+++ b/gns3server/agent/gns3_copilot/agent/model_factory.py
@@ -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 .
+#
+# Project Home: https://github.com/yueguobin/gns3-copilot
+#
+
"""
Model Factory for GNS3-Copilot Agent
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
diff --git a/gns3server/agent/gns3_copilot/agent_service.py b/gns3server/agent/gns3_copilot/agent_service.py
index 70fc166e3..44607d821 100644
--- a/gns3server/agent/gns3_copilot/agent_service.py
+++ b/gns3server/agent/gns3_copilot/agent_service.py
@@ -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 .
+#
+# 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
Provides project-level Agent instances with SQLite checkpoint management.
diff --git a/gns3server/agent/gns3_copilot/chat_sessions_repository.py b/gns3server/agent/gns3_copilot/chat_sessions_repository.py
index fde214f35..da1952aef 100644
--- a/gns3server/agent/gns3_copilot/chat_sessions_repository.py
+++ b/gns3server/agent/gns3_copilot/chat_sessions_repository.py
@@ -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 .
+#
+# 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.
Provides CRUD operations for the chat_sessions table in the project's
diff --git a/gns3server/agent/gns3_copilot/gns3_client/__init__.py b/gns3server/agent/gns3_copilot/gns3_client/__init__.py
index 246940e56..4ef9e02bb 100644
--- a/gns3server/agent/gns3_copilot/gns3_client/__init__.py
+++ b/gns3server/agent/gns3_copilot/gns3_client/__init__.py
@@ -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 .
+#
+# Project Home: https://github.com/yueguobin/gns3-copilot
+#
+
"""
GNS3 Client Package
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.
Main classes:
@@ -11,13 +33,18 @@ Main classes:
- Node: GNS3 Node management
- Link: GNS3 Link management
- GNS3TopologyTool: GNS3 topology reading tool
-- GNS3UpdateDrawingTool: GNS3 drawing update tool
+- GNS3ProjectInfoTool: GNS3 project info tool
Main functions:
-- get_gns3_connector: Factory function to create Gns3Connector from environment
-- get_gns3_connector_with_llm_config: Factory function to create connector AND retrieve LLM config
+- get_gns3_connector: Factory function to create Gns3Connector
+- 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_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 (
diff --git a/gns3server/agent/gns3_copilot/gns3_client/connector_factory.py b/gns3server/agent/gns3_copilot/gns3_client/connector_factory.py
index 7edf136aa..f36507275 100644
--- a/gns3server/agent/gns3_copilot/gns3_client/connector_factory.py
+++ b/gns3server/agent/gns3_copilot/gns3_client/connector_factory.py
@@ -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 .
+#
+# Project Home: https://github.com/yueguobin/gns3-copilot
+#
+
"""
GNS3 Connector Factory Module
-This module provides factory functions for creating Gns3Connector instances.
-It creates appropriately configured connectors using JWT token authentication.
+This module provides factory functions for creating Gns3Connector instances
+with JWT token authentication and context-aware configuration management.
-The URL resolution strategy follows a priority order:
-1. Explicitly provided URL parameter
-2. Runtime configuration from Controller.instance().compute("local")
-3. Static configuration from Config.instance().settings.Server
-4. Fallback to localhost:3080
+Features:
+- Context variable based request-scoped data management (JWT tokens, LLM config)
+- Auto-detection of GNS3 server URL from Controller/Config
+- Fallback URL strategy for flexible deployment
+- LLM configuration retrieval for users
-Main Functions:
- get_gns3_connector: Create a Gns3Connector with JWT token
-
-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
+This module is part of the GNS3-Copilot project.
+GitHub: https://github.com/yueguobin/gns3-copilot
"""
import logging
diff --git a/gns3server/agent/gns3_copilot/gns3_client/custom_gns3fy.py b/gns3server/agent/gns3_copilot/gns3_client/custom_gns3fy.py
index 2ac90b5c3..7c372ef3c 100644
--- a/gns3server/agent/gns3_copilot/gns3_client/custom_gns3fy.py
+++ b/gns3server/agent/gns3_copilot/gns3_client/custom_gns3fy.py
@@ -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 .
+#
+# 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).
-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
diff --git a/gns3server/agent/gns3_copilot/gns3_client/gns3_project_info.py b/gns3server/agent/gns3_copilot/gns3_client/gns3_project_info.py
index e59f7460e..d431608c9 100644
--- a/gns3server/agent/gns3_copilot/gns3_client/gns3_project_info.py
+++ b/gns3server/agent/gns3_copilot/gns3_client/gns3_project_info.py
@@ -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 .
+#
+# Project Home: https://github.com/yueguobin/gns3-copilot
+#
+
"""
+GNS3 Project Info Tool
+
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
diff --git a/gns3server/agent/gns3_copilot/gns3_client/gns3_topology_reader.py b/gns3server/agent/gns3_copilot/gns3_client/gns3_topology_reader.py
index 7d962775b..b2ac98caf 100644
--- a/gns3server/agent/gns3_copilot/gns3_client/gns3_topology_reader.py
+++ b/gns3server/agent/gns3_copilot/gns3_client/gns3_topology_reader.py
@@ -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 .
+#
+# Project Home: https://github.com/yueguobin/gns3-copilot
+#
+
"""
+GNS3 Topology Reader Tool
+
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
diff --git a/gns3server/agent/gns3_copilot/project_agent_manager.py b/gns3server/agent/gns3_copilot/project_agent_manager.py
index cc71ea87b..9320e5019 100644
--- a/gns3server/agent/gns3_copilot/project_agent_manager.py
+++ b/gns3server/agent/gns3_copilot/project_agent_manager.py
@@ -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 .
+#
+# 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
Manages AgentService instances for GNS3 projects using a singleton pattern.
diff --git a/gns3server/agent/gns3_copilot/prompts/__init__.py b/gns3server/agent/gns3_copilot/prompts/__init__.py
index 1ebcb4f54..91f1985ae 100644
--- a/gns3server/agent/gns3_copilot/prompts/__init__.py
+++ b/gns3server/agent/gns3_copilot/prompts/__init__.py
@@ -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 .
+#
+# 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
-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
diff --git a/gns3server/agent/gns3_copilot/prompts/base_prompt.py b/gns3server/agent/gns3_copilot/prompts/base_prompt.py
index 1ed2ab840..3dd30b9b7 100644
--- a/gns3server/agent/gns3_copilot/prompts/base_prompt.py
+++ b/gns3server/agent/gns3_copilot/prompts/base_prompt.py
@@ -1,10 +1,35 @@
-"""
-System prompt for GNS3 Network Lab Teaching Assistant
+# 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 .
+#
+# 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.
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
diff --git a/gns3server/agent/gns3_copilot/prompts/prompt_loader.py b/gns3server/agent/gns3_copilot/prompts/prompt_loader.py
index a9f1f7ef7..d725ebdee 100644
--- a/gns3server/agent/gns3_copilot/prompts/prompt_loader.py
+++ b/gns3server/agent/gns3_copilot/prompts/prompt_loader.py
@@ -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 .
+#
+# 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.
+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
@@ -14,7 +41,7 @@ logger = logging.getLogger(__name__)
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
based on environment variables (e.g., ENGLISH_LEVEL).
diff --git a/gns3server/agent/gns3_copilot/prompts/title_prompt.py b/gns3server/agent/gns3_copilot/prompts/title_prompt.py
index 7416416ee..90b6ebb23 100644
--- a/gns3server/agent/gns3_copilot/prompts/title_prompt.py
+++ b/gns3server/agent/gns3_copilot/prompts/title_prompt.py
@@ -1,7 +1,33 @@
-"""
-Prompt template for generating conversation titles.
+# 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 .
+#
+# 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.
+
+This module is part of the GNS3-Copilot project.
+GitHub: https://github.com/yueguobin/gns3-copilot
"""
TITLE_PROMPT = """
diff --git a/gns3server/agent/gns3_copilot/tools_v2/__init__.py b/gns3server/agent/gns3_copilot/tools_v2/__init__.py
index bf8a655fd..0e0812a2d 100644
--- a/gns3server/agent/gns3_copilot/tools_v2/__init__.py
+++ b/gns3server/agent/gns3_copilot/tools_v2/__init__.py
@@ -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 .
+#
+# 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
This package provides various tools for interacting with GNS3 network simulator, including:
diff --git a/gns3server/agent/gns3_copilot/tools_v2/config_tools_nornir.py b/gns3server/agent/gns3_copilot/tools_v2/config_tools_nornir.py
index f4e5df1d0..daa4d0ce0 100644
--- a/gns3server/agent/gns3_copilot/tools_v2/config_tools_nornir.py
+++ b/gns3server/agent/gns3_copilot/tools_v2/config_tools_nornir.py
@@ -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 .
+#
+# 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
in a GNS3 topology using Nornir.
"""
diff --git a/gns3server/agent/gns3_copilot/tools_v2/display_tools_nornir.py b/gns3server/agent/gns3_copilot/tools_v2/display_tools_nornir.py
index 13b805814..131cfb015 100644
--- a/gns3server/agent/gns3_copilot/tools_v2/display_tools_nornir.py
+++ b/gns3server/agent/gns3_copilot/tools_v2/display_tools_nornir.py
@@ -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 .
+#
+# 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
in a GNS3 topology using Nornir.
"""
diff --git a/gns3server/agent/gns3_copilot/tools_v2/gns3_create_link.py b/gns3server/agent/gns3_copilot/tools_v2/gns3_create_link.py
index 556e9efd9..fb1b3d635 100644
--- a/gns3server/agent/gns3_copilot/tools_v2/gns3_create_link.py
+++ b/gns3server/agent/gns3_copilot/tools_v2/gns3_create_link.py
@@ -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 .
+#
+# 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.
Provides functionality to create links between nodes in GNS3 projects
diff --git a/gns3server/agent/gns3_copilot/tools_v2/gns3_create_node.py b/gns3server/agent/gns3_copilot/tools_v2/gns3_create_node.py
index 82b9a35d6..b451721fd 100644
--- a/gns3server/agent/gns3_copilot/tools_v2/gns3_create_node.py
+++ b/gns3server/agent/gns3_copilot/tools_v2/gns3_create_node.py
@@ -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 .
+#
+# 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.
Provides functionality to create multiple nodes in GNS3 projects
diff --git a/gns3server/agent/gns3_copilot/tools_v2/gns3_get_node_temp.py b/gns3server/agent/gns3_copilot/tools_v2/gns3_get_node_temp.py
index 88bf62862..2cb932b46 100644
--- a/gns3server/agent/gns3_copilot/tools_v2/gns3_get_node_temp.py
+++ b/gns3server/agent/gns3_copilot/tools_v2/gns3_get_node_temp.py
@@ -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 .
+#
+# 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.
Provides functionality to retrieve all available device templates
diff --git a/gns3server/agent/gns3_copilot/tools_v2/gns3_start_node.py b/gns3server/agent/gns3_copilot/tools_v2/gns3_start_node.py
index f07846cf6..0907b9bb3 100644
--- a/gns3server/agent/gns3_copilot/tools_v2/gns3_start_node.py
+++ b/gns3server/agent/gns3_copilot/tools_v2/gns3_start_node.py
@@ -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 .
+#
+# 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.
Provides functionality to start one or multiple nodes in GNS3 projects
diff --git a/gns3server/agent/gns3_copilot/tools_v2/gns3_update_node_name.py b/gns3server/agent/gns3_copilot/tools_v2/gns3_update_node_name.py
index 983ef5f51..614d3e348 100644
--- a/gns3server/agent/gns3_copilot/tools_v2/gns3_update_node_name.py
+++ b/gns3server/agent/gns3_copilot/tools_v2/gns3_update_node_name.py
@@ -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 .
+#
+# 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.
Provides functionality to update the name of one or multiple nodes in GNS3 projects.
diff --git a/gns3server/agent/gns3_copilot/tools_v2/vpcs_tools_telnetlib3.py b/gns3server/agent/gns3_copilot/tools_v2/vpcs_tools_telnetlib3.py
index 27b86ab52..4e5c8e80e 100644
--- a/gns3server/agent/gns3_copilot/tools_v2/vpcs_tools_telnetlib3.py
+++ b/gns3server/agent/gns3_copilot/tools_v2/vpcs_tools_telnetlib3.py
@@ -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 .
+#
+# 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.
Supports concurrent execution of multiple command groups across multiple VPCS devices.
"""
diff --git a/gns3server/agent/gns3_copilot/utils/__init__.py b/gns3server/agent/gns3_copilot/utils/__init__.py
index 8646724fd..e9d2a091c 100644
--- a/gns3server/agent/gns3_copilot/utils/__init__.py
+++ b/gns3server/agent/gns3_copilot/utils/__init__.py
@@ -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 .
+#
+# 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
This package provides reusable public models and utilities for GNS3 network automation tasks.
diff --git a/gns3server/agent/gns3_copilot/utils/get_gns3_device_port.py b/gns3server/agent/gns3_copilot/utils/get_gns3_device_port.py
index 368b9d7bd..90d554318 100644
--- a/gns3server/agent/gns3_copilot/utils/get_gns3_device_port.py
+++ b/gns3server/agent/gns3_copilot/utils/get_gns3_device_port.py
@@ -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 .
+#
+# 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
"""
diff --git a/gns3server/agent/gns3_copilot/utils/gns3_drawing_utils.py b/gns3server/agent/gns3_copilot/utils/gns3_drawing_utils.py
index 79e738c24..17bbf99cf 100644
--- a/gns3server/agent/gns3_copilot/utils/gns3_drawing_utils.py
+++ b/gns3server/agent/gns3_copilot/utils/gns3_drawing_utils.py
@@ -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 .
+#
+# 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.
Calculates drawing parameters and generates SVG content for network area annotations.
diff --git a/gns3server/agent/gns3_copilot/utils/llm_config_helper.py b/gns3server/agent/gns3_copilot/utils/llm_config_helper.py
index 8db2f07e7..7d0124868 100644
--- a/gns3server/agent/gns3_copilot/utils/llm_config_helper.py
+++ b/gns3server/agent/gns3_copilot/utils/llm_config_helper.py
@@ -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 .
+#
+# 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
This module provides utility functions to retrieve LLM model configurations
diff --git a/gns3server/agent/gns3_copilot/utils/message_converters.py b/gns3server/agent/gns3_copilot/utils/message_converters.py
index dffc6dce2..dd9894c13 100644
--- a/gns3server/agent/gns3_copilot/utils/message_converters.py
+++ b/gns3server/agent/gns3_copilot/utils/message_converters.py
@@ -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.
#
@@ -16,6 +16,9 @@
# along with this program. If not, see .
"""
+
+This module is part of the GNS3-Copilot project.
+GitHub: https://github.com/yueguobin/gns3-copilot
Message format converters for OpenAI-compatible message format.
Converts between LangChain messages and OpenAI-compatible format.
"""
diff --git a/gns3server/agent/gns3_copilot/utils/parse_tool_content.py b/gns3server/agent/gns3_copilot/utils/parse_tool_content.py
index e8374d08d..5898df9e4 100644
--- a/gns3server/agent/gns3_copilot/utils/parse_tool_content.py
+++ b/gns3server/agent/gns3_copilot/utils/parse_tool_content.py
@@ -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 .
+#
+# Project Home: https://github.com/yueguobin/gns3-copilot
+#
"""
Public module for parsing tool execution results
@@ -39,6 +60,9 @@ Standard Tool Response Format:
Author: Guobin Yue
"""
+This module is part of the GNS3-Copilot project.
+GitHub: https://github.com/yueguobin/gns3-copilot
+
import ast
import json
import logging