Skip to content

Commit b6eca06

Browse files
author
beautistart
committed
feat: align dynamic attention and task execution flow
1 parent 91b7465 commit b6eca06

40 files changed

Lines changed: 6207 additions & 4996 deletions

audit/reports/llm_attention_selection_implementation.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@
4949
| 配置项 | 默认值 | 说明 |
5050
|--------|--------|------|
5151
| enabled | True | 功能开关 |
52-
| pressure_threshold_high | 0.9 | 高压阈值 |
53-
| pressure_threshold_medium | 0.75 | 中压阈值 |
52+
| threshold_budget_ratio | 0.5 | 阈值预算=LLM原始上下文窗口的50% |
53+
| pressure_threshold_high | 1.0 | RED触发线:上下文压力 >100% |
54+
| pressure_threshold_medium | 0.9 | YELLOW触发线:上下文压力 >90% |
5455
| cooldown_base_seconds | 30.0 | 基础冷却时间 |
5556
| fallback_mode | FOCUS | Fallback模式 |
56-
| decision_timeout_ms | 500 | 决策超时 |
57+
| decision_timeout_ms | None | 无限等待LLM完成注意力选择 |
5758
| oscillation_detection_window | 10 | 震荡检测窗口 |
5859

5960
**核心方法**:
@@ -244,7 +245,7 @@ async def _try_llm_mode_selection(self):
244245
| 指标 | 目标值 | 实现情况 |
245246
|------|--------|----------|
246247
| 压力检测延迟 | < 5ms | ✅ 实现,有性能日志监控 |
247-
| LLM决策超时 | 500ms | ✅ 实现asyncio.wait_for() |
248+
| LLM决策等待 | 默认无限等待 | ✅ 实现;配置为正数时才使用 `asyncio.wait_for()` |
248249
| 冷却时间 | 30秒起 | ✅ 实现,动态调整 |
249250
| 震荡检测 | 实时 | ✅ 实现,ABA/ABAB模式检测 |
250251

config/zulong_config.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
attention_selection:
22
cooldown_base_seconds: 30.0
3-
decision_timeout_ms: 500
3+
decision_timeout_ms: null
44
enabled: true
55
fallback_mode: FOCUS
66
max_switch_history: 50
77
min_confidence_threshold: 0.3
88
oscillation_detection_window: 10
9-
pressure_threshold_high: '0.1'
10-
pressure_threshold_medium: '0.1'
9+
threshold_budget_ratio: '0.15'
10+
pressure_threshold_high: '1.0'
11+
pressure_threshold_medium: '0.9'
1112
audio:
1213
asr:
1314
backend: sensevoice
@@ -130,9 +131,10 @@ l2_inference:
130131
backup_model: deepseek-v4-pro
131132
circuit_breaker:
132133
bfs_min_interval: 3
133-
context_red_ratio: '0.1'
134+
threshold_budget_ratio: '0.15'
135+
context_red_ratio: '1.0'
134136
context_window_size: 131072
135-
context_yellow_ratio: '0.1'
137+
context_yellow_ratio: '0.9'
136138
enabled: true
137139
max_yellow_before_red: 4
138140
no_progress_red: 8
@@ -229,7 +231,7 @@ llm:
229231
base_url: http://localhost:11434/v1
230232
model_id: qwen3.5:4b
231233
deepseek:
232-
api_key: sk-f5fbf20095de478fb711cfd0d573739e
234+
api_key: ${DEEPSEEK_API_KEY}
233235
backend: deepseek
234236
base_url: https://api.deepseek.com
235237
model_id: deepseek-v4-pro
@@ -296,7 +298,7 @@ llm:
296298
schedule_policy: lpm
297299
tp_size: 1
298300
siliconflow:
299-
api_key: sk-fmylzckwftjrirdovmqygassifruqckzjsqzpbmyjrbqivcy
301+
api_key: ${SILICONFLOW_API_KEY}
300302
backend: siliconflow
301303
base_url: https://api.siliconflow.cn/v1
302304
model_id: deepseek-ai/DeepSeek-V4-Flash

docs/LLM_Attention_Selection_Integration_Guide.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,9 @@ attention_selection:
323323
enabled: true # 启用/禁用LLM自主选择
324324

325325
# 压力阈值配置
326-
pressure_threshold_high: 0.6 # 高压阈值
327-
pressure_threshold_medium: 0.5 # 中压阈值
326+
threshold_budget_ratio: 0.5 # 阈值预算=LLM原始上下文窗口的50%
327+
pressure_threshold_high: 1.0 # RED触发线:上下文压力 >100%
328+
pressure_threshold_medium: 0.9 # YELLOW触发线:上下文压力 >90%
328329

329330
# 冷却时间配置
330331
cooldown_base_seconds: 30.0 # 基础冷却时间(秒)
@@ -333,7 +334,7 @@ attention_selection:
333334
fallback_mode: "FOCUS" # Fallback默认模式
334335

335336
# 性能配置
336-
decision_timeout_ms: 500 # LLM决策超时(毫秒)
337+
decision_timeout_ms: null # null表示等待LLM完成注意力选择
337338

338339
# 震荡检测配置
339340
oscillation_detection_window: 10 # 震荡检测窗口大小
@@ -359,7 +360,12 @@ def test_pressure_detection():
359360

