|
120 | 120 | toolchain_from_examples, |
121 | 121 | ) |
122 | 122 | from agents.matmaster_agent.services.questions import get_random_questions |
123 | | -from agents.matmaster_agent.state import EXPAND, MULTI_PLANS, UPLOAD_FILE |
| 123 | +from agents.matmaster_agent.state import EXPAND, MULTI_PLANS, PLAN, UPLOAD_FILE |
124 | 124 | from agents.matmaster_agent.sub_agents.mapping import ( |
125 | 125 | AGENT_CLASS_MAPPING, |
126 | 126 | ALL_AGENT_TOOLS_LIST, |
@@ -541,13 +541,14 @@ async def _run_plan_make_agent( |
541 | 541 | yield update_state_event(ctx, state_delta={'multi_plans': update_multi_plans}) |
542 | 542 |
|
543 | 543 | # 检查是否应该跳过用户确认步骤 |
544 | | - if should_bypass_confirmation(ctx): |
| 544 | + if plan_make_count == 1 and should_bypass_confirmation(ctx): |
545 | 545 | # 自动设置计划确认状态 |
546 | 546 | yield update_state_event( |
547 | 547 | ctx, |
548 | 548 | state_delta={ |
549 | 549 | 'plan_confirm': { |
550 | 550 | 'flag': True, |
| 551 | + 'selected_plan_id': 0, |
551 | 552 | 'reason': 'Auto confirmed for single bypass tool', |
552 | 553 | } |
553 | 554 | }, |
@@ -690,32 +691,35 @@ async def _run_research_flow( |
690 | 691 | if check_plan(ctx) == FlowStatusEnum.COMPLETE or not ctx.session.state[ |
691 | 692 | 'plan_confirm' |
692 | 693 | ].get('flag', False): |
| 694 | + # 清空 Plan 和 MULTI_PLANS |
| 695 | + if check_plan(ctx) == FlowStatusEnum.COMPLETE: |
| 696 | + yield update_state_event(ctx, state_delta={PLAN: {}, MULTI_PLANS: {}}) |
| 697 | + |
693 | 698 | async for _plan_confirm_event in self._run_plan_confirm_agent(ctx): |
694 | 699 | yield _plan_confirm_event |
695 | 700 |
|
696 | | - plan_confirm = ctx.session.state['plan_confirm'].get('flag', False) |
697 | | - |
698 | | - # 制定计划(1. 无计划;2. 计划未通过;3. 计划已完成;4. 用户未确认计划) |
699 | | - if ( |
700 | | - check_plan(ctx) |
701 | | - in [ |
702 | | - FlowStatusEnum.NO_PLAN, |
703 | | - FlowStatusEnum.COMPLETE, |
704 | | - FlowStatusEnum.FAILED, |
705 | | - ] |
706 | | - or not plan_confirm |
707 | | - ): |
| 701 | + # 制定计划(1. 无计划;2. 计划已完成;3. 计划失败;4. 用户未确认计划) |
| 702 | + if check_plan(ctx) in [ |
| 703 | + FlowStatusEnum.NO_PLAN, |
| 704 | + FlowStatusEnum.COMPLETE, |
| 705 | + FlowStatusEnum.FAILED, |
| 706 | + ] or not ctx.session.state['plan_confirm'].get('flag', False): |
708 | 707 | async for _plan_make_event in self._run_plan_make_agent( |
709 | 708 | ctx, UPDATE_USER_CONTENT, TOOLCHAIN_EXAMPLES_PROMPT |
710 | 709 | ): |
711 | 710 | yield _plan_make_event |
712 | 711 |
|
713 | | - # 确定选择某个计划 |
| 712 | + # 从 MultiPlans 中选择某个计划 |
714 | 713 | logger.info(f'{ctx.session.id} check_plan = {check_plan(ctx)}') |
715 | | - if plan_confirm and check_plan(ctx) in [FlowStatusEnum.NEW_PLAN]: |
| 714 | + if ctx.session.state['plan_confirm'].get('flag', False) and check_plan(ctx) in [ |
| 715 | + FlowStatusEnum.NEW_PLAN |
| 716 | + ]: |
716 | 717 | selected_plan_id = ctx.session.state['plan_confirm']['selected_plan_id'] |
717 | 718 | selected_plan = ctx.session.state[MULTI_PLANS]['plans'][selected_plan_id] |
718 | | - yield update_state_event(ctx, state_delta={'plan': selected_plan}) |
| 719 | + yield update_state_event(ctx, state_delta={PLAN: selected_plan}) |
| 720 | + logger.info( |
| 721 | + f'{ctx.session.id} Reset Plan, plan = {ctx.session.state[PLAN]}' |
| 722 | + ) |
719 | 723 |
|
720 | 724 | # 计划未确认,暂停往下执行 |
721 | 725 | if ctx.session.state['plan_confirm']['flag']: |
|
0 commit comments