diff --git a/.features/skill/MEMORY.md b/.features/skill/MEMORY.md new file mode 100644 index 0000000..7d6fc1a --- /dev/null +++ b/.features/skill/MEMORY.md @@ -0,0 +1,121 @@ +# Skill 功能 + +> 负责范围:技能包管理服务 - 核心实现 +> 最后更新:2025-02-11 + +## 当前状态 + +Skill 系统支持两种来源:官方 skills (`./skills/`) 和用户 skills (`projects/uploads/{bot_id}/skills/`)。支持 Hook 系统和 MCP 服务器配置,通过 SKILL.md 或 plugin.json 定义元数据。 + +## 核心文件 + +- `routes/skill_manager.py` - Skill 上传/删除/列表 API +- `agent/plugin_hook_loader.py` - Hook 系统实现 +- `agent/deep_assistant.py` - `CustomSkillsMiddleware` +- `agent/prompt_loader.py` - PrePrompt hooks + MCP 配置合并 +- `skills/` - 官方 skills 目录 +- `skills_developing/` - 开发中 skills + +## 最近重要事项 + +- 2025-02-11: 初始化 skill 功能 memory + +## Gotchas(开发必读) + +- ⚠️ 执行脚本必须使用绝对路径 +- ⚠️ MCP 配置优先级:Skill MCP > 默认 MCP > 用户参数 +- ⚠️ 上传大小限制:50MB(ZIP),解压后最大 500MB +- ⚠️ 压缩比例检查:最大 100:1(防止 zip 炸弹) +- ⚠️ 符号链接检查:禁止解压包含符号链接的文件 + +## Skill 目录结构 + +``` +skill-name/ +├── SKILL.md # 核心指令文档(必需) +├── skill.yaml # 元数据配置(可选) +├── .claude-plugin/ +│ └── plugin.json # Hook 和 MCP 配置(可选) +└── scripts/ # 可执行脚本(可选) + └── script.py +``` + +## Hook 系统 + +| Hook 类型 | 执行时机 | 用途 | +|-----------|---------|------| +| `PrePrompt` | system_prompt 加载时 | 动态注入用户上下文 | +| `PostAgent` | agent 执行后 | 处理响应结果 | +| `PreSave` | 保存消息前 | 内容过滤/修改 | + +## API 接口 + +| 端点 | 方法 | 功能 | +|------|------|------| +| `GET /api/v1/skill/list` | - | 返回官方 + 用户 skills | +| `POST /api/v1/skill/upload` | - | ZIP 上传,解压到用户目录 | +| `DELETE /api/v1/skill/remove` | - | 删除用户 skill | + +## 内置 Skills + +| Skill 名称 | 功能描述 | +|-----------|---------| +| `excel-analysis` | Excel 数据分析、透视表、图表 | +| `managing-scripts` | 管理可复用脚本库 | +| `rag-retrieve` | RAG 知识库检索 | +| `jina-ai` | Jina AI Reader/Search | +| `user-context-loader` | Hook 机制示例 | + +## plugin.json 格式 + +```json +{ + "name": "skill-name", + "description": "描述", + "hooks": { + "PrePrompt": [{"type": "command", "command": "python hooks/pre_prompt.py"}], + "PostAgent": [...], + "PreSave": [...] + }, + "mcpServers": { + "server-name": { + "command": "...", + "args": [...] + } + } +} +``` + +## Skill 加载优先级 + +1. Skill MCP 配置(最高) +2. 默认 MCP 配置 (`mcp/mcp_settings.json`) +3. 用户传入参数(覆盖所有) + +## 安全措施 + +- ZipSlip 防护:检查解压路径 +- 路径遍历防护:验证 `bot_id` 和 `skill_name` 格式 +- 大小限制:上传 50MB,解压后 500MB +- 压缩比限制:最大 100:1 + +## 设计原则 + +- **渐进式加载**:按需加载,避免一次性读取所有 +- **绝对路径优先**:执行脚本必须使用绝对路径 +- **通用化设计**:脚本应参数化,解决一类问题 +- **安全优先**:完整的上传验证链 + +## 配置项 + +```bash +SKILLS_DIR=./skills # 官方 skills 目录 +BACKEND_HOST=xxx # RAG API 主机 +MASTERKEY=xxx # 认证密钥 +``` + +## 索引 + +- 设计决策:`decisions/` +- 变更历史:`changelog/` +- 相关文档:`docs/` diff --git a/.features/skill/changelog/2025-Q4.md b/.features/skill/changelog/2025-Q4.md new file mode 100644 index 0000000..b43c00a --- /dev/null +++ b/.features/skill/changelog/2025-Q4.md @@ -0,0 +1,38 @@ +# 2025-Q4 Skill Changelog + +## 版本 0.1.0 - 初始实现 + +### 2025-10-31 +- **新增**: agent skills 支持,测试阶段代码 +- **文件**: `chat_handler.py`, `knowledge_chat_cc_service.py` +- **作者**: Alex + +### 2025-11-03 +- **新增**: 内置 skills (pptx, docx, pdf, xlsx) +- **新增**: jina skill - 规范 jina 网络搜索 +- **解决**: "prompt too long" 问题 + +### 2025-11-13 +- **新增**: cc agent task 任务添加默认 skills +- **文件**: `task_handler.py`, `knowledge_task_cc_service.py` + +### 2025-11-19 +- **新增**: skill-creator 内置技能 + +### 2025-11-20 +- **新增**: EFS 类型接口,新增上传 skill +- **功能**: 支持 skill 包上传 + +### 2025-11-21 +- **新增**: EFS 删除 skill 接口 +- **移除**: skill 查询接口(暂存) + +### 2025-11-22 +- **新增**: GRPC chat 接口,skills 参数支持 + +### 2025-11-26 +- **新增**: skill 上传支持 `.skill` 后缀(测试) + +### 2025-11-28 +- **优化**: 默认挂载的 skill 改为合并逻辑 +- **优化**: 代码结构优化 diff --git a/.features/skill/changelog/2026-Q1.md b/.features/skill/changelog/2026-Q1.md new file mode 100644 index 0000000..9c0ea7e --- /dev/null +++ b/.features/skill/changelog/2026-Q1.md @@ -0,0 +1,36 @@ +# 2026-Q1 Skill Changelog + +## 版本 0.2.0 - API 完善 + +### 2026-01-07 +- **新增**: Skills 列表查询 API(能力管理页面) +- **新增**: 技能管理 API with authentication +- **文件**: `routes/skill_manager.py` +- **作者**: claude[bot], 朱潮 + +### 2026-01-09 +- **重构**: 移除 catalog agent,合并到 general agent +- **说明**: 简化架构,统一使用 general_agent +- **作者**: 朱潮 + +### 2026-01-10 +- **修复**: SKILL.md 的 name 字段解析逻辑 +- **新增**: 支持非标准 YAML 格式 +- **新增**: 目录名称不匹配时自动重命名 +- **作者**: Alex + +### 2026-01-13 +- **修复**: multipart form data format for catalog service +- **作者**: 朱潮 + +### 2026-01-28 +- **新增**: enable_thinking, enable_memory, skills to agent_bot_config +- **作者**: 朱潮 + +### 2026-01-30 +- **修复**: skill router 正确注册 +- **作者**: 朱潮 + +### 2026-02-11 +- **新增**: 初始化 skill feature memory +- **作者**: 朱潮 diff --git a/.features/skill/decisions/001-architecture.md b/.features/skill/decisions/001-architecture.md new file mode 100644 index 0000000..e899950 --- /dev/null +++ b/.features/skill/decisions/001-architecture.md @@ -0,0 +1,46 @@ +# 001: Skill 架构设计 + +## 状态 +已采纳 (Accepted) + +## 上下文 +需要为 QWEN_AGENT 模式的机器人提供可扩展的技能(插件/工具)支持,允许动态加载自定义功能。 + +## 决策 + +### 目录结构设计 +``` +skill-name/ +├── SKILL.md # 核心指令文档(必需) +├── skill.yaml # 元数据配置(可选) +├── .claude-plugin/ +│ └── plugin.json # Hook 和 MCP 配置(可选) +└── scripts/ # 可执行脚本(可选) +``` + +### Hook 系统 +| Hook 类型 | 执行时机 | 用途 | +|-----------|---------|------| +| `PrePrompt` | system_prompt 加载时 | 动态注入用户上下文 | +| `PostAgent` | agent 执行后 | 处理响应结果 | +| `PreSave` | 保存消息前 | 内容过滤/修改 | + +### 技能来源 +1. **官方 skills**: `./skills/` 目录 +2. **用户 skills**: `projects/uploads/{bot_id}/skills/` + +## 结果 + +### 正面影响 +- 渐进式加载,按需读取 +- 支持多种元数据格式(优先级: plugin.json > SKILL.md) +- 完整的 Hook 扩展机制 +- MCP 服���器配置支持 + +### 负面影响 +- 需要管理文件系统权限 +- 技能包格式验证复杂度增加 + +## 替代方案 +1. 使用数据库存储(拒绝:文件更灵活) +2. 仅支持单一格式(拒绝:用户多样性需求) diff --git a/.features/skill/decisions/002-security.md b/.features/skill/decisions/002-security.md new file mode 100644 index 0000000..dc671c5 --- /dev/null +++ b/.features/skill/decisions/002-security.md @@ -0,0 +1,35 @@ +# 002: Skill 上传安全措施 + +## 状态 +已采纳 (Accepted) + +## 上下文 +用户可以上传 ZIP 格式的技能包,需要防范常见的安全攻击。 + +## 决策 + +### 安全防护措施 + +| 威胁 | 防护措施 | +|------|---------| +| ZipSlip 攻击 | 检查每个文件的解压路径 | +| 路径遍历 | 验证 `bot_id` 和 `skill_name` 格式 | +| Zip 炸弹 | 压缩比检查(最大 100:1) | +| 磁盘空间滥用 | 上传 50MB,解压后最大 500MB | +| 符号链接攻击 | 禁止解压包含符号链接的文件 | + +### 限制规则 +```python +MAX_UPLOAD_SIZE = 50 * 1024 * 1024 # 50MB +MAX_EXTRACTED_SIZE = 500 * 1024 * 1024 # 500MB +MAX_COMPRESSION_RATIO = 100 # 100:1 +``` + +## 结果 +- 完整的上传验证链 +- 防止恶意文件攻击 +- 资源使用可控 + +## 替代方案 +1. 使用沙箱容器解压(拒绝:复杂度高) +2. 仅允许预定义技能(拒绝:限制用户自定义能力) diff --git a/docker-compose-with-pgsql.yml b/docker-compose-with-pgsql.yml index e0332dd..cf998f0 100644 --- a/docker-compose-with-pgsql.yml +++ b/docker-compose-with-pgsql.yml @@ -31,7 +31,6 @@ services: # 应用配置 - BACKEND_HOST=http://api-dev.gbase.ai - MAX_CONTEXT_TOKENS=262144 - - DEFAULT_THINKING_ENABLE=true # PostgreSQL 配置 - CHECKPOINT_DB_URL=postgresql://postgres:E5ACJo6zJub4QS@postgres:5432/agent_db - R2_UPLOAD_CONFIG=/app/config/local-upload.yaml diff --git a/docker-compose.yml b/docker-compose.yml index d0886a6..16a757e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,6 @@ services: # 应用配置 - BACKEND_HOST=http://api-dev.gbase.ai - MAX_CONTEXT_TOKENS=262144 - - DEFAULT_THINKING_ENABLE=true - R2_UPLOAD_CONFIG=/app/config/s3-upload-sparticle.yaml volumes: # 挂载项目数据目录 diff --git a/prompt/FACT_RETRIEVAL_PROMPT.md b/prompt/FACT_RETRIEVAL_PROMPT.md index 1c2f93e..d075528 100644 --- a/prompt/FACT_RETRIEVAL_PROMPT.md +++ b/prompt/FACT_RETRIEVAL_PROMPT.md @@ -8,16 +8,17 @@ Types of Information to Remember: 4. Remember Activity and Service Preferences: Recall preferences for dining, travel, hobbies, and other services. 5. Monitor Health and Wellness Preferences: Keep a record of dietary restrictions, fitness routines, and other wellness-related information. 6. Store Professional Details: Remember job titles, work habits, career goals, and other professional information. -7. **Manage Relationships and Contacts**: CRITICAL - Keep track of people the user frequently interacts with. This includes: - - Full names of contacts (always record the complete name when mentioned) - - Short names, nicknames, or abbreviations the user uses to refer to the same person - - Relationship context (family, friend, colleague, client, etc.) +7. **Manage Relationships and People**: CRITICAL - Keep track of people the user frequently interacts with. This includes: + - Full names (always record the complete name when mentioned) + - Nicknames or short names the user uses for the same person + - Relationship (family, friend, colleague, client, etc.) - When a user mentions a short name and you have previously learned the full name, record BOTH to establish the connection - - Examples of connections to track: "Mike" → "Michael Johnson", "Tom" → "Thomas Anderson", "Lee" → "Lee Ming", "田中" → "田中一郎" - - **Handle Multiple People with Same Surname**: When there are multiple people with the same surname (e.g., "滨田太郎" and "滨田清水"), track which one the user most recently referred to with just the surname ("滨田"). Record this as the default/active reference. - - **Format for surname disambiguation**: "Contact: [Full Name] (relationship, also referred as [Surname]) - DEFAULT when user says '[Surname]'" + - Examples: "Mike" → "Michael Johnson", "Tom" → "Thomas Anderson", "Lee" → "Lee Ming", "田中" → "田中一郎" + - **Handle Multiple People with Same Surname**: When there are multiple people with the same surname (e.g., "滨田太郎" and "滨田清水"), track which one the user most recently referred to with just the surname. 8. Miscellaneous Information Management: Keep track of favorite books, movies, brands, and other miscellaneous details that the user shares. +**IMPORTANT - Plain Language Rule**: All extracted facts MUST be written in plain, everyday language that anyone can understand. Do NOT use structured formats like "Contact:", "referred as", "DEFAULT when user says" etc. Write facts as natural sentences or short notes. + Here are some few shot examples: Input: Hi. @@ -39,49 +40,49 @@ Input: Me favourite movies are Inception and Interstellar. Output: {{"facts" : ["Favourite movies are Inception and Interstellar"]}} Input: I had dinner with Michael Johnson yesterday. -Output: {{"facts" : ["Had dinner with Michael Johnson", "Contact: Michael Johnson"]}} +Output: {{"facts" : ["Had dinner with Michael Johnson", "Michael Johnson is an acquaintance"]}} Input: I'm meeting Mike for lunch tomorrow. He's my colleague. -Output: {{"facts" : ["Meeting Mike for lunch tomorrow", "Contact: Michael Johnson (colleague, referred as Mike)"]}} +Output: {{"facts" : ["Meeting Mike for lunch tomorrow", "Michael Johnson is a colleague, also called Mike"]}} Input: Have you seen Tom recently? I think Thomas Anderson is back from his business trip. -Output: {{"facts" : ["Contact: Thomas Anderson (referred as Tom)", "Thomas Anderson was on a business trip"]}} +Output: {{"facts" : ["Thomas Anderson is also called Tom", "Thomas Anderson was on a business trip"]}} Input: My friend Lee called me today. -Output: {{"facts" : ["Friend Lee called today", "Contact: Lee (friend)"]}} +Output: {{"facts" : ["Friend Lee called today", "Lee is a friend"]}} Input: Lee's full name is Lee Ming. We work together. -Output: {{"facts" : ["Contact: Lee Ming (colleague, also referred as Lee)", "Works with Lee Ming"]}} +Output: {{"facts" : ["Lee Ming is a colleague, also called Lee", "Works with Lee Ming"]}} Input: I need to call my mom later. -Output: {{"facts" : ["Need to call mom", "Contact: mom (family, mother)"]}} +Output: {{"facts" : ["Need to call mom later"]}} Input: I met with Director Sato yesterday. We discussed the new project. -Output: {{"facts" : ["Met with Director Sato yesterday", "Contact: Director Sato (boss/supervisor)"]}} +Output: {{"facts" : ["Met with Director Sato yesterday", "Director Sato is a boss/supervisor"]}} Input: I know two people named 滨田: 滨田太郎 and 滨田清水. -Output: {{"facts" : ["Contact: 滨田太郎", "Contact: 滨田清水"]}} +Output: {{"facts" : ["滨田太郎という知り合いがいる", "滨田清水という知り合いがいる"]}} Input: I had lunch with 滨田太郎 today. -Output: {{"facts" : ["Had lunch with 滨田太郎 today", "Contact: 滨田太郎 (also referred as 滨田) - DEFAULT when user says '滨田'"]}} +Output: {{"facts" : ["今日滨田太郎とランチした", "滨田太郎は「滨田」とも呼ばれている"]}} Input: 滨田 called me yesterday. -Output: {{"facts" : ["滨田太郎 called yesterday", "Contact: 滨田太郎 (also referred as 滨田) - DEFAULT when user says '滨田'"]}} +Output: {{"facts" : ["昨日滨田太郎から電話があった"]}} Input: I'm meeting 滨田清水 next week. -Output: {{"facts" : ["Meeting 滨田清水 next week", "Contact: 滨田清水 (also referred as 滨田) - DEFAULT when user says '滨田'"]}} +Output: {{"facts" : ["来週滨田清水と会う予定"]}} Input: 滨田 wants to discuss the project. -Output: {{"facts" : ["滨田清水 wants to discuss the project", "Contact: 滨田清水 (also referred as 滨田) - DEFAULT when user says '滨田'"]}} +Output: {{"facts" : ["滨田清水がプロジェクトについて話したい"]}} Input: There are two Mikes in my team: Mike Smith and Mike Johnson. -Output: {{"facts" : ["Contact: Mike Smith (colleague)", "Contact: Mike Johnson (colleague)"]}} +Output: {{"facts" : ["Mike Smith is a colleague", "Mike Johnson is a colleague"]}} Input: Mike Smith helped me with the bug fix. -Output: {{"facts" : ["Mike Smith helped with bug fix", "Contact: Mike Smith (colleague, also referred as Mike) - DEFAULT when user says 'Mike'"]}} +Output: {{"facts" : ["Mike Smith helped with bug fix", "Mike Smith is also called Mike"]}} Input: Mike is coming to the meeting tomorrow. -Output: {{"facts" : ["Mike Smith is coming to the meeting tomorrow", "Contact: Mike Smith (colleague, also referred as Mike) - DEFAULT when user says 'Mike'"]}} +Output: {{"facts" : ["Mike Smith is coming to the meeting tomorrow"]}} Input: 私は林檎好きです Output: {{"facts" : ["林檎が好き"]}} @@ -113,17 +114,16 @@ Remember the following: - For colloquial or grammatically informal expressions (common in spoken Japanese, Chinese, Korean, etc.), understand the full intended meaning and record it in a clear, semantically complete form. - In Japanese, spoken language often omits particles (e.g., が, を, に). When extracting facts, include the necessary particles to make the meaning unambiguous. For example: "私は林檎好きです" should be understood as "林檎が好き" (likes apples), not literally "私は林檎好き". - When the user expresses a preference or opinion in casual speech, record the core preference/opinion clearly. Remove the subject pronoun (私は/I) since facts are about the user by default, but keep all other semantic components intact. -- **CRITICAL for Contact/Relationship Tracking**: - - ALWAYS use the "Contact: [name] (relationship/context)" format when recording people - - When you see a short name that matches a known full name, record as "Contact: [Full Name] (relationship, also referred as [Short Name])" - - Record relationship types explicitly: family, friend, colleague, boss, client, neighbor, etc. - - For family members, also record the specific relation: (mother, father, sister, brother, spouse, etc.) +- **CRITICAL for People/Relationship Tracking**: + - Write people-related facts in plain, natural language. Do NOT use structured formats like "Contact:", "referred as", or "DEFAULT when user says". + - Good examples: "Michael Johnson is a colleague, also called Mike", "田中さんは友達", "滨田太郎は「滨田」とも呼ばれている" + - Bad examples: "Contact: Michael Johnson (colleague, referred as Mike)", "Contact: 滨田太郎 (also referred as 滨田) - DEFAULT when user says '滨田'" + - Record relationship types naturally: "is a friend", "is a colleague", "is family (mother)", etc. + - For nicknames: "also called [nickname]" or "[full name]は「[nickname]」とも呼ばれている" - **Handling Multiple People with Same Name/Surname**: - - When multiple contacts share the same surname or short name (e.g., multiple "滨田" or "Mike"), track which person was most recently referenced - - When user explicitly mentions the full name (e.g., "滨田太郎"), mark this person as the DEFAULT for the short form - - Use the format: "Contact: [Full Name] (relationship, also referred as [Short Name]) - DEFAULT when user says '[Short Name]'" - - When the user subsequently uses just the short name/surname, resolve to the most recently marked DEFAULT person - - When a different person with the same name is explicitly mentioned, update the DEFAULT marker to the new person + - When multiple people share the same surname, track which person was most recently referenced + - When user explicitly mentions a full name, remember this as the person currently associated with the short name + - When the user subsequently uses just the short name/surname, resolve to the most recently associated person Following is a conversation between the user and the assistant. You have to extract the relevant facts and preferences about the user, if any, from the conversation and return them in the json format as shown above. You should detect the language of the user input and record the facts in the same language. \ No newline at end of file diff --git a/prompt/novare.md b/prompt/novare.md index 49d0d13..709646a 100644 --- a/prompt/novare.md +++ b/prompt/novare.md @@ -74,6 +74,13 @@ - dxcore_update_device_status(device_id="[B设备id]",running_control=0) → 灯光亮度调整为0 **响应**:"已为您关闭Define Room4的灯光" +### 位置降级搜索场景 +**用户**:"3階執務スペース、フォーラム側窓側の照明をつけて" +- find_device_by_area(description="3階執務スペース、フォーラム側窓側", device_type="light") → 返回无结果 +- find_device_by_area(description="3階執務スペース", device_type="light") → 降级搜索,找到设备 +- 告知用户是基于"3階執務スペース"范围搜索到的结果,并确认是否操作 +**响应**:"「3階執務スペース、フォーラム側窓側」では見つかりませんでしたが、3階執務スペースエリアで照明が見つかりました。こちらの照明を操作しますか?" + @@ -92,6 +99,17 @@ ▪ 主动向用户确认:向用户列出所有候选房间,并提示用户选择或明确具体是哪一个。确认提示语可参考:“请问您想查询的是以下哪个房间?[列出候选房间列表]”。 ▪ 理解用户二次确认:等待用户回复后,根据其选择再次调用查询工具获取最终信息。用户对候选房间的指明(如回复“第一个”或重复房间名)应视为对该房间的确认。 4. 处理无匹配结果:如果工具返回未找到任何相关房间,应明确告知用户这一情况,并建议用户检查房间名称是否正确或提供更多线索。 + 5. **位置粒度降级搜索(詳細な位置指定で見つからない場合)**: + 用户指定了详细的位置信息(如包含方位、区域细节),但工具返回无匹配结果时,自动执行降级搜索: + - **第1步**:从位置描述中去除方位修饰语(側、付近、奥、手前、寄り等)和细节描述,保留核心区域名重新搜索 + - 例: "3階執務スペース、フォーラム側窓側" → find_device_by_area(description="3階執務スペース") + - 例: "2階会議室A、入口付近" → find_device_by_area(description="2階会議室A") + - **第2步**:如果仍无结果,进一步简化到楼层+大区域级别 + - 例: "3階執務スペース" → find_device_by_area(description="3階") + - **降级成功时的回复**:告知用户是基于更广范围的搜索结果,让用户确认 + - 回复格式: "「{元の位置}」では見つかりませんでしたが、{簡略化した位置}エリアで以下の設備が見つかりました。こちらでよろしいですか?" + - **全部失败时**:告知用户未找到设备,建议提供其他位置信息或直接指定房间名 + - 回复格式: "申し訳ございません、該当エリアでは操作可能な設備が見つかりませんでした。お部屋の名前をお教えいただけますか?" 3. 更新设备(此操作需要确认) - **条件**:用户意图为控制设备或调节参数(如开关、温度、风速), 需要进行确认。 @@ -105,6 +123,7 @@ - 通过 find_employee_location(name="[当前用户名字/邮箱]") 获取用户的sensor_id - 然后通过 find_iot_device(target_sensor_id="[当前用户的sensor_id]", device_type="[目标设备类型]") 查找他附近的设备 - 找到设备后告知用户找到的设备信息,并确认是否执行操作 + - **位置指定但匹配失败时**:如果用户指定了详细位置(如"3階執務スペース、フォーラム側窓側の照明をつけて"),但 find_device_by_area 返回无匹配结果,应按照规则 2 第 5 点的**位置粒度降级搜索**策略执行,而不是直接回复"找不到设备" 3. **空调温度调节确认方式**: - 如果用户说"有点热"、"调低点"、"太热了"等,表示要降温: 1. 先查询当前室温 @@ -142,8 +161,8 @@ - 如果用户指定了具体档位(如"调到强"),直接使用指定档位 - **边界情况**:如果已达到最高档(强)或最低档(弱)无法继续调整,告知用户并主动建议调整温度 - 回复格式:"風量は既に『強/弱』になっていますので、これ以上調整できません。代わりに温度を調整しますか?" - 6. **若用户已明确确认**:直接调用【设备控制】工具执行操作。 - 7. **若用户未确认且为新请求**:向用户发送确认提示:"即将为您 [操作内容] [设备名称] [具体参数],是否确认?",待用户确认后再执行。 + 6. **若用户已明确确认**:**立即**调用【设备控制】工具执行操作,不做任何额外确认或复述。确认后的唯一动作就是调用工具。 + 7. **若用户未确认且为新请求**:向用户发送确认提示:"即将为您 [操作内容] [设备名称] [具体参数],是否确认?",待用户确认后再执行。每个操作只确认一次。 4. 查询人员信息/wowtalk账号/人员位置 - **条件**:用户意图为查找某人、员工、同事或房间位置。 @@ -190,15 +209,43 @@ - 影响范围大的操作:影响整个房间或楼层的设备控制 ### 用户确认意图推理 -- 用户明确确认:如回复“确认”、“好的”、“是的”、“拜托了”、“よろしく”、“请”、“please”等肯定性语气的内容。 -- 用户意图重申:用户完整或核心重复当前待执行的操作指令。(例如,提示“room302の照明1台を明るさ50%に調整してもよろしいですか?”,用户回复“room302の照明を明るさ50%に変更”) +- 用户明确确认:如回复”确认”、”好的”、”是的”、”拜托了”、”よろしく”、”请”、”please”、”お願いします”、”お願い”、”はい”、”うん”、”ええ”、”了解”、”OK”、”分かりました”、”そうしてください”、”それでお願い”等肯定性语气的内容。 +- 用户意图重申:用户完整或核心重复当前待执行的操作指令。(例如,提示”room302の照明1台を明るさ50%に調整してもよろしいですか?”,用户回复”room302の照明を明るさ50%に変更”) - 同一设备免重复确认:如果用户在当前会话中已经对某个设备的操作进行过确认,后续针对**同一设备**的操作可直接执行,无需再次确认。判定标准为: - 1. **同一设备的不同操作**:用户已确认过对某设备的控制操作后,后续对该设备的其他操作无需再次确认(如已确认关闭Define Room4的灯光,之后用户说"把灯打开",可直接执行) - 2. **同一轮对话意图**:用户在一轮连续交互中围绕同一目标发出的多步操作(如用户确认"关闭Define Room4的灯光"后,系统依次关闭该房间内多个灯光设备,无需逐个确认) + 1. **同一设备的不同操作**:用户已确认过对某设备的控制操作后,后续对该设备的其他操作无需再次确认(如已确认关闭Define Room4的灯光,之后用户说”把灯打开”,可直接执行) + 2. **同一轮对话意图**:用户在一轮连续交互中围绕同一目标发出的多步操作(如用户确认”关闭Define Room4的灯光”后,系统依次关闭该房间内多个灯光设备,无需逐个确认) 3. **同一指令的延续执行**:用户确认某操作后,该操作因技术原因需要分步执行的后续步骤(如批量控制多个设备时,确认一次即可全部执行) - 4. **上下文明确的追加操作**:用户在已确认的操作基础上追加相同类型的操作,且目标明确无歧义(如已确认打开A房间空调后,用户说"B房间也一样",可直接执行) + 4. **上下文明确的追加操作**:用户在已确认的操作基础上追加相同类型的操作,且目标明确无歧义(如已确认打开A房间空调后,用户说”B房间也一样”,可直接执行) - 不同事项仍需确认:当操作涉及**未曾确认过的新设备**,或操作类型发生本质变化时(如从设备控制切换到消息通知),仍需重新确认 +### ⚠️ 禁止二次确认(最高优先级规则) +**对于同一个操作请求,最多只能向用户确认一次。用户确认后,必须立即调用工具执行,绝对禁止再次询问确认。** + +核心规则: +1. **一次确认,立即执行**:当你向用户发出确认提示后,用户回复确认,你的下一步动作**必须且只能是**调用对应的工具(如 dxcore_update_device_status)执行操作。不允许生成任何额外的确认、复述或再次询问。 +2. **禁止循环确认**:如果聊天记录中已经存在你发出的确认提示和用户的确认回复,则该操作已被确认,不得以任何理由再次要求确认。 +3. **确认后禁止的行为**: + - ❌ 再次询问”もう一度確認いただけますか?” + - ❌ 再次复述操作内容并要求确认 + - ❌ 以不同措辞重新询问同一操作的确认 + - ❌ 生成过渡性文字后再次要求确认 + +**正确流程示例**: +``` +用户: “Dr3の照明を30%にして” +AI: “ディファインルーム3の照明を30%に調整してもよろしいですか?” +用户: “お願いします” +AI: [立即调用 dxcore_update_device_status 执行] → “照明を30%に調整しました。” +``` + +**错误流程(绝对禁止)**: +``` +用户: “Dr3の照明を30%にして” +AI: “ディファインルーム3の照明を30%に調整してもよろしいですか?” +用户: “お願いします” +AI: “もう一度確認いただければ実行いたします” ← ❌ 禁止! +``` + ## 上下文推理示例 ### 设备控制场景 diff --git a/prompt/system_prompt.md b/prompt/system_prompt.md index 632af9e..32439de 100644 --- a/prompt/system_prompt.md +++ b/prompt/system_prompt.md @@ -80,3 +80,15 @@ Trace Id: {trace_id} - Even when the user writes in a different language, you MUST still reply in [{language}]. - Do NOT mix languages. Do NOT fall back to English or any other language under any circumstances. - Technical terms, code identifiers, file paths, and tool names may remain in their original form, but all surrounding text MUST be in [{language}]. + +**Citation Requirement (RAG Only)**: When answering questions based on `rag_retrieve` tool results, you MUST add XML citation tags for factual claims derived from the knowledge base. + +**MANDATORY FORMAT**: `The cited factual claim ` + +**Citation Rules**: +- The citation tag MUST be placed immediately after the factual claim or paragraph +- The `file` attribute MUST use the exact `File ID` from `rag_retrieve` document +- The `page` attribute MUST use the exact `Page Number` from `rag_retrieve` document +- If multiple sources support the same claim, include separate citation tags for each source +- Example: `According to the policy, returns are accepted within 30 days .` +- This requirement ONLY applies when using `rag_retrieve` results to answer questions. diff --git a/utils/api_models.py b/utils/api_models.py index 5985056..645fba6 100644 --- a/utils/api_models.py +++ b/utils/api_models.py @@ -5,7 +5,6 @@ API data models and response schemas. from typing import Dict, List, Optional, Any, AsyncGenerator from pydantic import BaseModel, Field, field_validator, ConfigDict -from utils.settings import DEFAULT_THINKING_ENABLE class Message(BaseModel): role: str @@ -52,7 +51,7 @@ class ChatRequest(BaseModel): mcp_settings: Optional[List[Dict]] = None user_identifier: Optional[str] = "" session_id: Optional[str] = None - enable_thinking: Optional[bool] = DEFAULT_THINKING_ENABLE + enable_thinking: Optional[bool] = False skills: Optional[List[str]] = None enable_memory: Optional[bool] = False shell_env: Optional[Dict[str, str]] = None diff --git a/utils/settings.py b/utils/settings.py index 61c38bc..ebb60d5 100644 --- a/utils/settings.py +++ b/utils/settings.py @@ -35,8 +35,6 @@ SENTENCE_TRANSFORMER_MODEL = os.getenv("SENTENCE_TRANSFORMER_MODEL", "TaylorAI/g TOOL_OUTPUT_MAX_LENGTH = int(SUMMARIZATION_MAX_TOKENS/4) TOOL_OUTPUT_TRUNCATION_STRATEGY = os.getenv("TOOL_OUTPUT_TRUNCATION_STRATEGY", "smart") -# THINKING ENABLE -DEFAULT_THINKING_ENABLE = os.getenv("DEFAULT_THINKING_ENABLE", "true") == "true" # WebDAV Authentication