| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import json
- from agent.tools import tool
- from utils.log_capture import log, log_fold
- def _log_tool_call(tool_name: str, params: dict, result: str) -> None:
- """以折叠块结构化输出工具调用的参数与返回内容(经 log() 进入 build_log buffer)。"""
- with log_fold(f"🔧 {tool_name}"):
- with log_fold("📥 调用参数"):
- log(json.dumps(params, ensure_ascii=False, indent=2))
- with log_fold("📤 返回内容"):
- log(result)
- @tool(
- description="系统化思考与规划工具。不会获取新信息或更改数据库,只用于记录思考过程。",
- )
- def think_and_plan(thought: str, thought_number: int, action: str, plan: str) -> str:
- """这是用于系统化思考与规划的工具,支持在面对复杂选题构建任务时分阶段梳理思考、规划和行动步骤。该工具不会获取新信息或更改数据库,只会将想法附加到记忆中。
- Args:
- thought: 当前的思考内容,可以是对问题的分析、假设、洞见、反思或对前一步骤的总结。
- thought_number: 当前思考步骤的编号,用于追踪和回溯整个思考与规划过程。
- action: 基于当前思考和计划,建议下一步采取的行动步骤。
- plan: 针对当前任务拟定的计划或方案。
- Returns:
- A string describing the thought, plan, and action steps.
- """
- params = {
- "thought": thought,
- "thought_number": thought_number,
- "action": action,
- "plan": plan,
- }
- result = (
- f"[思考 #{thought_number}]\n"
- f"思考: {thought}\n"
- f"计划: {plan}\n"
- f"下一步: {action}\n"
- f"(此工具仅用于记录思考过程,不会修改任何数据)"
- )
- _log_tool_call("think_and_plan", params, result)
- return result
|