feat:任务大纲停止以及执行结果暂停继续逻辑完善
This commit is contained in:
@@ -270,6 +270,12 @@ def Handle_executePlanOptimized():
|
||||
- 无依赖关系的动作并行执行
|
||||
- 有依赖关系的动作串行执行
|
||||
|
||||
支持参数:
|
||||
plan: 执行计划
|
||||
num_StepToRun: 要运行的步骤数
|
||||
RehearsalLog: 已执行的历史记录
|
||||
existingKeyObjects: 已存在的KeyObjects(用于重新执行时传递中间结果)
|
||||
|
||||
前端使用 EventSource 接收
|
||||
"""
|
||||
incoming_data = request.get_json()
|
||||
@@ -281,6 +287,7 @@ def Handle_executePlanOptimized():
|
||||
num_StepToRun=incoming_data.get("num_StepToRun"),
|
||||
RehearsalLog=incoming_data.get("RehearsalLog", []),
|
||||
AgentProfile_Dict=AgentProfile_Dict,
|
||||
existingKeyObjects=incoming_data.get("existingKeyObjects"),
|
||||
):
|
||||
yield chunk
|
||||
except Exception as e:
|
||||
@@ -405,7 +412,7 @@ def handle_ping():
|
||||
def handle_execute_plan_optimized_ws(data):
|
||||
"""
|
||||
WebSocket版本:优化版流式执行计划
|
||||
支持步骤级流式 + 动作级智能并行
|
||||
支持步骤级流式 + 动作级智能并行 + 动态追加步骤
|
||||
|
||||
请求格式:
|
||||
{
|
||||
@@ -414,7 +421,8 @@ def handle_execute_plan_optimized_ws(data):
|
||||
"data": {
|
||||
"plan": {...},
|
||||
"num_StepToRun": null,
|
||||
"RehearsalLog": []
|
||||
"RehearsalLog": [],
|
||||
"enable_dynamic": true # 是否启用动态追加步骤
|
||||
}
|
||||
}
|
||||
"""
|
||||
@@ -425,27 +433,66 @@ def handle_execute_plan_optimized_ws(data):
|
||||
plan = incoming_data.get("plan")
|
||||
num_StepToRun = incoming_data.get("num_StepToRun")
|
||||
RehearsalLog = incoming_data.get("RehearsalLog", [])
|
||||
enable_dynamic = incoming_data.get("enable_dynamic", False)
|
||||
|
||||
# 使用原有的流式执行函数
|
||||
for chunk in executePlan_streaming(
|
||||
plan=plan,
|
||||
num_StepToRun=num_StepToRun,
|
||||
RehearsalLog=RehearsalLog,
|
||||
AgentProfile_Dict=AgentProfile_Dict,
|
||||
):
|
||||
# 通过WebSocket推送进度
|
||||
# 如果前端传入了execution_id,使用前端的;否则生成新的
|
||||
execution_id = incoming_data.get("execution_id")
|
||||
if not execution_id:
|
||||
import time
|
||||
execution_id = f"{plan.get('General Goal', '').replace(' ', '_')}_{int(time.time() * 1000)}"
|
||||
|
||||
if enable_dynamic:
|
||||
# 动态模式:使用executePlan_streaming_dynamic
|
||||
from AgentCoord.RehearsalEngine_V2.ExecutePlan_Optimized import executePlan_streaming_dynamic
|
||||
|
||||
# 发送执行ID(确认使用的ID)
|
||||
emit('progress', {
|
||||
'id': request_id,
|
||||
'status': 'streaming',
|
||||
'data': chunk.replace('data: ', '').replace('\n\n', '')
|
||||
'status': 'execution_started',
|
||||
'execution_id': execution_id,
|
||||
'message': '执行已启动,支持动态追加步骤'
|
||||
})
|
||||
|
||||
# 发送完成信号
|
||||
emit('progress', {
|
||||
'id': request_id,
|
||||
'status': 'complete',
|
||||
'data': None
|
||||
})
|
||||
for chunk in executePlan_streaming_dynamic(
|
||||
plan=plan,
|
||||
num_StepToRun=num_StepToRun,
|
||||
RehearsalLog=RehearsalLog,
|
||||
AgentProfile_Dict=AgentProfile_Dict,
|
||||
execution_id=execution_id
|
||||
):
|
||||
emit('progress', {
|
||||
'id': request_id,
|
||||
'status': 'streaming',
|
||||
'data': chunk.replace('data: ', '').replace('\n\n', '')
|
||||
})
|
||||
|
||||
# 发送完成信号
|
||||
emit('progress', {
|
||||
'id': request_id,
|
||||
'status': 'complete',
|
||||
'data': None
|
||||
})
|
||||
|
||||
else:
|
||||
# 非动态模式:使用原有方式
|
||||
for chunk in executePlan_streaming(
|
||||
plan=plan,
|
||||
num_StepToRun=num_StepToRun,
|
||||
RehearsalLog=RehearsalLog,
|
||||
AgentProfile_Dict=AgentProfile_Dict,
|
||||
):
|
||||
emit('progress', {
|
||||
'id': request_id,
|
||||
'status': 'streaming',
|
||||
'data': chunk.replace('data: ', '').replace('\n\n', '')
|
||||
})
|
||||
|
||||
# 发送完成信号
|
||||
emit('progress', {
|
||||
'id': request_id,
|
||||
'status': 'complete',
|
||||
'data': None
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
# 发送错误信息
|
||||
@@ -456,6 +503,68 @@ def handle_execute_plan_optimized_ws(data):
|
||||
})
|
||||
|
||||
|
||||
@socketio.on('add_steps_to_execution')
|
||||
def handle_add_steps_to_execution(data):
|
||||
"""
|
||||
WebSocket版本:向正在执行的任务追加新步骤
|
||||
|
||||
请求格式:
|
||||
{
|
||||
"id": "request-id",
|
||||
"action": "add_steps_to_execution",
|
||||
"data": {
|
||||
"execution_id": "execution_id",
|
||||
"new_steps": [...]
|
||||
}
|
||||
}
|
||||
"""
|
||||
request_id = data.get('id')
|
||||
incoming_data = data.get('data', {})
|
||||
|
||||
try:
|
||||
from AgentCoord.RehearsalEngine_V2.dynamic_execution_manager import dynamic_execution_manager
|
||||
|
||||
execution_id = incoming_data.get('execution_id')
|
||||
new_steps = incoming_data.get('new_steps', [])
|
||||
|
||||
if not execution_id:
|
||||
emit('response', {
|
||||
'id': request_id,
|
||||
'status': 'error',
|
||||
'error': '缺少execution_id参数'
|
||||
})
|
||||
return
|
||||
|
||||
# 追加新步骤到执行队列
|
||||
added_count = dynamic_execution_manager.add_steps(execution_id, new_steps)
|
||||
|
||||
if added_count > 0:
|
||||
print(f"✅ 成功追加 {added_count} 个步骤到执行队列: {execution_id}")
|
||||
emit('response', {
|
||||
'id': request_id,
|
||||
'status': 'success',
|
||||
'data': {
|
||||
'message': f'成功追加 {added_count} 个步骤',
|
||||
'added_count': added_count
|
||||
}
|
||||
})
|
||||
else:
|
||||
print(f"⚠️ 无法追加步骤,执行ID不存在或已结束: {execution_id}")
|
||||
emit('response', {
|
||||
'id': request_id,
|
||||
'status': 'error',
|
||||
'error': '执行ID不存在或已结束'
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 追加步骤失败: {str(e)}")
|
||||
emit('response', {
|
||||
'id': request_id,
|
||||
'status': 'error',
|
||||
'error': str(e)
|
||||
})
|
||||
|
||||
|
||||
@socketio.on('generate_base_plan')
|
||||
def handle_generate_base_plan_ws(data):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user