本文分析 Agent 的 Tool 调用策略,包括并行 vs 串行调用的权衡。
Tool Calling 策略直接影响 Agent 效率和可靠性。
def should_call_tool(query: str) -> bool:
if any(kw in query for kw in ["查询", "搜索", "获取"]):
return True
return False
import asyncio
async def batch_call_tools(tools, args):
tasks = [call_tool(t, a) for t, a in zip(tools, args)]
return await asyncio.gather(*tasks)
调用策略验证通过