Gemini CLI Sub-Agents Eliminate Context Rot
Sub-agents in Gemini CLI let a main orchestrator delegate to isolated specialists, keeping the primary context lean while handling heavy tasks like research or code analysis in parallel.
Solve Context Rot with Multi-Agent Orchestration
Single AI agents suffer from context rot: after multiple tasks like web searches, file reads, or analysis, the context window bloats with unused intermediate data, slowing responses, dropping quality, and wasting tokens. Restarting sessions loses continuity and requires re-explaining context. Sub-agents fix this by turning the main agent into an orchestrator that delegates to specialists—researcher, reviewer, analyst—each with its own isolated context, tools, and instructions. Specialists perform intensive work (e.g., 15 web searches), then return only a clean summary, keeping the main session fast and lean. This builds a faster "team" than one agent, with parallel execution for multiple specialists simultaneously.
Harness Automatic Delegation, Tool Isolation, and Parallelism
Gemini CLI's sub-agents shine with three features: (1) Automatic delegation—the main agent scans specialist descriptions and picks the right one without manual prompts. (2) Tool isolation—each specialist accesses only assigned tools (e.g., researcher searches web but can't write files; reviewer reads code but can't execute commands), enforcing security and focus. (3) Parallel execution—run 2-3 agents concurrently in separate contexts for speed. Update to Gemini CLI v38.2+ and run /agents to list them; invoke with @agentname task, e.g., @generalist research top three AI marketing platforms.
Activate Default Agents and Build Custom Ones
Out-of-box agents include: code-based investigator (deep codebase analysis like auth flows or dependencies), CLI help (Gemini CLI expertise), generalist (heavy tasks in isolation), and hidden browser agent (webpage interaction, e.g., fetch HubSpot homepage headline—enable via settings.json by adding domains like hubspot.com and restarting CLI). To create custom agents like "competitor analyst" for positioning, messaging, pricing, and audience: prompt CLI to generate a YAML .md file with expertise, constraints, tools, and instructions; fix errors iteratively via CLI. Restart CLI to load; it auto-discovers and prompts to enable. Delegate tasks like @competitor-analyst Analyze Jasper AI enterprise features for targeted outputs like "governed AI workspace" with key details. Scale by adding multiple specialists for task-specific research without main context clutter.