async def _process_tools(resp):
"""Process tool calls asynchronously for efficiency."""
if tools := resp.tools:
for t in tools: print('Calling', t._name())
tasks = [t.call() for t in tools]
tool_results = await asyncio.gather(*tasks)
return list(zip(tools, tool_results))
return None
async def run(query: str, *, tools, max_steps: int = 10):
"""Main agent loop: continue until done or max steps reached."""
done, history, i = False, [], 0
while not done and i < max_steps:
resp, history, done = await _one_step(query, tools=tools, history=history)
i += 1
return resp