concurrency

并发控制确保系统在高负载下稳定运行,避免资源耗尽。

并发限制

工具执行并发

const MAX_TOOL_CONCURRENCY = 5;

class ConcurrencyLimiter {
  private running = 0;
  private queue: Array<() => void> = [];
  
  async acquire(): Promise<void> {
    if (this.running < MAX_TOOL_CONCURRENCY) {
      this.running++;
      return;
    }
    
    // 等待空闲
    return new Promise(resolve => {
      this.queue.push(resolve);
    });
  }
  
  release(): void {
    this.running--;
    
    if (this.queue.length > 0) {
      const next = this.queue.shift();
      this.running++;
      next();
    }
  }
}

Agent 并发

资源管理

内存限制

文件句柄限制

优先级调度

工具优先级

背压处理

队列限制

流量控制

超时控制

工具超时

全局超时

下一步