Back to Blog
Published:
Last Updated:
Recently Updated
AWS & Google Agent FrameworksChapter 2

Supervisor-Router on Google ADK with Per-Org Tool Registration

9 min read
1,700 words
high priority
Mudassir Marwat

Mudassir Marwat

Founder & CEO, Cognilium AI

Supervisor-Router on Google ADK with Per-Org Tool Registration — Cognilium AI

TL;DR

Building a multi-tenant agent platform on Google ADK where the supervisor binds only the tools each org has paid for and integrated — without forking the agent definition per tenant.

A multi-tenant SaaS that exposes 7 specialist agents through a supervisor needs a model where each org sees only the tools they have paid for and connected. The naive approach — register every tool, let the LLM ignore the irrelevant ones — fails on cost (every tool description in the system prompt costs tokens on every turn) and on security (the LLM hallucinates a Salesforce call for an org without Salesforce, the user sees a 401 and blames the AI).

The system this writeup describes runs on Google ADK 1.15 with Gemini 2.0 Flash for chat and Gemini 2.5 Pro for document intelligence. The supervisor sits in front of seven specialists (Doc, Email, Calendar, Investment, Compliance, Audit, Reporting). What makes it shippable is that the supervisor is instantiated per-request from a factory that reads org-level RBAC and integration status before binding tools.

The agent factory

Every request hits a TenantContextMiddleware that reads the immutable Firebase custom claim, looks up organizations/{orgId}/permissions, and attaches it to request.context. The supervisor factory takes that context and assembles the agent: which specialists to register (Investment is excluded for ops-only orgs), which tools to bind to each specialist (Salesforce-write only for orgs with the Salesforce integration in connected state), and which system prompt fragment to splice in (compliance-mode adds an audit-trail clause).

The factory output is a fresh ADK Agent instance per request. A naive implementation rebuilds it from scratch every call, which costs ~150ms in Firestore reads. The factory caches by {orgId, integrations_hash} so warm path is ~5ms. Hash invalidates on any integration change via a Pub/Sub topic the integrations service publishes to.

RBAC at two layers

Layer one: tool registration. The factory only binds tools the org is allowed to use. The LLM literally does not know the others exist — system prompt is shorter, hallucination cannot reach into a non-connected Salesforce.

Layer two: per-tool permission check inside the tool handler. Every tool starts with assert_permission(request.context, "salesforce:read"). This catches the case where someone bypasses the factory (test fixtures, internal scripts) and acts as a runtime audit point. Either layer alone is brittle — the factory layer can be bypassed accidentally; the tool layer is enforced last but cannot trim the prompt. Together they cover both gaps.

Why ADK and not Assistants v2

  • ADK gives you agent-as-code with versioning in git — every supervisor change is reviewable
  • Vertex AI handles model routing without a third-party gateway
  • Native streaming through ADK works with Gemini 2.5 Pro grounded responses
  • Tool definitions live in Python with full type-checking, not in a Web Studio

The Assistants v2 alternative is one assistant per org, which works but turns "add a feature to the supervisor" into a fan-out migration across N orgs. ADK keeps the source of truth in code and the per-org variation in data.

Numbers from production

  • Cold supervisor instantiation: ~150ms (Firestore × 3 + tool factory)
  • Warm: ~5ms (in-memory cache, hash-keyed)
  • 7 specialists × up to 12 tools each = ~84-tool catalog at registration time
  • Our own builds run 4-6 specialists with 3-5 tools each — supervisor prompt stays under 4KB
  • Pub/Sub-driven cache invalidation: <1s from integration change to next request seeing the new state

Share this article

The work behind this series

Framework-agnostic agent deployment with memory persistence and observability.

Mudassir Marwat

Mudassir Marwat

Founder & CEO, Cognilium AI

Mudassir Marwat's argument is that ERP systems record decisions they never optimise.

Founder & CEO of Cognilium AI; 37 AI agents in production across four products; 4 production AI products built and operated; three clouds in production (AWSGCPAzure)
Agentic AIRAG → GraphRAG retrievalVoice AIMulti-Agent Orchestration

Frequently Asked Questions

Find answers to common questions about the topics covered in this article.

Two reasons: cost (every registered tool inflates the system prompt, which costs tokens on every turn) and security (if the supervisor knows about a Salesforce tool the org has not connected, hallucination produces a 401 the user sees as "the AI broke"). Bind only what the org has paid for and integrated.
Both, defense in depth. Agent factory binds only allowed tools at registration time (first line). Each tool also re-checks the user permission inside its handler before calling the downstream API (second line). Either layer alone is brittle; together they are robust.
Immutable Firebase custom claims set at signup, plus a Firestore document at organizations/{orgId}/permissions. The middleware reads the claim, fetches the doc, and merges into the request context. Anything downstream uses request.context — no service ever queries Firestore directly for ACLs.
Tool factory caches by {orgId, integrations_hash}. Cold path: ~150ms (Firestore reads + tool wiring). Warm: ~5ms (in-memory map lookup). Cache is invalidated on integration change via Pub/Sub.
The pattern is portable. Assistants v2 has tool registration via the API; the equivalent is creating an assistant per org, or building a thin layer that filters tools at the request boundary. The trade-off: ADK gives you native agent-as-code, Assistants v2 gives you a hosted thread runtime — pick by ops preference.

