Files
Summer Shen 9578366e36 init repo
2026-03-31 09:14:32 +08:00

37 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 1. 项目基础设施
- [x] 1.1 在 `pyproject.toml` 中添加依赖:`llama-index-core``llama-index-llms-openai``python-frontmatter`
- [x] 1.2 创建模块文件结构:`src/llama_agent_skills/skill.py``registry.py``agent.py``config.py`
- [x] 1.3 在 `config.py` 中实现配置管理:LLM API key(环境变量)、默认 SKILL 目录路径、基础 system prompt
## 2. Skill 数据模型与解析器(skill.py
- [x] 2.1 实现 `Skill` 数据类(frozen dataclass),包含字段:`name``description``body``metadata``source_path`
- [x] 2.2 实现 `SkillLoadError` 自定义异常类
- [x] 2.3 实现 `load_skill(path: Path) -> Skill` 函数:使用 `python-frontmatter` 解析 SKILL.md,校验必填字段(name、description),提取 metadata 并构造 Skill 实例
- [x] 2.4 处理解析错误场景:缺少 frontmatter、缺少必填字段、文件不存在,均抛出 `SkillLoadError`
## 3. SKILL 注册表(registry.py
- [x] 3.1 实现 `SkillRegistry` 类,包含 `register(skill)``unregister(name)``get(name)``list_skills()` 方法
- [x] 3.2 实现 `scan_directory(path: Path) -> list[Skill]` 函数:遍历目录下所有 `*/SKILL.md` 文件,调用 `load_skill` 解析,跳过无效文件并记录日志
- [x] 3.3 实现 `SkillRegistry.load_from_directory(path)` 便捷方法:调用 `scan_directory` 并批量注册
## 4. Agent 核心(agent.py
- [x] 4.1 实现 `build_system_prompt(base_prompt: str, skills: list[Skill]) -> str` 函数:按设计文档中的格式将 SKILL 内容拼接到 system prompt
- [x] 4.2 实现 `create_agent(skills, tools, llm_config) -> AgentWorkflow` 函数:使用 `AgentWorkflow.from_tools_or_functions()` 创建 Agent,传入组装后的 system prompt 和工具列表
- [x] 4.3 实现 `run_agent(agent, message) -> str` 异步函数:接受用户输入,运行 Agent 并返回响应文本
## 5. 入口整合(__init__.py
- [x] 5.1 改造 `main()` 函数:从配置读取 SKILL 目录,创建 SkillRegistry 并加载 SKILL,构建 Agent,进入交互式对话循环
- [x] 5.2 支持命令行参数或环境变量指定 SKILL 目录路径和 LLM 模型名称
## 6. 验证与测试
- [x] 6.1 使用项目中现有的 `.opencode/skills/` 目录下的 SKILL.md 文件作为测试数据,验证 skill loader 能正确解析所有 4 个 SKILL
- [x] 6.2 验证 SkillRegistry 的注册、注销、列表功能
- [x] 6.3 验证 Agent 创建后的 system prompt 包含所有已加载 SKILL 的内容
- [x] 6.4 端到端测试:加载 SKILL → 创建 Agent → 发送消息 → 获取响应