initializePlan
Initialize or fully replace a new task plan by defining its goal and structured tasks with dependencies and reasoning, enabling organized task management on MCPlanManager.
Instructions
初始化或完全替换一个新的任务计划。
Args: goal (str): 描述计划总体目标的字符串。 tasks (List[TaskInput]): 任务对象的列表。每个任务的结构如下: - name (str): 任务的名称,在一个计划中应唯一。 - dependencies (List[Union[str, int]]): 依赖的任务名称或ID列表。 - reasoning (str): 阐述为何需要此任务。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| goal | Yes | ||
| tasks | Yes |
Implementation Reference
- src/mcplanmanager/app.py:11-24 (handler)MCP tool handler for 'initializePlan'. Decorated with @mcp.tool(), validates inputs using Pydantic models, converts to dicts, and delegates to PlanManager.initializePlan.@mcp.tool() def initializePlan(goal: str, tasks: List[TaskInput]) -> ToolResponse[dict]: """ 初始化或完全替换一个新的任务计划。 Args: goal (str): 描述计划总体目标的字符串。 tasks (List[TaskInput]): 任务对象的列表。每个任务的结构如下: - name (str): 任务的名称,在一个计划中应唯一。 - dependencies (List[Union[str, int]]): 依赖的任务名称或ID列表。 - reasoning (str): 阐述为何需要此任务。 """ task_dicts = [task.model_dump() for task in tasks] return plan_manager.initializePlan(goal, task_dicts)
- src/mcplanmanager/app.py:11-11 (registration)Registration of the 'initializePlan' tool via FastMCP @mcp.tool() decorator.@mcp.tool()
- src/mcplanmanager/models.py:14-22 (schema)Pydantic model defining the schema for each task input to initializePlan (used as List[TaskInput]). Also defines ToolResponse for output.class TaskInput(BaseModel): """ 用于初始化计划时,定义单个任务输入的Pydantic模型。 这为Agent提供了一个清晰、可验证的数据结构。 """ name: str dependencies: List[Union[str, int]] reasoning: str
- Core implementation of plan initialization logic in PlanManager class, including task processing, dependency resolution, and circular dependency detection.def initializePlan(self, goal: str, tasks: List[Dict]) -> Dict: """ 初始化计划 """ if not tasks: return {"success": False, "message": "At least one task is required"} current_time = datetime.now().isoformat() # 重置计划数据 self.plan_data = { "meta": { "goal": goal, "created_at": current_time, "updated_at": current_time }, "state": { "current_task_id": None, "status": "idle" }, "tasks": [] } # 处理任务列表 try: # First pass: create tasks and map names to IDs processed_tasks, task_name_to_id = self._process_tasks_pass_one(tasks) # Second pass: resolve dependencies self._process_tasks_pass_two(tasks, processed_tasks, task_name_to_id) # Third pass: detect circular dependencies self._check_all_circular_dependencies(processed_tasks) except ValueError as e: return {"success": False, "message": str(e)} self.plan_data["tasks"] = processed_tasks self._update_timestamp() return { "success": True, "message": "Plan initialized successfully", "data": self.plan_data }
- src/mcplanmanager/models.py:5-12 (schema)Generic Pydantic model for tool output schema (ToolResponse[dict] for initializePlan).class ToolResponse(BaseModel, Generic[T]): """ 一个通用的工具响应模型,用于标准化所有工具的返回结构。 """ success: bool = Field(True, description="操作是否成功。") message: Optional[str] = Field(None, description="关于操作结果的可读消息。") data: Optional[T] = Field(None, description="操作返回的主要数据负载。")