Still have questions?

Get in touch with our team for personalized assistance.

Contact Us

Still have a question this did not answer?

The person who wrote this article answers these. Describe your setup and what you are stuck on — you will get a straight answer, including where we think the approach is wrong.

Related Articles

Continue exploring related topics and insights from our content library.

Surviving Partial Failure in a 3,300-Call Agent Pipeline
8 min
1
Mudassir Marwat
May 5, 2026

Surviving Partial Failure in a 3,300-Call Agent Pipeline

Two-tier retries, atomic DynamoDB chunk claims, and checkpoint-based cancellation — the failure-recovery layer that lets a multi-agent contract review pipeline finish even when 5% of LLM calls fail.

words
Read Article
Multi-Agent Orchestration on AWS Bedrock AgentCore
9 min
2
Mudassir Marwat
May 4, 2026

Multi-Agent Orchestration on AWS Bedrock AgentCore

The supervisor + specialist pattern is the most reliable way to ship multi-agent systems on AWS — here is how to wire it, observe it, and bound its cost.

words
Read Article
Bias-Detection Alerts on a 4-Agent Candidate Evaluation Pipeline
7 min
3
Mudassir Marwat
May 5, 2026

Bias-Detection Alerts on a 4-Agent Candidate Evaluation Pipeline

A four-agent hiring pipeline is a regulated decision system. Continuous monitoring with alerts at the four-fifths-rule disparity-impact threshold.

words
Read Article

Explore More Insights

Discover more expert articles on AI, engineering, and technology trends.

Personalized for You

Curated content recommendations based on your current reading and interests.

Surviving Partial Failure in a 3,300-Call Agent Pipeline — Cognilium AI
Trending
119%

Surviving Partial Failure in a 3,300-Call Agent Pipeline

Same topic cluster: AWS & Google Agent Frameworks
Same author: Mudassir Marwat

Two-tier retries, atomic DynamoDB chunk claims, and checkpoint-based cancellation — the failure-recovery layer that lets a multi-agent contract review pipeline finish even when 5% of LLM calls fail.

Mudassir Marwat
8 min read
AWS & Google Agent Frameworks
Read Article
Trending
38%

Why do received goods sit uninvoiced, and what can an agent actually do about it?

High priority content
Related topic cluster: Procure-to-Pay Agent Operations

Dynamics 365 already matches product receipts to invoices hourly or daily. The balance that will not clear is the residue the automation cannot resolve.

Ali Ahmed
7 min read
Procure-to-Pay Agent Operations
Read Article
When to Mix SQS FIFO and Standard Queues in an Agent Pipeline — Cognilium AI
For You
109%

When to Mix SQS FIFO and Standard Queues in an Agent Pipeline

Same topic cluster: AWS & Google Agent Frameworks
Same author: Mudassir Marwat

FIFO for chunk ordering, Standard for parallel analysis fan-out. Why a single queue type for the whole pipeline is the wrong default, with the dead-letter and retry settings that make the split work.

Mudassir Marwat
7 min read
AWS & Google Agent Frameworks
Read Article
Diagram of supervisor-specialist multi-agent orchestration on AWS Bedrock AgentCore.
For You
109%

Multi-Agent Orchestration on AWS Bedrock AgentCore

Same topic cluster: AWS & Google Agent Frameworks
Same author: Mudassir Marwat

The supervisor + specialist pattern is the most reliable way to ship multi-agent systems on AWS — here is how to wire it, observe it, and bound its cost.

Mudassir Marwat
9 min read
AWS & Google Agent Frameworks
Read Article
Zero-Trust Multi-Tenant Firestore: Middleware, Claims, and 60+ Wildcard Permissions — Cognilium AI
Trending
70%

Zero-Trust Multi-Tenant Firestore: Middleware, Claims, and 60+ Wildcard Permissions

Same author: Mudassir Marwat
Preferred author

Hard tenant isolation on Firestore: middleware, immutable claims, wildcard permissions. The architecture that makes leakage structurally impossible.

Mudassir Marwat
9 min read
Enterprise Document AI
Read Article
Your multi-agent system has no brakes. You designed which agents exist and how they connect, but not the thing that decides when they stop, and in most systems nothing does. Control is emergent: it falls out of agents calling each other, so the system stops only when something runs out. Four ways control fails: non-termination, where the loop never ends; premature stop, where an agent's "done" was not actually done; mis-routing, where the task orbits and never lands; and no budget, where the rare tail run wrecks the bill. The fix is explicit control, not a smarter agent.
Trending
67%

Your Multi-Agent System Has No Brakes

Same author: Mudassir Marwat
Preferred author

A multi-agent system with no termination condition does not fail, it spends. The stopping criteria that actually hold, and the ones that only look like limits.

Mudassir Marwat
9 min read
Multi-Agent Systems in Production
Read Article

Smart Recommendations

Our AI analyzes topic clusters, author expertise, and content relationships to surface the most relevant articles for you.

Topic Matching
Author Expertise
Content Quality
Personal Interests

Questions on this?

Talk to an engineer

Schedule a call