|
15 | 15 | DisallowTransferAndContentLimitMCPAgent, |
16 | 16 | ) |
17 | 17 | from agents.matmaster_agent.flow_agents.model import PlanStepStatusEnum |
| 18 | +from agents.matmaster_agent.flow_agents.step_utils import get_current_step |
18 | 19 | from agents.matmaster_agent.locales import i18n |
19 | 20 | from agents.matmaster_agent.logger import PrefixFilter |
20 | 21 | from agents.matmaster_agent.model import BohrJobInfo, DFlowJobInfo |
21 | | -from agents.matmaster_agent.state import CURRENT_STEP |
| 22 | +from agents.matmaster_agent.state import CURRENT_STEP, CURRENT_STEP_STATUS |
22 | 23 | from agents.matmaster_agent.style import tool_response_failed_card |
23 | 24 | from agents.matmaster_agent.utils.event_utils import ( |
24 | 25 | all_text_event, |
@@ -99,11 +100,13 @@ async def _run_events(self, ctx: InvocationContext) -> AsyncGenerator[Event, Non |
99 | 100 | yield tool_response_failed_event |
100 | 101 |
|
101 | 102 | # 更新 plan 为失败 |
102 | | - update_plan = copy.deepcopy(ctx.session.state['plan']) |
103 | | - update_plan['steps'][ctx.session.state['plan_index']][ |
104 | | - 'status' |
105 | | - ] = 'failed' |
106 | | - yield update_state_event(ctx, state_delta={'plan': update_plan}) |
| 103 | + post_execution_step = copy.deepcopy(get_current_step(ctx)) |
| 104 | + post_execution_step[CURRENT_STEP_STATUS] = ( |
| 105 | + PlanStepStatusEnum.FAILED |
| 106 | + ) |
| 107 | + yield update_state_event( |
| 108 | + ctx, state_delta={CURRENT_STEP: post_execution_step} |
| 109 | + ) |
107 | 110 |
|
108 | 111 | raise RuntimeError('Tool Execution Failed') |
109 | 112 | dict_result = load_tool_response(first_part) |
@@ -189,12 +192,14 @@ async def _run_events(self, ctx: InvocationContext) -> AsyncGenerator[Event, Non |
189 | 192 | yield tool_response_failed_event |
190 | 193 |
|
191 | 194 | # 更新 plan 为失败 |
192 | | - update_plan = copy.deepcopy(ctx.session.state['plan']) |
193 | | - update_plan['steps'][ctx.session.state['plan_index']][ |
194 | | - 'status' |
195 | | - ] = 'failed' |
| 195 | + post_execution_step = copy.deepcopy( |
| 196 | + get_current_step(ctx) |
| 197 | + ) |
| 198 | + post_execution_step[CURRENT_STEP_STATUS] = ( |
| 199 | + PlanStepStatusEnum.FAILED |
| 200 | + ) |
196 | 201 | yield update_state_event( |
197 | | - ctx, state_delta={'plan': update_plan} |
| 202 | + ctx, state_delta={CURRENT_STEP: post_execution_step} |
198 | 203 | ) |
199 | 204 |
|
200 | 205 | raise RuntimeError('Tool Execution Failed') |
@@ -270,10 +275,10 @@ async def _run_events(self, ctx: InvocationContext) -> AsyncGenerator[Event, Non |
270 | 275 | ctx, self.name, '工具参数无变化,本次跳过执行', ModelRole |
271 | 276 | ): |
272 | 277 | yield _info_event |
273 | | - update_plan = copy.deepcopy(ctx.session.state['plan']) |
274 | | - update_plan['steps'][ctx.session.state['plan_index']][ |
275 | | - 'status' |
276 | | - ] = PlanStepStatusEnum.FAILED |
277 | | - yield update_state_event(ctx, state_delta={'plan': update_plan}) |
| 278 | + post_execution_step = copy.deepcopy(ctx.session.state[CURRENT_STEP]) |
| 279 | + post_execution_step['status'] = PlanStepStatusEnum.FAILED |
| 280 | + yield update_state_event( |
| 281 | + ctx, state_delta={CURRENT_STEP: post_execution_step} |
| 282 | + ) |
278 | 283 | else: |
279 | 284 | yield event |
0 commit comments