Managing Context Budgets Across Parallel Agent Fan-Outs in Google ADK
Architectural patterns for allocating, tracking, and aggregating token budgets across concurrent sub-agents in Google Agent Development Kit fan-out workflows.
Published on • December 5, 2026
AI Assistant

In Google ADK 2.0, the ParallelAgent and workflow graph fan-out topologies allow orchestrators to dispatch a single task into dozens of concurrent sub-agents: searching different document repositories, evaluating vendor contracts across distinct compliance categories, or running concurrent security scans.
However, unchecked fan-outs introduce a severe risk of exponential token explosion. If an orchestrator fans out to 10 sub-agents, and each sub-agent accumulates a 50,000-token context history, returning all raw results to the fan-in aggregator node will result in:
- Breaching model context limits or rate quotas.
- Incurring massive inference costs.
- Degrading synthesizer output due to overwhelming token noise.
To prevent this, production systems implement Dynamic Context Budgeting.
The Fan-Out Context Lifecycle
Managing context budgets requires two-way control:
- Outbound Budget Allocation: Capping how much prompt history and state is forwarded to each sub-agent branch.
- Inbound Result Compaction: Enforcing strict output token quotas before sub-agent outputs are aggregated into the parent node.
┌───────────────────────────────┐
│ Orchestrator Parent Context │
│ Total Budget: 100k │
└───────────────┬───────────────┘
│ Fan-Out (Budget: 15k each)
┌───────────────────────┼───────────────────────┐
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Sub-Agent 1 │ │ Sub-Agent 2 │ │ Sub-Agent 3 │
│ Max In: 15k │ │ Max In: 15k │ │ Max In: 15k │
│ Max Out: 2k │ │ Max Out: 2k │ │ Max Out: 2k │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘
│ │ │
└───────────────────────┼───────────────────────┘
│ Fan-In Aggregation (Max: 6k tokens)
▼
┌───────────────────────────────┐
│ Aggregator Node │
│ Clean, Synthesized Output │
└───────────────────────────────┘
Implementing a Token Budget Gatekeeper
The budget gatekeeper monitors sub-agent execution, dynamically distributing token quotas based on branch priority:
import asyncio
from typing import List, Dict, Any
from dataclasses import dataclass
from google.genai import Client
@dataclass
class BranchBudget:
branch_name: str
max_input_tokens: int
max_output_tokens: int
class ContextBudgetManager:
def __init__(self, total_fanout_budget: int = 60000):
self.total_budget = total_fanout_budget
self.client = Client()
def allocate_budgets(self, branch_names: List[str]) -> Dict[str, BranchBudget]:
"""Evenly or weighted allocation of total budget across parallel branches."""
count = len(branch_names)
per_branch_tokens = self.total_budget // count
# Reserve 80% for input context and 20% for generated output
input_budget = int(per_branch_tokens * 0.8)
output_budget = int(per_branch_tokens * 0.2)
return {
name: BranchBudget(
branch_name=name,
max_input_tokens=input_budget,
max_output_tokens=output_budget
)
for name in branch_names
}
async def enforce_output_limit(self, output_text: str, max_tokens: int) -> str:
"""Verifies output token count; compresses if exceeding budget."""
token_count = await self.client.models.count_tokens(
model="gemini-3.8-flash",
contents=output_text
)
if token_count.total_tokens <= max_tokens:
return output_text
# Compress if over budget
compression_prompt = (
f"Condense the following summary into strictly under {max_tokens} tokens. "
"Retain all critical numbers, findings, and risks.\n\n"
f"{output_text}"
)
response = await self.client.models.generate_content(
model="gemini-3.8-flash",
contents=compression_prompt
)
return response.text
Orchestrating with ADK ParallelAgent
Integrating the budget manager with Google ADK ParallelAgent execution:
from google_adk.agents import LlmAgent, ParallelAgent
from google_adk.runners import Runner
from google_adk.sessions import InMemorySessionService
async def run_parallel_analysis():
branch_names = ["FinancialRiskAgent", "LegalComplianceAgent", "TechnicalAuditAgent"]
budget_mgr = ContextBudgetManager(total_fanout_budget=30000)
budgets = budget_mgr.allocate_budgets(branch_names)
# Instantiate sub-agents with strict output limits in system instructions
sub_agents = []
for name in branch_names:
b = budgets[name]
agent = LlmAgent(
name=name,
model="gemini-3.8-flash",
system_instruction=(
f"You are the {name}. Analyze the provided scenario exclusively from your domain. "
f"Your response MUST be concise and strictly under {b.max_output_tokens} tokens. "
"Output as bulleted points."
)
)
sub_agents.append(agent)
parallel_swarm = ParallelAgent(
name="SecurityReviewSwarm",
sub_agents=sub_agents
)
runner = Runner(agent=parallel_swarm, session_service=InMemorySessionService())
session = await runner.session_service.create_session("analysis_run_01")
prompt = "Review the proposed cloud migration architecture for healthcare patient records."
result = await runner.run_async(session_id=session.id, user_message=prompt)
print("Completed parallel fanout with bounded context.")
print("Aggregate responses compiled safely.")
if __name__ == "__main__":
asyncio.run(run_parallel_analysis())
Key Production Strategies
- Static Top-Level System Prompts: Shared system instructions should be identical across sub-agents to maximize Gemini’s automatic prefix cache across parallel execution threads.
- Asymmetric Budgeting: Allocate higher token quotas to complex technical branches and lower quotas to categorical checks.
- Structured Aggregator Reductions: Use a dedicated synthesis agent at the fan-in node to distill branch outputs into an executive brief before saving to the permanent session history.