Commit 014b0587 by sunqi02

框架部分plan文件更新执行状态

1 parent 9732e618
# Skill 与 Tool 系统实施计划 # Skill 与 Tool 系统实施计划
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [x]`) syntax for tracking.
**Goal:** 实现 Skill Scanner(技能文件扫描生成 skills.json 索引)和 Tool Manager(工具注册 + ReAct 执行循环),集成到 AgentHub。 **Goal:** 实现 Skill Scanner(技能文件扫描生成 skills.json 索引)和 Tool Manager(工具注册 + ReAct 执行循环),集成到 AgentHub。
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
**Files:** **Files:**
- Modify: `app/config/settings.py` - Modify: `app/config/settings.py`
- [ ] **Step 1: 添加 location 字段** - [x] **Step 1: 添加 location 字段**
```python ```python
class SkillConfig(BaseModel): class SkillConfig(BaseModel):
...@@ -40,14 +40,14 @@ class SkillConfig(BaseModel): ...@@ -40,14 +40,14 @@ class SkillConfig(BaseModel):
location: str = "" # 技能目录路径,如 "skills/meeting_minutes" location: str = "" # 技能目录路径,如 "skills/meeting_minutes"
``` ```
- [ ] **Step 2: 验证现有代码兼容性** - [x] **Step 2: 验证现有代码兼容性**
现有 `ConfigLoader.load_skills()` 从 `skills.json` 反序列化 `SkillConfig`。当前 `skills.json` 没有 `location` 字段,Pydantic 使用默认值 `""` 向后兼容。 现有 `ConfigLoader.load_skills()` 从 `skills.json` 反序列化 `SkillConfig`。当前 `skills.json` 没有 `location` 字段,Pydantic 使用默认值 `""` 向后兼容。
Run: `python -c "from app.config.settings import SkillConfig; s = SkillConfig(code='test', name='t', description='d', instruction='i'); print(s.location)"` Run: `python -c "from app.config.settings import SkillConfig; s = SkillConfig(code='test', name='t', description='d', instruction='i'); print(s.location)"`
Expected: 输出空字符串 Expected: 输出空字符串
- [ ] **Step 3: Commit** - [x] **Step 3: Commit**
```bash ```bash
git add app/config/settings.py git add app/config/settings.py
...@@ -61,7 +61,7 @@ git commit -m "feat: add location field to SkillConfig model" ...@@ -61,7 +61,7 @@ git commit -m "feat: add location field to SkillConfig model"
**Files:** **Files:**
- Create: `app/service/skill_scanner.py` - Create: `app/service/skill_scanner.py`
- [ ] **Step 1: 编写 scan_skills 函数** - [x] **Step 1: 编写 scan_skills 函数**
```python ```python
import logging import logging
...@@ -141,7 +141,7 @@ def scan_skills(skills_dir: Path) -> Dict[str, SkillConfig]: ...@@ -141,7 +141,7 @@ def scan_skills(skills_dir: Path) -> Dict[str, SkillConfig]:
return skills return skills
``` ```
- [ ] **Step 2: 编写 update_skills_json 函数** - [x] **Step 2: 编写 update_skills_json 函数**
```python ```python
import json import json
...@@ -165,12 +165,12 @@ def update_skills_json(skills_dir: Path, config_dir: Path) -> None: ...@@ -165,12 +165,12 @@ def update_skills_json(skills_dir: Path, config_dir: Path) -> None:
logger.info(f"skills.json 已更新: {len(skills)} 个技能") logger.info(f"skills.json 已更新: {len(skills)} 个技能")
``` ```
- [ ] **Step 3: 验证模块可导入** - [x] **Step 3: 验证模块可导入**
Run: `PYTHONPATH=. python -c "from app.service.skill_scanner import scan_skills, update_skills_json; print('OK')"` Run: `PYTHONPATH=. python -c "from app.service.skill_scanner import scan_skills, update_skills_json; print('OK')"`
Expected: `OK` Expected: `OK`
- [ ] **Step 4: Commit** - [x] **Step 4: Commit**
```bash ```bash
git add app/service/skill_scanner.py git add app/service/skill_scanner.py
...@@ -184,7 +184,7 @@ git commit -m "feat: add skill_scanner module with scan_skills and update_skills ...@@ -184,7 +184,7 @@ git commit -m "feat: add skill_scanner module with scan_skills and update_skills
**Files:** **Files:**
- Modify: `app/main.py` - Modify: `app/main.py`
- [ ] **Step 1: 在 lifespan startup 中调用 update_skills_json** - [x] **Step 1: 在 lifespan startup 中调用 update_skills_json**
在 `lifespan` 函数的 `Base.metadata.create_all(bind=engine)` 之后、`config_loader = ConfigLoader()` 之前插入: 在 `lifespan` 函数的 `Base.metadata.create_all(bind=engine)` 之后、`config_loader = ConfigLoader()` 之前插入:
...@@ -201,17 +201,17 @@ config_dir = Path(__file__).parent.parent / "config" ...@@ -201,17 +201,17 @@ config_dir = Path(__file__).parent.parent / "config"
update_skills_json(skills_dir, config_dir) update_skills_json(skills_dir, config_dir)
``` ```
- [ ] **Step 2: 启动验证** - [x] **Step 2: 启动验证**
Run: `PYTHONPATH=. python -m app.main` (等待 startup 完成,然后 Ctrl+C) Run: `PYTHONPATH=. python -m app.main` (等待 startup 完成,然后 Ctrl+C)
Expected: 日志输出 `skills.json 已更新: 4 个技能` Expected: 日志输出 `skills.json 已更新: 4 个技能`
- [ ] **Step 3: 验证 skills.json 已更新,包含 location 字段** - [x] **Step 3: 验证 skills.json 已更新,包含 location 字段**
Run: `python -c "import json; d=json.load(open('config/skills.json')); s=list(d['skills'].values())[0]; print('location' in s, s.get('location'))"` Run: `python -c "import json; d=json.load(open('config/skills.json')); s=list(d['skills'].values())[0]; print('location' in s, s.get('location'))"`
Expected: `True skills/buddy-sings` (或其他技能目录名) Expected: `True skills/buddy-sings` (或其他技能目录名)
- [ ] **Step 4: Commit** - [x] **Step 4: Commit**
```bash ```bash
git add app/main.py git add app/main.py
...@@ -225,7 +225,7 @@ git commit -m "feat: call update_skills_json on app startup" ...@@ -225,7 +225,7 @@ git commit -m "feat: call update_skills_json on app startup"
**Files:** **Files:**
- Modify: `app/config/settings.py` - Modify: `app/config/settings.py`
- [ ] **Step 1: 添加 ToolConfig 和 ToolGroup 模型** - [x] **Step 1: 添加 ToolConfig 和 ToolGroup 模型**
在 `app/config/settings.py` 末尾追加: 在 `app/config/settings.py` 末尾追加:
...@@ -247,13 +247,13 @@ class ToolGroup(BaseModel): ...@@ -247,13 +247,13 @@ class ToolGroup(BaseModel):
description: str = "" description: str = ""
``` ```
- [ ] **Step 2: 验证模型** - [x] **Step 2: 验证模型**
Run: `python -c "from app.config.settings import ToolConfig, ToolGroup; tc = ToolConfig(name='test', description='d', input_schema={'type': 'object', 'properties': {}}); tg = ToolGroup(name='basic', active=True); print(tc.source, tg.active)"` Run: `python -c "from app.config.settings import ToolConfig, ToolGroup; tc = ToolConfig(name='test', description='d', input_schema={'type': 'object', 'properties': {}}); tg = ToolGroup(name='basic', active=True); print(tc.source, tg.active)"`
Expected: `function True` Expected: `function True`
- [ ] **Step 3: Commit** - [x] **Step 3: Commit**
```bash ```bash
git add app/config/settings.py git add app/config/settings.py
...@@ -267,7 +267,7 @@ git commit -m "feat: add ToolConfig and ToolGroup data models" ...@@ -267,7 +267,7 @@ git commit -m "feat: add ToolConfig and ToolGroup data models"
**Files:** **Files:**
- Create: `app/service/tool_manager.py` - Create: `app/service/tool_manager.py`
- [ ] **Step 1: 编写 ToolManager 异常类和基础结构** - [x] **Step 1: 编写 ToolManager 异常类和基础结构**
```python ```python
import inspect import inspect
...@@ -295,7 +295,7 @@ class ToolExecutionError(Exception): ...@@ -295,7 +295,7 @@ class ToolExecutionError(Exception):
pass pass
``` ```
- [ ] **Step 2: 编写 _parse_func_schema 辅助函数** - [x] **Step 2: 编写 _parse_func_schema 辅助函数**
```python ```python
_TYPE_MAP = { _TYPE_MAP = {
...@@ -347,7 +347,7 @@ def _parse_func_schema(func: Callable, description: Optional[str] = None) -> dic ...@@ -347,7 +347,7 @@ def _parse_func_schema(func: Callable, description: Optional[str] = None) -> dic
} }
``` ```
- [ ] **Step 3: 编写 ToolManager 类(register_tool、call_tool、get_tool_schemas)** - [x] **Step 3: 编写 ToolManager 类(register_tool、call_tool、get_tool_schemas)**
```python ```python
class ToolManager: class ToolManager:
...@@ -447,12 +447,12 @@ class ToolManager: ...@@ -447,12 +447,12 @@ class ToolManager:
return decorator return decorator
``` ```
- [ ] **Step 4: 验证模块可导入** - [x] **Step 4: 验证模块可导入**
Run: `PYTHONPATH=. python -c "from app.service.tool_manager import ToolManager; tm = ToolManager(); print(len(tm.groups))"` Run: `PYTHONPATH=. python -c "from app.service.tool_manager import ToolManager; tm = ToolManager(); print(len(tm.groups))"`
Expected: `1` Expected: `1`
- [ ] **Step 5: Commit** - [x] **Step 5: Commit**
```bash ```bash
git add app/service/tool_manager.py git add app/service/tool_manager.py
...@@ -466,7 +466,7 @@ git commit -m "feat: add ToolManager with register/call/schema/group support" ...@@ -466,7 +466,7 @@ git commit -m "feat: add ToolManager with register/call/schema/group support"
**Files:** **Files:**
- Modify: `app/service/agent_hub.py` - Modify: `app/service/agent_hub.py`
- [ ] **Step 1: 导入 ToolManager,在 __init__ 中初始化** - [x] **Step 1: 导入 ToolManager,在 __init__ 中初始化**
在 `agent_hub.py` 顶部添加导入: 在 `agent_hub.py` 顶部添加导入:
...@@ -480,7 +480,7 @@ from app.service.tool_manager import ToolManager ...@@ -480,7 +480,7 @@ from app.service.tool_manager import ToolManager
self.tool_manager = ToolManager() self.tool_manager = ToolManager()
``` ```
- [ ] **Step 2: 将 _call_model 替换为支持 messages + tools + ReAct 循环的版本** - [x] **Step 2: 将 _call_model 替换为支持 messages + tools + ReAct 循环的版本**
替换 `_call_model` 方法: 替换 `_call_model` 方法:
...@@ -562,7 +562,7 @@ async def _call_model( ...@@ -562,7 +562,7 @@ async def _call_model(
raise AgentHubError("ReAct循环超过最大次数(10)") raise AgentHubError("ReAct循环超过最大次数(10)")
``` ```
- [ ] **Step 3: 修改 process_message 以构建 messages 列表而不是单字符串** - [x] **Step 3: 修改 process_message 以构建 messages 列表而不是单字符串**
`process_message` 中,将: `process_message` 中,将:
...@@ -598,14 +598,14 @@ response_content = await self._call_model( ...@@ -598,14 +598,14 @@ response_content = await self._call_model(
`_build_history_section` 现在只在 `process_message` 中使用。既然改为 messages 列表方式,`_build_history_section` 不再被调用。保留该方法(未来可能用于日志/调试),但不影响功能。 `_build_history_section` 现在只在 `process_message` 中使用。既然改为 messages 列表方式,`_build_history_section` 不再被调用。保留该方法(未来可能用于日志/调试),但不影响功能。
- [ ] **Step 4: 验证向后兼容(无工具时行为不变)** - [x] **Step 4: 验证向后兼容(无工具时行为不变)**
现有的测试中 `test_hub` 的 `_call_model` 被 mock 了,所以签名变化不影响测试。但需要确认 `process_message` 传入的 messages 列表格式正确。 现有的测试中 `test_hub` 的 `_call_model` 被 mock 了,所以签名变化不影响测试。但需要确认 `process_message` 传入的 messages 列表格式正确。
Run: `PYTHONPATH=. python -m pytest tests/test_agent_hub.py -v --tb=short` Run: `PYTHONPATH=. python -m pytest tests/test_agent_hub.py -v --tb=short`
Expected: 全部 21 个测试通过 Expected: 全部 21 个测试通过
- [ ] **Step 5: Commit** - [x] **Step 5: Commit**
```bash ```bash
git add app/service/agent_hub.py git add app/service/agent_hub.py
...@@ -619,7 +619,7 @@ git commit -m "feat: integrate ToolManager with ReAct loop into AgentHub._call_m ...@@ -619,7 +619,7 @@ git commit -m "feat: integrate ToolManager with ReAct loop into AgentHub._call_m
**Files:** **Files:**
- Create: `tests/test_skill_scanner.py` - Create: `tests/test_skill_scanner.py`
- [ ] **Step 1: 编写测试** - [x] **Step 1: 编写测试**
```python ```python
import json import json
...@@ -744,12 +744,12 @@ class TestUpdateSkillsJson: ...@@ -744,12 +744,12 @@ class TestUpdateSkillsJson:
assert "技能 alpha 的说明" in data["skills"]["alpha"]["instruction"] assert "技能 alpha 的说明" in data["skills"]["alpha"]["instruction"]
``` ```
- [ ] **Step 2: 运行测试** - [x] **Step 2: 运行测试**
Run: `PYTHONPATH=. python -m pytest tests/test_skill_scanner.py -v` Run: `PYTHONPATH=. python -m pytest tests/test_skill_scanner.py -v`
Expected: 全部 7 个测试通过 Expected: 全部 7 个测试通过
- [ ] **Step 3: Commit** - [x] **Step 3: Commit**
```bash ```bash
git add tests/test_skill_scanner.py git add tests/test_skill_scanner.py
...@@ -763,7 +763,7 @@ git commit -m "test: add skill_scanner unit tests (7 tests)" ...@@ -763,7 +763,7 @@ git commit -m "test: add skill_scanner unit tests (7 tests)"
**Files:** **Files:**
- Create: `tests/test_tool_manager.py` - Create: `tests/test_tool_manager.py`
- [ ] **Step 1: 编写 ToolManager 测试** - [x] **Step 1: 编写 ToolManager 测试**
```python ```python
import pytest import pytest
...@@ -930,12 +930,12 @@ class TestToolManagerGroups: ...@@ -930,12 +930,12 @@ class TestToolManagerGroups:
assert tm.groups["basic"].active is True assert tm.groups["basic"].active is True
``` ```
- [ ] **Step 2: 运行测试** - [x] **Step 2: 运行测试**
Run: `PYTHONPATH=. python -m pytest tests/test_tool_manager.py -v` Run: `PYTHONPATH=. python -m pytest tests/test_tool_manager.py -v`
Expected: 全部 12 个测试通过 Expected: 全部 12 个测试通过
- [ ] **Step 3: Commit** - [x] **Step 3: Commit**
```bash ```bash
git add tests/test_tool_manager.py git add tests/test_tool_manager.py
...@@ -946,22 +946,22 @@ git commit -m "test: add ToolManager unit tests (12 tests)" ...@@ -946,22 +946,22 @@ git commit -m "test: add ToolManager unit tests (12 tests)"
### Task 9: 最终验证与收尾 ### Task 9: 最终验证与收尾
- [ ] **Step 1: 运行全部测试** - [x] **Step 1: 运行全部测试**
Run: `PYTHONPATH=. python -m pytest tests/ -v --tb=short` Run: `PYTHONPATH=. python -m pytest tests/ -v --tb=short`
Expected: 全部测试通过(原有 21 + 新增 7 + 新增 12 = 40 个测试) Expected: 全部测试通过(原有 21 + 新增 7 + 新增 12 = 40 个测试)
- [ ] **Step 2: 验证 skills.json 最新状态** - [x] **Step 2: 验证 skills.json 最新状态**
Run: `python -c "import json; d=json.load(open('config/skills.json')); [print(f'{k}: location={v[\"location\"]}') for k,v in d['skills'].items()]"` Run: `python -c "import json; d=json.load(open('config/skills.json')); [print(f'{k}: location={v[\"location\"]}') for k,v in d['skills'].items()]"`
Expected: 输出 4 个技能的 code 和 location Expected: 输出 4 个技能的 code 和 location
- [ ] **Step 3: 验证启动无异常** - [x] **Step 3: 验证启动无异常**
Run: `PYTHONPATH=. timeout 5 python -m app.main 2>&1 || true` Run: `PYTHONPATH=. timeout 5 python -m app.main 2>&1 || true`
Expected: 日志中显示 `skills.json 已更新` 且无报错 Expected: 日志中显示 `skills.json 已更新` 且无报错
- [ ] **Step 4: Commit 收尾(如有 skills.json 变更)** - [x] **Step 4: Commit 收尾(如有 skills.json 变更)**
```bash ```bash
git add config/skills.json git add config/skills.json
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!