360361
def test_threshold_check():
361362
"""测试阈值判断"""
362-
config = AttentionConfig(pressure_threshold_high=0.6)
363+
config = AttentionConfig(
364+
threshold_budget_ratio=0.5,
365+
pressure_threshold_high=1.0,
366+
pressure_threshold_medium=0.9,
367+
decision_timeout_ms=None,
368+
)
363369
detector = PressureDetector(mock_awm, config)
364370
metrics = PressureMetrics(current_pressure=1.0, ...)
365371
result = detector.check_threshold(metrics)

docs/architecture/system-overview.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,16 +383,15 @@ Requirement (深度 0)
383383
**源文件**: `zulong/l2/attention_window.py`
384384
**成熟度**: 基本可用
385385

386-
**三模式状态机**:
387-
- **GLOBAL**: 全局视角,关注大纲和整体结构,深层节点权重递减
388-
- **FOCUS**: 聚焦特定节点,提高关联上下文权重
389-
- **SINGLE_CHAIN**: 单链推理,只保留当前执行链路的高权重信息
390-
391-
**模式切换由工具调用驱动** (零 LLM 开销):
392-
- `recall_memory` / `read_memory_node` → GLOBAL → FOCUS
393-
- `exec_write_file` / `exec_run_command` → FOCUS → SINGLE_CHAIN
394-
- `task_view_overview` / `submit_final_answer` → 强制回 GLOBAL
395-
- `navigate_attention` → deeper / broader / jump 三种导航
386+
**三模式动态注意力**:
387+
- **GLOBAL**: 全局视角,关注完整任务结构、跨分支依赖、历史证据与最终复核。
388+
- **FOCUS**: 局部注意,围绕当前节点/需求缺口/关键证据按需注入上下文,暂时排除无关上下文。
389+
- **SINGLE_CHAIN**: 单链注意,围绕当前推理链或调试链按需注入必要上下文;当需要跨分支判断时可重新注入其他上下文或上浮回 GLOBAL。
390+
391+
**模式切换原则**:
392+
- 上下文压力阈值监控是触发 L2 动态注意力切换的主信号。
393+
- LLM 根据压力值、当前 TaskGraph 节点、未覆盖 TaskSpec、MemoryGraph 证据和工具结果,自主选择 GLOBAL / FOCUS / SINGLE_CHAIN。
394+
- 显式注意力导航接口可执行 LLM 的注意力选择;普通工具调用不得作为 L2 注意力主规则绑定,只能进入工具账本、压力观测和质量证据。
396395

397396
**Token 预算**: `budget = (context_window - reserved) × 90%`,reserved = 7096 tokens
398397

docs/task-system/fc-loop.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ fc_graph.py 路径完全缺失以下能力:
7070
### 3.3 AttentionWindow (attention_window.py, 948 行, 生产级 4/5)
7171

7272
- **三种模式**:
73-
- GLOBAL: 大纲权重高, 深度递减 (depth0→×1.2, depth4+→×0.3)
74-
- FOCUS: 当前节点×3.0, 祖先/依赖×2.0, 兄弟×1.5, 无关×0.5
75-
- SINGLE_CHAIN: 当前链×5.0, 祖先×3.0, 依赖×2.5, 无关×0.2
76-
- **自动状态机**: recall_memory→FOCUS, exec_write_file→SINGLE_CHAIN, task_view_overview→GLOBAL
73+
- GLOBAL: 保持全局任务/记忆上下文视角,用于规划、复核、汇总与跨分支判断
74+
- FOCUS: 由 LLM 在上下文压力或任务阶段需要时选择焦点节点,按需注入当前节点、祖先、依赖与关键证据,暂排无关上下文
75+
- SINGLE_CHAIN: 由 LLM 在单链深度执行/调试时选择当前推理链,优先注入当前链路必要上下文;需要跨分支判断时应能重新注入其他上下文或回到 GLOBAL
76+
- **触发原则**: 上下文压力阈值监控是触发 L2 动态注意力切换的主信号;LLM 根据当前任务、压力、覆盖缺口和证据状态自主选择 GLOBAL / FOCUS / SINGLE_CHAIN。普通工具调用只能进入工具账本、压力观测和质量证据,不得作为主规则绑定或直接触发模式切换。
7777
- **权重公式**: `base × time_decay(0.95^age) × mode_mult × memory_boost(1.0~1.5)`
7878
- **消息分组**: tool_group 确保 assistant+tool 消息原子性淘汰
7979
- **淘汰处理**: 淘汰摘要持久化到 MemoryGraph + TaskGraph, 提示LLM用recall_memory恢复
@@ -229,7 +229,7 @@ Cline v3.82.0 fork → zulong-ide 插件 → 全面重写通信协议 (XML → W
229229
|------|------|---------|---------|
230230
| `circuit_breaker.py` | L61 | `CB_RETAINED_NAMES` 白名单 | CB RED 状态下仍允许调用 |
231231
| `circuit_breaker.py` | L74 | 终结类工具白名单 | 分类为"终结工具" |
232-
| `attention_window.py` | L89 | GLOBAL_TRIGGER_TOOLS 集合 | 调用后自动切换到 GLOBAL 模式 |
232+
| `attention_window.py` | 历史旧实现 | GLOBAL_TRIGGER_TOOLS 集合 | 已废弃:普通工具名不得直接触发 GLOBAL 模式 |
233233
| `attention_window.py` | L519 | 特殊处理分支 | 调用时清除焦点状态 |
234234
| `task_graph.py` | L129 | 注释文档 | 模型通过它完成任务 |
235235

0 commit comments

Comments
 (0)