Skip to content

Commit 4cc8590

Browse files
authored
Merge pull request #676 from AnguseZhang/chore/add_http_412
refactor: 提取工具重试退出逻辑为独立函数should_exit_retryLoop
2 parents 6be5663 + 49e46ae commit 4cc8590

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

agents/matmaster_agent/flow_agents/execution_agent/agent.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
DisallowTransferAndContentLimitLlmAgent,
1414
)
1515
from agents.matmaster_agent.flow_agents.constant import MATMASTER_SUPERVISOR_AGENT
16+
from agents.matmaster_agent.flow_agents.execution_agent.utils import (
17+
should_exit_retryLoop,
18+
)
1619
from agents.matmaster_agent.flow_agents.model import PlanStepStatusEnum
1720
from agents.matmaster_agent.flow_agents.step_validation_agent.prompt import (
1821
STEP_VALIDATION_INSTRUCTION,
@@ -28,7 +31,7 @@
2831
from agents.matmaster_agent.locales import i18n
2932
from agents.matmaster_agent.logger import PrefixFilter
3033
from agents.matmaster_agent.prompt import MatMasterCheckTransferPrompt
31-
from agents.matmaster_agent.state import ERROR_DETAIL, ERROR_OCCURRED, PLAN
34+
from agents.matmaster_agent.state import PLAN
3235
from agents.matmaster_agent.sub_agents.mapping import (
3336
MatMasterSubAgentsEnum,
3437
)
@@ -368,15 +371,8 @@ async def _run_events(self, ctx: InvocationContext) -> AsyncGenerator[Event, Non
368371
and ctx.session.state[PLAN]['steps'][index]['retry_count']
369372
< MAX_TOOL_RETRIES
370373
):
371-
# 下载 results.txt 失败,退出同一工具重试
372-
DOWNLOAD_RESULTS_TXT_FAILED = (
373-
ctx.session.state[ERROR_OCCURRED]
374-
and ctx.session.state[ERROR_DETAIL].startswith(
375-
'ClientResponseError'
376-
)
377-
and 'results.txt' in ctx.session.state[ERROR_DETAIL]
378-
)
379-
if DOWNLOAD_RESULTS_TXT_FAILED:
374+
# 对于某些错误,重试没有必要,直接退出
375+
if should_exit_retryLoop:
380376
break
381377

382378
validation_result = ctx.session.state.get(
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from google.adk.agents import InvocationContext
2+
3+
from agents.matmaster_agent.state import ERROR_DETAIL, ERROR_OCCURRED
4+
5+
6+
def should_exit_retryLoop(ctx: InvocationContext) -> bool:
7+
ANY_ERROR = ctx.session.state[ERROR_OCCURRED]
8+
9+
# 下载 results.txt 失败,退出同一工具重试
10+
DOWNLOAD_RESULTS_TXT_FAILED = (
11+
ANY_ERROR
12+
and ctx.session.state[ERROR_DETAIL].startswith('ClientResponseError')
13+
and 'results.txt' in ctx.session.state[ERROR_DETAIL]
14+
)
15+
16+
# HTTP 412 ERROR
17+
HTTP_412_ERROR = (
18+
ANY_ERROR
19+
and ctx.session.state[ERROR_DETAIL].startswith('HTTPStatusError')
20+
and '412 Precondition Failed' in ctx.session.state[ERROR_DETAIL]
21+
)
22+
23+
return DOWNLOAD_RESULTS_TXT_FAILED or HTTP_412_ERROR

0 commit comments

Comments
 (0)