From ff3781b0fb0d4811735fc5aba5c53201f4aa5baf Mon Sep 17 00:00:00 2001 From: Zander Hill <zander@xargs.io> Date: Sun, 2 Mar 2025 14:42:35 -0800 Subject: [PATCH] Fix issue with task_summary breaking if planning=True With specific definitions of agents the task_summary fails with an error related to `t` being an invalid format specifyer due to the way the string formatting works in planning_handler.py This breaks the format of outputs but builds the output in a manner not at risk of breaking due to mixing interpolation styles in python strings. --- src/crewai/utilities/planning_handler.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/crewai/utilities/planning_handler.py b/src/crewai/utilities/planning_handler.py index 6ce74f236f..303c0dc1af 100644 --- a/src/crewai/utilities/planning_handler.py +++ b/src/crewai/utilities/planning_handler.py @@ -96,6 +96,14 @@ def _create_tasks_summary(self) -> str: tasks_summary = [] for idx, task in enumerate(self.tasks): knowledge_list = self._get_agent_knowledge(task) + agent_tools = task.agent.tools if task.agent else [] + if agent_tools is None: + agent_tools = [] + if knowledge_list is None: + knowledge_list = [] + + knowledge_summary = [str(k) for k in knowledge_list if k is not None] + task_summary = f""" Task Number {idx + 1} - {task.description} "task_description": {task.description} @@ -103,10 +111,8 @@ def _create_tasks_summary(self) -> str: "agent": {task.agent.role if task.agent else "None"} "agent_goal": {task.agent.goal if task.agent else "None"} "task_tools": {task.tools} - "agent_tools": %s%s""" % ( - f"[{', '.join(str(tool) for tool in task.agent.tools)}]" if task.agent and task.agent.tools else '"agent has no tools"', - f',\n "agent_knowledge": "[\\"{knowledge_list[0]}\\"]"' if knowledge_list and str(knowledge_list) != "None" else "" - ) + "agent_tools": {', '.join(str(t) for t in agent_tools)} + "agent_knowledge": {', '.join(str(k) for k in knowledge_summary)}""" tasks_summary.append(task_summary) return " ".join(tasks_summary)