notes.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Helpers for coordinating note tool usage instructions."""
  2. from __future__ import annotations
  3. import json
  4. from models import TodoItem
  5. def build_note_guidance(task: TodoItem) -> str:
  6. """Generate note tool usage guidance for a specific task."""
  7. tags_list = ["deep_research", f"task_{task.id}"]
  8. tags_literal = json.dumps(tags_list, ensure_ascii=False)
  9. if task.note_id:
  10. read_payload = json.dumps({"action": "read", "note_id": task.note_id}, ensure_ascii=False)
  11. update_payload = json.dumps(
  12. {
  13. "action": "update",
  14. "note_id": task.note_id,
  15. "task_id": task.id,
  16. "title": f"任务 {task.id}: {task.title}",
  17. "note_type": "task_state",
  18. "tags": tags_list,
  19. "content": "请将本轮新增信息补充到任务概览中",
  20. },
  21. ensure_ascii=False,
  22. )
  23. return (
  24. "笔记协作指引:\n"
  25. f"- 当前任务笔记 ID:{task.note_id}。\n"
  26. f"- 在书写总结前必须调用:[TOOL_CALL:note:{read_payload}] 获取最新内容。\n"
  27. f"- 完成分析后调用:[TOOL_CALL:note:{update_payload}] 同步增量信息。\n"
  28. "- 更新时保持原有段落结构,新增内容请在对应段落中补充。\n"
  29. f"- 建议 tags 保持为 {tags_literal},保证其他 Agent 可快速定位。\n"
  30. "- 成功同步到笔记后,再输出面向用户的总结。\n"
  31. )
  32. create_payload = json.dumps(
  33. {
  34. "action": "create",
  35. "task_id": task.id,
  36. "title": f"任务 {task.id}: {task.title}",
  37. "note_type": "task_state",
  38. "tags": tags_list,
  39. "content": "请记录任务概览、来源概览",
  40. },
  41. ensure_ascii=False,
  42. )
  43. return (
  44. "笔记协作指引:\n"
  45. f"- 当前任务尚未建立笔记,请先调用:[TOOL_CALL:note:{create_payload}]。\n"
  46. "- 创建成功后记录返回的 note_id,并在后续所有更新中复用。\n"
  47. "- 同步笔记后,再输出面向用户的总结。\n"
  48. )