Manages pre-instantiated sub-agent pools for performance and reuse. Covers sizing, checkout/checkin, state reset, health monitoring, auto-scaling, and multi-pool routing.
Ships in claude-skills-collection. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
| Situation | Pool recommandé ? |
|---|---|
| Latence de cold-start > 500 ms (chargement modèle, init tools) | Oui |
| Rafales de tâches homogènes (même type d'agent) | Oui |
| Tâches ponctuelles, types variés et imprévisibles | Non |
| Budget CPU/mémoire contraint, peu de concurrence | Non — instancier à la demande |
| SLA strict sur le temps de réponse (< 200 ms P95) | Oui |
Règle rapide : si le coût de warm-up dépasse 20 % du temps de traitement moyen d'une tâche, un pool est rentable.
Choisir entre pool statique (taille fixe, simple, prévisible) et pool dynamique (auto-scaling, plus complexe).
Identifier les types d'agents et leur proportion :
researcher_pool : min=3, max=10
coder_pool : min=2, max=8
reviewer_pool : min=1, max=4
Pré-créer min_size agents, effectuer un health check avant de les marquer available.
async def initialize(self):
for _ in range(self.min_size):
agent = await self._create_agent()
if await agent.ping(): # health check initial
self._all_agents[agent.id] = agent
await self._available.put(agent)
else:
await agent.destroy() # ne pas injecter un agent cassé
print(f"[POOL:{self.agent_type}] {self._available.qsize()} agents prêts")
Ne jamais attendre indéfiniment. Lever une exception explicite plutôt que bloquer.
async def _checkout(self, timeout: float = 5.0) -> PooledAgent:
try:
agent = await asyncio.wait_for(self._available.get(), timeout=timeout)
except asyncio.TimeoutError:
raise PoolExhaustedError(
f"Aucun agent {self.agent_type} disponible après {timeout}s "
f"(pool size={len(self._all_agents)}, waiters={self._waiters})"
)
agent.status = "busy"
agent.use_count += 1
return agent
@asynccontextmanager
async def borrow(self, timeout: float = 5.0):
self._waiters += 1
agent = await self._checkout(timeout=timeout)
self._waiters -= 1
try:
yield agent
finally:
await self._checkin(agent) # retour même si exception
# Usage
async with pool.borrow(timeout=3.0) as agent:
result = await agent.run(task)
Un agent retourné doit être indiscernable d'un agent neuf.
def reset_state(self):
self.conversation_history.clear() # historique LLM
self.memory.flush() # mémoire éphémère
self.tool_cache.clear() # cache des tools
self.context_vars = {} # variables de session
self.status = "available"
self.last_used = datetime.utcnow()
Checkin avec remplacement automatique si l'agent est usé :
async def _checkin(self, agent: PooledAgent):
agent.reset_state()
if agent.use_count >= agent.max_uses or not await agent.ping():
del self._all_agents[agent.id]
fresh = await self._create_agent()
self._all_agents[fresh.id] = fresh
await self._available.put(fresh)
else:
await self._available.put(agent)
min_size = ceil(avg_concurrent_tasks * 1.2) # marge 20 %
max_size = ceil(peak_concurrent_tasks * 1.5) # marge 50 % pour pics
max_uses = 50 # refresh préventif — ajuster selon dégradation observée
Calibrer avec des mesures réelles : lancer un test de charge, observer utilization et avg_wait_ms.
async def _health_loop(self, interval: float = 30.0):
while True:
await asyncio.sleep(interval)
for agent_id, agent in list(self._all_agents.items()):
if agent.status == "available" and not await agent.ping():
self._all_agents.pop(agent_id, None)
fresh = await self._create_agent()
self._all_agents[fresh.id] = fresh
await self._available.put(fresh)
print(f"[HEALTH] Agent {agent_id} remplacé (unhealthy)")
async def _autoscale_loop(self, interval: float = 10.0):
while True:
await asyncio.sleep(interval)
m = self.metrics()
# Scale-up : file d'attente non vide ET pool non saturé
if m["waiters"] > 0 and m["total"] < self.max_size:
fresh = await self._create_agent()
self._all_agents[fresh.id] = fresh
await self._available.put(fresh)
# Scale-down : utilisation < 20 % ET au-dessus du min
elif m["utilization"] < 0.2 and m["total"] > self.min_size:
try:
agent = self._available.get_nowait()
del self._all_agents[agent.id]
await agent.destroy()
except asyncio.QueueEmpty:
pass
class PoolRouter:
def __init__(self):
self._pools: dict[str, AgentPool] = {}
def register(self, pool: AgentPool) -> "PoolRouter":
self._pools[pool.agent_type] = pool
return self
def borrow(self, task_type: str, timeout: float = 5.0):
pool = self._pools.get(task_type)
if not pool:
raise ValueError(f"Aucun pool enregistré pour: {task_type!r}")
return pool.borrow(timeout=timeout)
# Mise en place
router = PoolRouter()
router.register(AgentPool("researcher", min_size=3, max_size=10))
router.register(AgentPool("coder", min_size=2, max_size=8))
router.register(AgentPool("reviewer", min_size=1, max_size=4))
async with router.borrow("coder") as agent:
result = await agent.run(task)
def metrics(self) -> dict:
busy = sum(1 for a in self._all_agents.values() if a.status == "busy")
total = len(self._all_agents)
return {
"type": self.agent_type,
"total": total,
"busy": busy,
"available": total - busy,
"utilization_pct": round(busy / max(total, 1) * 100, 1),
"waiters": self._waiters,
"avg_use_count": sum(a.use_count for a in self._all_agents.values()) / max(total, 1),
}
Exposer via Prometheus (/metrics), Datadog, ou simple log périodique. Alerter si waiters > 0 pendant plus de 10 s.
Tâches entrantes
│
▼
┌─────────────┐
│ Pool Router │ routing par task_type
└──────┬──────┘
├─────────────────────┐
▼ ▼
┌──────────────┐ ┌──────────────┐
│ researcher │ │ coder pool │
│ [A][A][B][A] │ │ [A][B][A] │
│ min=3 max=10 │ │ min=2 max=8 │
└──────┬───────┘ └──────────────┘
│ checkout → execute → reset → checkin
▼
Health Monitor (ping toutes les 30 s, remplace si KO)
Auto-Scaler (ajuste total selon waiters / utilization)
A = available B = busy
| Critère | LangGraph | CrewAI | Custom asyncio |
|---|---|---|---|
| Pool natif | Non | Non | asyncio.Queue |
| State reset automatique | Non | Non | Manuel (total contrôle) |
| Auto-scaling | Non | Non | Manuel / HPA K8s |
| Health check intégré | Non | Non | Manuel |
| Multi-pool routing | Non | Partiel | Total |
Pool trop grand (idle cost)
Maintenir 50 agents sans charge coûte en mémoire et en tokens d'initialisation. Calibrer min_size au strict nécessaire ; l'auto-scaler gère les pics.
State reset incomplet Si l'historique de conversation persiste, l'agent "se souvient" de la tâche précédente. Résultat : fuites de données entre clients, hallucinations contextuelles. Le reset doit couvrir : historique LLM, mémoire, cache tools, variables session.
Timeout absent sur checkout
Sans timeout, une tâche bloque indéfiniment si le pool est saturé. Toujours asyncio.wait_for(queue.get(), timeout=N) et lever PoolExhaustedError.
Pool monotype pour tâches hétérogènes Un pool d'agents généralistes sous-performe face à des pools spécialisés. La spécialisation améliore la qualité, réduit le prompt overhead et permet un sizing indépendant.
Pas de refresh après N utilisations
Les agents LLM accumulent un état interne subtil (cache KV) et peuvent dégrader sur la durée. Définir max_uses (50–200 selon le type) et remplacer proactivement.
Health check trop fréquent Un ping toutes les secondes sur 50 agents génère du bruit et consomme les quotas API. Intervalle recommandé : 30–60 s en production, 5 s en dev.
busy terminent leur tâche avant de détruire le pool (await asyncio.gather(*[a.finish() for a in busy_agents])).agent_id qui l'a traitée pour corréler les anomalies de qualité avec des agents spécifiques.max_size agents tous busy) dès le CI — vérifier que PoolExhaustedError est levée proprement, jamais un deadlock.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/claude-skills-collection:agent-pool-managerfrom claude-skills-collection
npx claudepluginhub vantaflow/claude-skills-collection --plugin claude-skills-collection348 skills in this plugin
/agent-a2a-protocol-guideGuide du protocole Agent-to-Agent (A2A) de Google pour l'interopérabilité entre agents IA — découverte, communication et collaboration inter-agents, avec exemples de code, critères de décision et pièges à éviter. Se déclenche avec "A2A", "agent-to-agent", "protocole A2A", "Google A2A", "interopérabilité agents". Also triggers on "agent-to-agent protocol", "agent interoperability", "connect two agents"./agent-agent-observabilityInstrumentation technique d'un agent IA — tracing distribué des appels LLM et outils, spans, métriques custom, corrélation de logs et dashboards de supervision. Pour les alertes et garde-fous de production, voir agent-monitoring-setup. Se déclenche avec "observabilité agent", "tracing agent", "LangSmith", "Langfuse", "OpenTelemetry agent", "spans LLM", "corréler les logs agent". Also triggers on "trace my agent", "LLM tracing", "agent spans"./agent-api-caller-subagentSous-agent spécialisé dans les appels API REST/GraphQL avec retry, auth et transformation de données. Se déclenche avec "sous-agent API", "API caller agent", "agent qui appelle une API", "REST agent", "HTTP agent", "API integration subagent", "external API agent". Also triggers on "subagent that calls an API", "API calling agent", "agent HTTP requests".Other plugins' skills for the same job