Coverage for merco/tools/recovery.py: 46%
13 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 14:04 +0800
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 14:04 +0800
1"""ToolReduceRecovery — reduces tools when context is too large."""
2from __future__ import annotations
4from merco.core.pipeline import Recovery, RecoveryContext
7class ToolReduceRecovery(Recovery):
8 """精简工具:上下文过大时关闭非关键工具集 [框架预留]
10 需要 Agent 支持 reduce_tools 标志位后启用。
11 """
13 name = "reduce_tools"
15 def __init__(self, min_tools: int = 5):
16 self.min_tools = min_tools
18 async def attempt(self, ctx: RecoveryContext) -> bool:
19 if ctx.compress_count >= ctx.max_reduce:
20 return False
21 if ctx.tool_count <= self.min_tools:
22 return False # 工具已经很少,不再精简
23 ctx.reduce_tools = True
24 return True