|
97 | 97 | check_plan, |
98 | 98 | get_tools_list, |
99 | 99 | is_plan_confirmed, |
| 100 | + scenes_contain_query_job_status, |
100 | 101 | should_bypass_confirmation, |
101 | 102 | ) |
102 | 103 | from agents.matmaster_agent.llm_config import MatMasterLlmConfig |
@@ -407,7 +408,12 @@ async def _run_scene_agent( |
407 | 408 | yield update_state_event(ctx, state_delta={'scenes': copy.deepcopy(scenes)}) |
408 | 409 |
|
409 | 410 | async def _run_plan_make_agent( |
410 | | - self, ctx: InvocationContext, UPDATE_USER_CONTENT, TOOLCHAIN_EXAMPLES_PROMPT |
| 411 | + self, |
| 412 | + ctx: InvocationContext, |
| 413 | + UPDATE_USER_CONTENT, |
| 414 | + TOOLCHAIN_EXAMPLES_PROMPT, |
| 415 | + *, |
| 416 | + skip_thinking: bool = False, |
411 | 417 | ) -> AsyncGenerator[Event, None]: |
412 | 418 | # 制定计划 |
413 | 419 | if check_plan(ctx) == FlowStatusEnum.FAILED: |
@@ -471,41 +477,49 @@ async def _run_plan_make_agent( |
471 | 477 | ) |
472 | 478 | expanded_query = expand_state.get('update_user_content', '') |
473 | 479 |
|
474 | | - # Thinking: loop (and optional revision) is handled inside ThinkingAgent |
| 480 | + # Thinking: skip for "query job status only" (e.g. 查看任务状态); run otherwise |
475 | 481 | thinking_text = '' |
476 | | - try: |
477 | | - self._thinking_agent.set_thinking_params( |
478 | | - available_tools_with_info_str, |
479 | | - session_file_summary, |
480 | | - original_query, |
481 | | - expanded_query, |
482 | | - short_term_memory=short_term_memory_block, |
483 | | - ) |
484 | | - last_full_text = '' |
485 | | - async for thinking_event in self._thinking_agent.run_async(ctx): |
486 | | - yield thinking_event |
| 482 | + if not skip_thinking: |
| 483 | + try: |
| 484 | + self._thinking_agent.set_thinking_params( |
| 485 | + available_tools_with_info_str, |
| 486 | + session_file_summary, |
| 487 | + original_query, |
| 488 | + expanded_query, |
| 489 | + short_term_memory=short_term_memory_block, |
| 490 | + ) |
| 491 | + last_full_text = '' |
| 492 | + async for thinking_event in self._thinking_agent.run_async(ctx): |
| 493 | + yield thinking_event |
| 494 | + if ( |
| 495 | + not getattr(thinking_event, 'partial', True) |
| 496 | + and getattr(thinking_event, 'content', None) |
| 497 | + and getattr(thinking_event.content, 'parts', None) |
| 498 | + ): |
| 499 | + parts_text = ''.join( |
| 500 | + p.text or '' |
| 501 | + for p in thinking_event.content.parts |
| 502 | + if getattr(p, 'text', None) |
| 503 | + ) |
| 504 | + if parts_text.strip(): |
| 505 | + last_full_text = parts_text.strip() |
| 506 | + thinking_text = (last_full_text or '').strip() |
487 | 507 | if ( |
488 | | - not getattr(thinking_event, 'partial', True) |
489 | | - and getattr(thinking_event, 'content', None) |
490 | | - and getattr(thinking_event.content, 'parts', None) |
| 508 | + getattr(self._thinking_agent, '_last_thinking_text', None) |
| 509 | + is not None |
491 | 510 | ): |
492 | | - parts_text = ''.join( |
493 | | - p.text or '' |
494 | | - for p in thinking_event.content.parts |
495 | | - if getattr(p, 'text', None) |
496 | | - ) |
497 | | - if parts_text.strip(): |
498 | | - last_full_text = parts_text.strip() |
499 | | - thinking_text = (last_full_text or '').strip() |
500 | | - if getattr(self._thinking_agent, '_last_thinking_text', None) is not None: |
501 | | - thinking_text = self._thinking_agent._last_thinking_text |
| 511 | + thinking_text = self._thinking_agent._last_thinking_text |
| 512 | + logger.info( |
| 513 | + f'{ctx.session.id} reasoning_agent result length={len(thinking_text)}, ' |
| 514 | + f'preview={repr(thinking_text[:300]) if thinking_text else "empty"}' |
| 515 | + ) |
| 516 | + except Exception as e: |
| 517 | + logger.warning( |
| 518 | + f'{ctx.session.id} reasoning_agent failed: {e}, proceed without thinking' |
| 519 | + ) |
| 520 | + else: |
502 | 521 | logger.info( |
503 | | - f'{ctx.session.id} reasoning_agent result length={len(thinking_text)}, ' |
504 | | - f'preview={repr(thinking_text[:300]) if thinking_text else "empty"}' |
505 | | - ) |
506 | | - except Exception as e: |
507 | | - logger.warning( |
508 | | - f'{ctx.session.id} reasoning_agent failed: {e}, proceed without thinking' |
| 522 | + f'{ctx.session.id} skip reasoning_agent (query_job_status_only)' |
509 | 523 | ) |
510 | 524 |
|
511 | 525 | self.plan_make_agent.instruction = get_plan_make_instruction( |
@@ -873,13 +887,18 @@ async def _run_research_flow( |
873 | 887 | yield update_state_event(ctx, state_delta={PLAN: {}, MULTI_PLANS: {}}) |
874 | 888 |
|
875 | 889 | # 制定计划(1. 无计划;2. 计划已完成;3. 计划失败;4. 用户未确认计划) |
| 890 | + # 仅查询任务状态时跳过 thinking(查任务状态不 thinking) |
| 891 | + skip_thinking = scenes_contain_query_job_status(ctx) |
876 | 892 | if check_plan(ctx) in [ |
877 | 893 | FlowStatusEnum.NO_PLAN, |
878 | 894 | FlowStatusEnum.COMPLETE, |
879 | 895 | FlowStatusEnum.FAILED, |
880 | 896 | ] or not is_plan_confirmed(ctx): |
881 | 897 | async for _plan_make_event in self._run_plan_make_agent( |
882 | | - ctx, UPDATE_USER_CONTENT, TOOLCHAIN_EXAMPLES_PROMPT |
| 898 | + ctx, |
| 899 | + UPDATE_USER_CONTENT, |
| 900 | + TOOLCHAIN_EXAMPLES_PROMPT, |
| 901 | + skip_thinking=skip_thinking, |
883 | 902 | ): |
884 | 903 | yield _plan_make_event |
885 | 904 |
|
|
0 commit comments