Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let @moonbox3 and @TaoChenOSU comment on if we need this, because I kind of doubt it, we already support fan-in/fan-out, but this is the definitely not the place to put this.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import asyncio
from typing import List, Any, Callable

class ParallelToolExecutor:
"""
Executor for parallel tool calls in agentic workflows.
Significantly reduces latency for multi-tool operations.
"""
def __init__(self, max_concurrency: int = 5):
self.semaphore = asyncio.Semaphore(max_concurrency)

async def execute_parallel(self, tool_calls: List[Callable[[], Any]]) -> List[Any]:
async def _run_tool(call):
async with self.semaphore:
return await asyncio.to_thread(call)

return await asyncio.gather(*[_run_tool(call) for call in tool_calls])