think_and_plan.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from agent.tools import tool
  2. from utils.tool_logging import format_tool_result_for_log, log_tool_call
  3. @tool(
  4. description="系统化思考与规划工具。不会获取新信息或更改数据库,只用于记录思考过程。",
  5. )
  6. def think_and_plan(thought: str, thought_number: int, action: str, plan: str) -> str:
  7. """这是用于系统化思考与规划的工具,支持在面对复杂选题构建任务时分阶段梳理思考、规划和行动步骤。该工具不会获取新信息或更改数据库,只会将想法附加到记忆中。
  8. Args:
  9. thought: 当前的思考内容,可以是对问题的分析、假设、洞见、反思或对前一步骤的总结。
  10. thought_number: 当前思考步骤的编号,用于追踪和回溯整个思考与规划过程。
  11. action: 基于当前思考和计划,建议下一步采取的行动步骤。
  12. plan: 针对当前任务拟定的计划或方案。
  13. Returns:
  14. A string describing the thought, plan, and action steps.
  15. """
  16. params = {
  17. "thought": thought,
  18. "thought_number": thought_number,
  19. "action": action,
  20. "plan": plan,
  21. }
  22. result = (
  23. f"[思考 #{thought_number}]\n"
  24. f"思考: {thought}\n"
  25. f"计划: {plan}\n"
  26. f"下一步: {action}\n"
  27. f"(此工具仅用于记录思考过程,不会修改任何数据)"
  28. )
  29. log_tool_call("think_and_plan", params, format_tool_result_for_log(result))
  30. return result