mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-10-21 17:36:42 +02:00
fix(agents): restore task description when replanning fails (#8308)
This commit is contained in:
1 parent
78cc9d9e95
commit
add3f7bf1e
2 files changed
+20
-2
No files matched your search
@@ -2844,8 +2844,10 @@ class AgentExecutor(Flow[AgentExecutorState], BaseAgentExecutor):
|
||||
if self.task:
|
||||
original_description = self.task.description
|
||||
self.task.description = enhanced_description
|
||||
output = planning_handler.handle_agent_reasoning()
|
||||
self.task.description = original_description
|
||||
try:
|
||||
output = planning_handler.handle_agent_reasoning()
|
||||
finally:
|
||||
self.task.description = original_description
|
||||
else:
|
||||
# description is a read-only property — recreate with enhanced text
|
||||
input_text = getattr(self, "_kickoff_input", "")
|
||||
|
||||
@@ -2988,6 +2988,22 @@ class TestPlanGenerationIsolation:
|
||||
"generate_plan should store plan in state, not task.description"
|
||||
)
|
||||
|
||||
def test_failed_replan_restores_task_description(self):
|
||||
task = SimpleNamespace(description="What is the capital of France?")
|
||||
executor = _build_executor(
|
||||
agent=SimpleNamespace(verbose=False),
|
||||
task=task,
|
||||
)
|
||||
|
||||
with patch("crewai.utilities.reasoning_handler.AgentReasoning") as reasoning:
|
||||
reasoning.return_value.handle_agent_reasoning.side_effect = ValueError(
|
||||
"planner failed"
|
||||
)
|
||||
executor._trigger_replan("step 1 is blocked")
|
||||
|
||||
assert task.description == "What is the capital of France?"
|
||||
assert executor.state.last_replan_reason == "Replan failed: planner failed"
|
||||
|
||||
|
||||
# Todo Status Tracking
|
||||
|
||||
|
||||
Reference in new issue
Block a user