feat(openwebui-skills-manager): enhance auto-discovery and structural refactoring
- Enable default overwrite installation policy for overlapping skills - Support deep recursive GitHub trees discovery mechanism to resolve #58 - Refactor internal architecture to fully decouple stateless helper logic - READMEs and docs synced (v0.3.0)
This commit is contained in:
206
plugins/debug/byok-infinite-session-research/analysis.md
Normal file
206
plugins/debug/byok-infinite-session-research/analysis.md
Normal file
@@ -0,0 +1,206 @@
|
||||
# BYOK模式与Infinite Session(自动上下文压缩)兼容性研究
|
||||
|
||||
**日期**: 2026-03-08
|
||||
**研究范围**: Copilot SDK v0.1.30 + OpenWebUI Extensions Pipe v0.10.0
|
||||
|
||||
## 研究问题
|
||||
在BYOK (Bring Your Own Key) 模式下,是否应该支持自动上下文压缩(Infinite Sessions)?
|
||||
用户报告:BYOK模式本不应该触发压缩,但当模型名称与Copilot内置模型一致时,意外地支持了压缩。
|
||||
|
||||
---
|
||||
|
||||
## 核心发现
|
||||
|
||||
### 1. SDK层面(copilot-sdk/python/copilot/types.py)
|
||||
|
||||
**InfiniteSessionConfig 定义** (line 453-470):
|
||||
```python
|
||||
class InfiniteSessionConfig(TypedDict, total=False):
|
||||
"""
|
||||
Configuration for infinite sessions with automatic context compaction
|
||||
and workspace persistence.
|
||||
"""
|
||||
enabled: bool
|
||||
background_compaction_threshold: float # 0.0-1.0, default: 0.80
|
||||
buffer_exhaustion_threshold: float # 0.0-1.0, default: 0.95
|
||||
```
|
||||
|
||||
**SessionConfig结构** (line 475+):
|
||||
- `provider: ProviderConfig` - 用于BYOK配置
|
||||
- `infinite_sessions: InfiniteSessionConfig` - 上下文压缩配置
|
||||
- **关键**: 这两个配置是**完全独立的**,没有相互依赖关系
|
||||
|
||||
### 2. OpenWebUI Pipe层面(github_copilot_sdk.py)
|
||||
|
||||
**Infinite Session初始化** (line 5063-5069):
|
||||
```python
|
||||
infinite_session_config = None
|
||||
if self.valves.INFINITE_SESSION: # 默认值: True
|
||||
infinite_session_config = InfiniteSessionConfig(
|
||||
enabled=True,
|
||||
background_compaction_threshold=self.valves.COMPACTION_THRESHOLD,
|
||||
buffer_exhaustion_threshold=self.valves.BUFFER_THRESHOLD,
|
||||
)
|
||||
```
|
||||
|
||||
**关键问题**:
|
||||
- ✗ 没有任何条件检查 `is_byok_model`
|
||||
- ✗ 无论使用官方模型还是BYOK模型,都会应用相同的infinite session配置
|
||||
- ✓ 回对比,reasoning_effort被正确地在BYOK模式下禁用(line 6329-6331)
|
||||
|
||||
### 3. 模型识别逻辑(line 6199+)
|
||||
|
||||
```python
|
||||
if m_info and "source" in m_info:
|
||||
is_byok_model = m_info["source"] == "byok"
|
||||
else:
|
||||
is_byok_model = not has_multiplier and byok_active
|
||||
```
|
||||
|
||||
BYOK模型识别基于:
|
||||
1. 模型元数据中的 `source` 字段
|
||||
2. 或者根据是否有乘数标签 (如 "4x", "0.5x") 和globally active的BYOK配置
|
||||
|
||||
---
|
||||
|
||||
## 技术可行性分析
|
||||
|
||||
### ✅ Infinite Sessions在BYOK模式下是技术可行的:
|
||||
|
||||
1. **SDK支持**: Copilot SDK允许在任何provider (官方、BYOK、Azure等) 下使用infinite session配置
|
||||
2. **配置独立性**: provider和infinite_sessions配置在SessionConfig中是独立的字段
|
||||
3. **无文档限制**: SDK文档中没有说BYOK模式不支持infinite sessions
|
||||
4. **测试覆盖**: SDK虽然有单独的BYOK测试和infinite-sessions测试,但缺少组合测试
|
||||
|
||||
### ⚠️ 但存在以下设计问题:
|
||||
|
||||
#### 问题1: 意外的自动启用
|
||||
- BYOK模式通常用于**精确控制**自己的API使用
|
||||
- 自动压缩可能会导致**意外的额外请求**和API成本增加
|
||||
- 没有明确的警告或文档说明BYOK也会压缩
|
||||
|
||||
#### 问题2: 没有模式特定的配置
|
||||
```python
|
||||
# 当前实现 - 一刀切
|
||||
if self.valves.INFINITE_SESSION:
|
||||
# 同时应用于官方模型和BYOK模型
|
||||
|
||||
# 应该是 - 模式感知
|
||||
if self.valves.INFINITE_SESSION and not is_byok_model:
|
||||
# 仅对官方模型启用
|
||||
# 或者
|
||||
if self.valves.INFINITE_SESSION_BYOK and is_byok_model:
|
||||
# BYOK专用配置
|
||||
```
|
||||
|
||||
#### 问题3: 压缩质量不确定性
|
||||
- BYOK模型可能是自部署的或开源模型
|
||||
- 上下文压缩由Copilot CLI处理,质量取决于CLI版本
|
||||
- 没有标准化的压缩效果评估
|
||||
|
||||
---
|
||||
|
||||
## 用户报告现象的根本原因
|
||||
|
||||
用户说:"BYOK模式本不应该触发压缩,但碰巧用的模型名称与Copilot内置模型相同,结果意外触发了压缩"
|
||||
|
||||
**分析**:
|
||||
1. OpenWebUI Pipe中,infinite_session配置是**全局启用**的 (INFINITE_SESSION=True)
|
||||
2. 模型识别逻辑中,如果模型元数据丢失,会根据模型名称和BYOK活跃状态来推断
|
||||
3. 如果用户使用的BYOK模型名称恰好是 "gpt-4", "claude-3-5-sonnet" 等,可能被识别错误
|
||||
4. 或者用户根本没意识到infinite session在BYOK模式下也被启用了
|
||||
|
||||
---
|
||||
|
||||
## 建议方案
|
||||
|
||||
### 方案1: 保守方案(推荐)
|
||||
**禁用BYOK模式下的automatic compression**
|
||||
|
||||
```python
|
||||
infinite_session_config = None
|
||||
# 只对标准官方模型启用,不对BYOK启用
|
||||
if self.valves.INFINITE_SESSION and not is_byok_model:
|
||||
infinite_session_config = InfiniteSessionConfig(
|
||||
enabled=True,
|
||||
background_compaction_threshold=self.valves.COMPACTION_THRESHOLD,
|
||||
buffer_exhaustion_threshold=self.valves.BUFFER_THRESHOLD,
|
||||
)
|
||||
```
|
||||
|
||||
**优点**:
|
||||
- 尊重BYOK用户的成本控制意愿
|
||||
- 降低意外API使用风险
|
||||
- 与reasoning_effort的BYOK禁用保持一致
|
||||
|
||||
**缺点**: 限制了BYOK用户的功能
|
||||
|
||||
### 方案2: 灵活方案
|
||||
**添加独立的BYOK compression配置**
|
||||
|
||||
```python
|
||||
class Valves(BaseModel):
|
||||
INFINITE_SESSION: bool = Field(
|
||||
default=True,
|
||||
description="Enable Infinite Sessions for standard Copilot models"
|
||||
)
|
||||
INFINITE_SESSION_BYOK: bool = Field(
|
||||
default=False,
|
||||
description="Enable Infinite Sessions for BYOK models (advanced users only)"
|
||||
)
|
||||
|
||||
# 使用逻辑
|
||||
if (self.valves.INFINITE_SESSION and not is_byok_model) or \
|
||||
(self.valves.INFINITE_SESSION_BYOK and is_byok_model):
|
||||
infinite_session_config = InfiniteSessionConfig(...)
|
||||
```
|
||||
|
||||
**优点**:
|
||||
- 给BYOK用户完全控制
|
||||
- 保持向后兼容性
|
||||
- 允许高级用户启用
|
||||
|
||||
**缺点**: 增加配置复杂度
|
||||
|
||||
### 方案3: 警告+ 文档
|
||||
**保持当前实现,但添加文档说明**
|
||||
|
||||
- 在README中明确说明infinite session对所有provider类型都启用
|
||||
- 添加Valve描述提示: "Applies to both standard Copilot and BYOK models"
|
||||
- 在BYOK配置部分明确提到压缩成本
|
||||
|
||||
**优点**: 减少实现负担,给用户知情权
|
||||
|
||||
**缺点**: 对已经启用的用户无帮助
|
||||
|
||||
---
|
||||
|
||||
## 推荐实施
|
||||
|
||||
**优先级**: 高
|
||||
**建议实施方案**: **方案1 (保守方案)** 或 **方案2 (灵活方案)**
|
||||
|
||||
如果选择方案1: 修改line 5063处的条件判断
|
||||
如果选择方案2: 添加INFINITE_SESSION_BYOK配置 + 修改初始化逻辑
|
||||
|
||||
---
|
||||
|
||||
## 相关代码位置
|
||||
|
||||
| 文件 | 行号 | 说明 |
|
||||
|-----|------|------|
|
||||
| `github_copilot_sdk.py` | 364-366 | INFINITE_SESSION Valve定义 |
|
||||
| `github_copilot_sdk.py` | 5063-5069 | Infinite session初始化 |
|
||||
| `github_copilot_sdk.py` | 6199-6220 | is_byok_model判断逻辑 |
|
||||
| `github_copilot_sdk.py` | 6329-6331 | reasoning_effort BYOK处理(参考) |
|
||||
|
||||
---
|
||||
|
||||
## 结论
|
||||
|
||||
**BYOK模式与Infinite Sessions的兼容性**:
|
||||
- ✅ 技术上完全可行
|
||||
- ⚠️ 但存在设计意图不清的问题
|
||||
- ✗ 当前实现对BYOK用户可能不友好
|
||||
|
||||
**推荐**: 实施方案1或2之一,增加BYOK模式的控制粒度。
|
||||
Reference in New Issue
Block a user