Skip to content

Commit 360c486

Browse files
authored
Merge pull request #724 from SchrodingersCattt/test
fix: skip thinking for job result querying
2 parents f8d2591 + 899dc7d commit 360c486

3 files changed

Lines changed: 70 additions & 36 deletions

File tree

agents/matmaster_agent/flow_agents/agent.py

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
check_plan,
9898
get_tools_list,
9999
is_plan_confirmed,
100+
scenes_contain_query_job_status,
100101
should_bypass_confirmation,
101102
)
102103
from agents.matmaster_agent.llm_config import MatMasterLlmConfig
@@ -407,7 +408,12 @@ async def _run_scene_agent(
407408
yield update_state_event(ctx, state_delta={'scenes': copy.deepcopy(scenes)})
408409

409410
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,
411417
) -> AsyncGenerator[Event, None]:
412418
# 制定计划
413419
if check_plan(ctx) == FlowStatusEnum.FAILED:
@@ -471,41 +477,49 @@ async def _run_plan_make_agent(
471477
)
472478
expanded_query = expand_state.get('update_user_content', '')
473479

474-
# Thinking: loop (and optional revision) is handled inside ThinkingAgent
480+
# Thinking: skip for "query job status only" (e.g. 查看任务状态); run otherwise
475481
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()
487507
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
491510
):
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:
502521
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)'
509523
)
510524

511525
self.plan_make_agent.instruction = get_plan_make_instruction(
@@ -873,13 +887,18 @@ async def _run_research_flow(
873887
yield update_state_event(ctx, state_delta={PLAN: {}, MULTI_PLANS: {}})
874888

875889
# 制定计划(1. 无计划;2. 计划已完成;3. 计划失败;4. 用户未确认计划)
890+
# 仅查询任务状态时跳过 thinking(查任务状态不 thinking)
891+
skip_thinking = scenes_contain_query_job_status(ctx)
876892
if check_plan(ctx) in [
877893
FlowStatusEnum.NO_PLAN,
878894
FlowStatusEnum.COMPLETE,
879895
FlowStatusEnum.FAILED,
880896
] or not is_plan_confirmed(ctx):
881897
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,
883902
):
884903
yield _plan_make_event
885904

agents/matmaster_agent/flow_agents/scene_agent/model.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,9 @@ class SceneEnum(DescriptiveEnum):
126126
'perovskite_research',
127127
'Research, literature/database search, and semantic mining focused on perovskite solar cells (efficiency, stability, additives, architectures, new molecules).',
128128
)
129+
130+
# job/task status only (no planning/thinking needed)
131+
QUERY_JOB_STATUS = (
132+
'query_job_status',
133+
'User only asks to check task/job status or get task results. e.g. 查询任务, 查看任务, 查看任务状态, 查看任务结果, 任务怎么样了, 任务进度, check task status, check task results. Use this when the sole intent is to query status or retrieve results of submitted jobs, not to create a new plan.',
134+
)

agents/matmaster_agent/flow_agents/utils.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,29 @@ def has_self_check(current_tool_name: str) -> bool:
163163
return tool.get('self_check', False)
164164

165165

166+
def scenes_contain_query_job_status(ctx: InvocationContext) -> bool:
167+
"""True when current scenes include query_job_status (e.g. 查询任务/查看任务状态)."""
168+
scenes = ctx.session.state.get('scenes') or []
169+
query_value = SceneEnum.QUERY_JOB_STATUS.value
170+
return any(getattr(s, 'value', s) == query_value for s in scenes)
171+
172+
166173
def is_plan_confirmed(ctx: InvocationContext) -> bool:
167174
# 1) 原有:前端状态里已确认
168175
biz_state = ctx.session.state.get(FRONTEND_STATE_KEY, {}).get(BIZ, {})
169176
if biz_state.get(PLAN_CONFIRM, False):
170177
return True
171178

172-
# 2) 新增:用户输入匹配“方案 + 数字”(方案和数字间允许空格)
179+
# 2) 用户输入匹配“方案 + 数字”(方案和数字间允许空格)
173180
try:
174181
text = (ctx.user_content.parts[0].text or '').strip()
175182
except Exception:
176183
text = ''
177-
178-
# 仅匹配纯数字:方案1 / 方案 1 / 方案 12
179184
if re.match(r'^\s*方案\s*\d+\s*$', text):
180185
return True
181186

187+
# 3) 查询任务/任务状态场景:仅查任务状态或结果,无需用户点确认,直接视为已确认
188+
if scenes_contain_query_job_status(ctx):
189+
return True
190+
182191
return False

0 commit comments

Comments
 (0)