1
0

note_tools.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from hello_agents.tools.builtin.note_tool import NoteTool
  2. class LearningNotesService:
  3. def __init__(self, workspace: str):
  4. self.note_tool = NoteTool(workspace=workspace)
  5. def save_learning_progress(
  6. self,
  7. user_id: str,
  8. progress: "LearningProgress"
  9. ):
  10. """保存学习路径与进度"""
  11. content = self._format_learning_content(progress)
  12. self.note_tool.run({
  13. "action": "create",
  14. "title": f"学习进度|{progress.topic}",
  15. "content": content,
  16. "tags": [
  17. "learning",
  18. "progress",
  19. progress.level,
  20. user_id
  21. ]
  22. })
  23. def _format_learning_content(self, progress: "LearningProgress") -> str:
  24. content = f"# 学习主题:{progress.topic}\n\n"
  25. content += f"**当前水平**:{progress.level}\n\n"
  26. # 学习路径
  27. content += "## 学习路径\n\n"
  28. for idx, step in enumerate(progress.steps, start=1):
  29. status_icon = {
  30. "completed": "✅",
  31. "in_progress": "⏳",
  32. "not_started": "⬜"
  33. }.get(step.status, "⬜")
  34. content += f"{idx}. {status_icon} **{step.title}**\n"
  35. if step.notes:
  36. content += f" - 备注:{step.notes}\n"
  37. content += "\n"
  38. # 掌握点
  39. if progress.mastered_points:
  40. content += "## 已掌握知识点\n\n"
  41. for p in progress.mastered_points:
  42. content += f"- ✅ {p}\n"
  43. content += "\n"
  44. # 薄弱点
  45. if progress.weak_points:
  46. content += "## 薄弱点\n\n"
  47. for p in progress.weak_points:
  48. content += f"- ⚠️ {p}\n"
  49. content += "\n"
  50. # 下一步建议
  51. content += "## 下一步学习建议\n\n"
  52. content += f"{progress.next_suggestion}\n"
  53. return content