|
102 | 102 | TaskDecomposedEvent, |
103 | 103 | TaskFailedEvent, |
104 | 104 | TaskStartedEvent, |
| 105 | + TaskUpdatedEvent, |
105 | 106 | WorkerCreatedEvent, |
106 | 107 | ) |
107 | 108 |
|
@@ -1673,8 +1674,30 @@ async def _apply_recovery_strategy( |
1673 | 1674 | elif strategy == RecoveryStrategy.REPLAN: |
1674 | 1675 | # Modify the task content and retry |
1675 | 1676 | if recovery_decision.modified_task_content: |
1676 | | - task.content = recovery_decision.modified_task_content |
1677 | | - logger.info(f"Task {task.id} content modified for replan") |
| 1677 | + old_content = task.content |
| 1678 | + new_content = recovery_decision.modified_task_content |
| 1679 | + |
| 1680 | + task.content = new_content |
| 1681 | + logger.info( |
| 1682 | + f"Task {task.id} content modified for replan, " |
| 1683 | + f"new_content: {new_content}" |
| 1684 | + ) |
| 1685 | + |
| 1686 | + task_updated_event = TaskUpdatedEvent( |
| 1687 | + task_id=task.id, |
| 1688 | + parent_task_id=task.parent.id if task.parent else None, |
| 1689 | + worker_id=task.assigned_worker_id, |
| 1690 | + update_type="replan", |
| 1691 | + old_value=old_content, |
| 1692 | + new_value=new_content, |
| 1693 | + metadata={ |
| 1694 | + "quality_score": recovery_decision.quality_score, |
| 1695 | + "reasoning": recovery_decision.reasoning, |
| 1696 | + "issues": recovery_decision.issues, |
| 1697 | + }, |
| 1698 | + ) |
| 1699 | + for cb in self._callbacks: |
| 1700 | + cb.log_task_updated(task_updated_event) |
1678 | 1701 |
|
1679 | 1702 | # Repost the modified task to the same worker |
1680 | 1703 | await self._post_task(task, original_assignee) |
@@ -1717,6 +1740,22 @@ async def _apply_recovery_strategy( |
1717 | 1740 | f"{new_worker}" |
1718 | 1741 | ) |
1719 | 1742 |
|
| 1743 | + task_updated_event = TaskUpdatedEvent( |
| 1744 | + task_id=task.id, |
| 1745 | + parent_task_id=task.parent.id if task.parent else None, |
| 1746 | + worker_id=task.assigned_worker_id, |
| 1747 | + update_type="reassign", |
| 1748 | + old_value=old_worker, |
| 1749 | + new_value=new_worker, |
| 1750 | + metadata={ |
| 1751 | + "quality_score": recovery_decision.quality_score, |
| 1752 | + "reasoning": recovery_decision.reasoning, |
| 1753 | + "issues": recovery_decision.issues, |
| 1754 | + }, |
| 1755 | + ) |
| 1756 | + for cb in self._callbacks: |
| 1757 | + cb.log_task_updated(task_updated_event) |
| 1758 | + |
1720 | 1759 | elif strategy == RecoveryStrategy.DECOMPOSE: |
1721 | 1760 | # Decompose the task into subtasks |
1722 | 1761 | reason = ( |
@@ -2056,8 +2095,21 @@ def modify_task_content(self, task_id: str, new_content: str) -> bool: |
2056 | 2095 |
|
2057 | 2096 | for task in self._pending_tasks: |
2058 | 2097 | if task.id == task_id: |
| 2098 | + old_content = task.content |
2059 | 2099 | task.content = new_content |
2060 | 2100 | logger.info(f"Task {task_id} content modified.") |
| 2101 | + |
| 2102 | + task_updated_event = TaskUpdatedEvent( |
| 2103 | + task_id=task.id, |
| 2104 | + parent_task_id=task.parent.id if task.parent else None, |
| 2105 | + worker_id=task.assigned_worker_id, |
| 2106 | + update_type="manual", |
| 2107 | + old_value=old_content, |
| 2108 | + new_value=new_content, |
| 2109 | + ) |
| 2110 | + for cb in self._callbacks: |
| 2111 | + cb.log_task_updated(task_updated_event) |
| 2112 | + |
2061 | 2113 | return True |
2062 | 2114 | logger.warning(f"Task {task_id} not found in pending tasks.") |
2063 | 2115 | return False |
|
0 commit comments