oudecheng
7b459b8ca1
feat(config): 压缩算法关键参数暴露到设置页面
...
将 4 个压缩参数(threshold_ratio、llm_compaction_threshold_ratio、
truncate_max_tokens、preserve_count)从硬编码提取到 config.json 顶层
compaction 节,前端新增 CompactionTab 供用户调整。
后端:
- config: 新增 CompactionConfig 结构体,Config 新增 compaction 字段
- context_compressor: 4 个参数内聚到 ContextCompressor 实例字段;
新增 with_compaction_config() 构造函数和 truncate_tool_results() 方法;
对用户配置做防御性 clamp(ratio ∈ [0.1,1.0],整数 ≥ 1)
- agent_loop: 调用 compressor.truncate_tool_results() 实现零参数耦合
- agent_factory: 新增 build_compressor() 方法,in-loop 与 sync 兜底
两条压缩路径共用同一套用户配置
- session: with_factories 改用 agent_factory.build_compressor(),修复
sync 压缩路径忽略用户配置的 P0 问题
前端:
- types: 新增 CompactionConfig 接口,TabId 新增 'compaction'
- 新建 CompactionTab.tsx,4 个 number input 分两组 SectionCard
- constants + ConfigPage: 注册"上下文压缩" Tab(Archive 图标)
清理:删除无调用方的 from_provider_config/from_runtime_config/with_config
方法及 DEFAULT_THRESHOLD_RATIO/LLM_COMPACTION_THRESHOLD_RATIO 常量。
测试:context_compressor 18 + session 31 + agent_loop 42 全通过。
2026-08-06 11:03:56 +08:00
oudecheng
6252b600cd
refactor(compression): 重构上下文压缩为两阶段+双阈值+三段保留
...
压缩时机从 process 整体返回后提前到每轮工具调用完成后,更及时控制上下文大小。
两阶段压缩:
- 工程化压缩(70% 阈值触发):截断非子代理 tool 结果到 100 token,仅改内存不影响 DB
- LLM 压缩(50% 阈值触发):工程化压缩后仍超 50% 才调 LLM,避免不必要的 LLM 调用
LLM 压缩三段保留策略:
- 保留最旧 5 个 unit 和最新 5 个 unit 原样
- 中间段用 LLM 生成摘要(heavy prompt)
- SystemGuard 永远保留不计入配额
- ToolRound 原子性由 parse_to_units 保证,切分在 unit 边界
工程化压缩:
- truncate_tool_results_in_place 截断 role="tool" 且 tool_name!="task" 的消息
- 子代理返回(tool_name="task")保持原样
- char_indices 确保 UTF-8 字符边界安全,截断后追加 "...[已截断]" 标记
AgentLoop 集成:
- 新增 CompactionSink trait,LLM 压缩结果通过 sink 回写 DB
- AgentProcessResult 新增 compaction_performed 和 engineering_compaction_applied 标记
- finalize_result 据此决定是否 reload DB 历史(避免重复 append)和跳过兜底压缩
错误恢复:
- LLM 压缩失败降级为仅工程化压缩,不中断 agent loop
- sink.compact 失败记 error 日志继续使用内存压缩结果,DB 下次 process 会重新触发压缩
清理旧的 two-segment 差异化压缩代码(OLDER_BUDGET_RATIO、find_safe_split_point、
build_light_summary_prompt 等),新增 unit_to_messages 辅助函数。
2026-08-05 21:56:41 +08:00
oudecheng
cda14360af
chore: 建立工程化基线(rustfmt + clippy + CI + eslint + prettier)
...
配置:
- rustfmt.toml: 固化 max_width=100 / 4 空格缩进,cargo fmt 全量格式化
- Cargo.toml: 配置 [lints.rust] 与 [lints.clippy] 渐进式规则
- .github/workflows/ci.yml: Rust(fmt+clippy+test) + 前端(eslint+tsc+test) 双平台 CI
- Makefile: 新增 check/fmt/fix 目标,clippy 对齐 --all-targets --all-features
- web: eslint flat config + prettier 配置 + package.json 脚本与依赖
- src/main.rs: loop→while 修复 clippy::never_loop
对抗性审查发现并修复:
- eslint 缺 caughtErrorsIgnorePattern 导致 catch(_) 误报为 error
- 前端 lint 未接入 CI,现已补上 Lint 步骤
- Makefile 与 CI 的 clippy flags 不一致,已对齐
2026-08-03 23:24:02 +08:00
oudecheng
a825b10c48
feat(model): 主 agent 支持会话级模型覆盖
...
新增 ModelSelectionStore 存储 session_id -> (provider, model) 映射,职责单一,仅依赖 std,不引入业务模块耦合。
AgentFactory::create 中按链式覆盖应用模型配置: 专家 frontmatter 覆盖 -> 用户手动选择覆盖(最高优先级)。
HTTP API: POST /api/session/select-model 设置/清除用户模型覆盖(校验 provider/model 存在性); GET /api/session/selected-model 读取当前 session 的用户覆盖(与 experts/selected 对称)。
在 build_session_manager 系列函数中创建并注入 ModelSelectionStore,GatewayState 持有 Arc<ModelSelectionStore> 供 HTTP handler 访问。
2026-07-30 23:24:51 +08:00
oudecheng
dc9211548a
feat(model): 专家和子代理支持独立配置 provider/model
...
- 新增 ModelResolver 解析器,按 frontmatter 中的 provider/model 名覆盖基础 LLMProviderConfig
- Expert/SubagentDef 数据结构新增 provider/model 字段,frontmatter 解析与渲染支持往返
- AgentFactory 和 DefaultSubAgentRuntime 持有 ModelResolver,在创建 agent 时解析模型覆盖
- HTTP API 新增 /api/model-options 端点,ExpertResponse/Create/Update 和 SubagentUpdateRequest 支持 provider/model
- update_expert/update_subagent 支持 provider/model 字段写回 frontmatter
- 保持架构解耦:ModelResolver 位于 config 底层,不引入新的跨模块依赖
2026-07-30 22:44:10 +08:00
oudecheng
c27efedb6c
feat(capability): 扩展 CapabilityPolicy 支持子代理黑白名单
...
- domain: CapabilityPolicy 新增 allowed_subagents/denied_subagents 字段及 check_subagent_allowed 方法
- experts: 专家 frontmatter 解析/渲染支持子代理策略字段
- task/runtime: spawn/resume 双路径校验父代理子代理策略;新增 update_subagent 写回 SUBAGENT.md(与 update_expert 对称);新增 SubagentPromptProvider 按专家策略过滤子代理索引
- task/runtime: 子代理自身 capability 作为孙代理的 parent_capability 透传(ToolContext),保持解耦
- traits: ToolContext 新增 parent_capability 字段
- agent_factory: 主 agent 注入 expert_capability 到 ToolContext
安全:策略不通过即拒绝(与 def 不可用即拒绝范式一致),防止 LLM 通过选择被禁子代理绕过限制;max_nesting_depth 兜底防递归不可被 def 覆盖。
2026-07-30 17:37:29 +08:00
oudecheng
12f1094426
feat(capability): 新增 CapabilityPolicy 统一策略模型并集成至专家/子代理/技能
...
- domain: 定义 CapabilityPolicy(allowed/denied skills/tools)统一策略结构
- experts: 专家支持 capability 字段,新增 update_expert 写回 EXPERT.md
- skills: SkillRuntime 暴露 capability 过滤接口
- tools/task: SubagentDef 增加 capability 字段,SubagentRuntime 新增 update_subagent 写回 SUBAGENT.md,工具集按 capability 过滤
- agent_factory: 按 capability 构建专家/子代理工具集(白名单交集 + 黑名单扣除)
2026-07-30 16:53:30 +08:00
oudecheng
bde55cbf14
feat: 重构工具提示提供者,整合工具使用说明;删除冗余的 TodoPromptProvider
2026-07-07 10:03:16 +08:00
oudecheng
4329cfbbe9
feat: 统一路径显示格式,确保跨平台兼容性;重构系统提示词提供者构建逻辑
2026-07-07 09:19:58 +08:00
oudecheng
9d7c1f2e52
feat: 集成专家提示词到网关配置、依赖注入与HTTP API
...
- config: 新增 ExpertsConfig,默认 sources=[user,project], enabled=true
- AgentFactory: 新增 experts 字段,providers 顺序为 Agent→Skill→Expert→Subagent→Todo
- GatewayState: 持有 Arc<ExpertRuntime>,from_config 中初始化
- runtime: build_session_manager_with_sender 接收 experts 参数
- 路由: 注册 7 个专家 API (list/toggle/create/update/delete/selected/select)
- http: 实现 7 个处理器,支持专家 CRUD 与 session 级选择
- session/cli: 测试便利构造器与 empty_config/build_config 补齐 experts 字段
2026-07-06 18:07:33 +08:00
oudecheng
8d30ccd020
feat: 新增子代理管理API,支持获取子代理列表和切换子代理状态
2026-07-06 14:41:30 +08:00
oudecheng
5ceafb1fd7
feat: 添加配置应用诊断日志,便于排查 AgentFactory 实例与工具列表
2026-07-03 16:33:01 +08:00
oudecheng
606fcbcd29
feat(agent): 注入并传递 tool_call_id 实现任务与工具调用精准关联
...
- 在 agent_loop 执行上下文中注入 tool_call_id,确保执行时传递该字段
- 在 agent_factory、ws、todo_read、todo_write 等多处构造对象时添加 tool_call_id 字段初始化
- 扩展协议定义及序列化,支持 tool_call_id 字段传递
- 在工具调用任务运行时传递 tool_call_id,便于事件追踪和层级关联
- 在前端 useChat hook 增加 tool_call_id 关联逻辑,实现 task_started 事件精准匹配和跳转
- 增加 pendingTaskNavs 缓存处理,解决 task_started 事件先于 tool_call 到达的顺序问题
- 调整消息渲染逻辑,根据 tool_call_id 进行优先匹配,提升用户交互体验
2026-06-22 10:22:36 +08:00
oudecheng
2607ca4aa4
refactor(task): 优化任务工具和子代理深度管理
...
- 在 AgentContext 中新增 task_id 字段,用于标识当前智能体任务 ID
- 统一 TaskTool 构造函数,使用 Option<u32> 表示最大嵌套深度限制
- 调整子代理工具注册,适配新的 TaskTool 构造函数
- 修改子代理运行时创建逻辑,传递并设置 task_id 和 parent_task_id
- 删除重复的 task_id 提取函数,改用传递参数进行关联
- 深度校验改为判断 Option,支持无深度限制和有限层数
- 增强子代理间的任务层级关联,正确传递 parent_task_id 元数据
2026-06-18 11:41:40 +08:00
oudecheng
e506ffd539
feat(agent): 支持子孙智能体的父任务链路传递
...
- 在 agent_factory 和子代理相关结构体中新增 parent_task_id 字段
- 协议层序列化、反序列化及 WebSocket 适配器支持 parent_task_id 信息传递
- todo_read 与 todo_write 工具添加 parent_task_id 以保持任务层级一致
- 在 DefaultSubAgentRuntime 中实现从 session_id 提取 parent_task_id 的逻辑
- 子智能体创建孙智能体时,正确设置并传递 parent_task_id 元数据
- 前端 useChat 钩子过滤孙智能体的 TaskStarted 事件,避免视图串扰
2026-06-18 11:30:47 +08:00
oudecheng
631c61fea2
feat(agent): 支持子代理最大嵌套深度控制
...
- 在配置结构体中新增 max_nesting_depth 字段,设置子代理最大嵌套深度
- 在 AgentFactory、todo_read、todo_write 等处初始化 nesting_depth 字段为 0
- 允许 Task 工具注册,使用 max_nesting_depth 控制子代理嵌套层数
- SubAgentRuntimeConfig 新增 max_nesting_depth 配置项,默认值为 1
- TaskTool 新增 max_nesting_depth 字段和带深度限制的构造函数
- 任务执行时增加嵌套深度校验,超过最大深度返回错误提示,防止无限递归创建子代理
2026-06-17 14:43:55 +08:00
oudecheng
eef0d24dcd
fix: topic_id 穿透到 ToolContext,统一 todo scope_key 计算
...
- AgentBuildRequest 加 topic_id 字段
- Session.create_agent 传入 current_topic
- ToolContext.topic_id 不再硬编码 None
- 删除已废弃的 intercept_todo_write_results
- 工具/emitter/handler 三处 scope_key 计算全部统一
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 17:36:10 +08:00
oudecheng
881fcace47
feat: 添加 todo_write 工具,支持全量替换和增量合并两种模式
...
- Tool: 纯内存实现 (Arc<RwLock<HashMap>>),零 DB 依赖,解耦持久化
- 状态机: pending → in_progress → completed/cancelled,单 in_progress 约束
- merge=false: 全量替换模式(默认)
- merge=true: 增量更新模式,只传变更的项,其余保留
- 隔离: scope_key = topic_id.unwrap_or(session_id),topic 和子代理隔离
- 持久化: TodoRepository trait + SessionStore SQLite 实现,在 Session 拦截器层完成
- 前端推送: WsOutbound::TodoList 事件
- Prompt: TodoPromptProvider 中文指令,子代理模板也包含
- 测试: 16 个单元测试,全部通过
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 14:19:07 +08:00
oudecheng
1b571e943f
feat: 添加停止当前执行的 Agent 功能,支持通过 /stop 命令取消执行
2026-06-03 16:49:29 +08:00
oudecheng
1c6ee160e5
feat: 添加父话题 ID 支持,优化子智能体任务管理和会话关联
2026-05-20 18:11:16 +08:00
bee1a39a06
feat: add task management tool with subagent support
...
- Introduced `TaskConfig` struct to manage task-related configurations.
- Implemented `TaskTool` for creating and managing subagents for complex tasks.
- Added `TaskSession` and `TaskRepository` for handling task sessions and persistence.
- Created `DefaultSubAgentRuntime` to execute tasks with timeout and history support.
- Enhanced `ToolContext` to include `subagent_description` for better context tracking.
- Implemented error handling for task execution and session management.
- Updated `ToolRegistryFactory` to register task tools conditionally based on configuration.
- Added prompt builders for subagent tasks to improve interaction clarity.
2026-05-16 16:12:28 +08:00
oudecheng
1c1efcabf4
feat: 移除冗余的 provider_config 字段,优化 AgentFactory 和 Session 的构造逻辑
2026-05-13 15:41:52 +08:00
oudecheng
a06fceaf0c
feat: 添加系统提示词提供者,支持动态注入和组合多个提示词源
2026-05-13 14:55:50 +08:00
oudecheng
cadc5e5577
feat: 支持分离 session_chat_id 和 notification_chat_id,优化任务执行逻辑
2026-05-13 09:39:05 +08:00
90e44950cb
feat: 重构技能事件处理逻辑,移除 SkillEventSink,添加 SkillActivateTool 模块以优化技能激活流程
...
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 15:31:56 +08:00
396504dffb
Refactor agent and storage components to introduce SkillProvider and repository patterns
...
- Introduced `SkillProvider` trait to abstract skill-related functionalities.
- Replaced `SkillRuntime` with `EmptySkillProvider` in `AgentLoop` for default behavior.
- Updated `AgentFactory` to accept `SkillProvider` instead of `SkillRuntime`.
- Created `SessionHistory` struct to manage chat histories and interactions.
- Added `MemoryRepository`, `SchedulerJobRepository`, and `SkillEventRepository` traits for better storage abstraction.
- Refactored tools to use new repository traits for memory and scheduler management.
- Cleaned up session management logic by consolidating chat history handling into `SessionHistory`.
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 15:12:45 +08:00
c547b88a12
feat: 添加持久化技能事件处理逻辑,重构技能事件记录机制
...
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 14:49:31 +08:00
c65921b5e8
feat: 添加 AgentFactory 和 PromptInjector,重构工具注册逻辑以优化会话管理
2026-04-28 13:06:00 +08:00