|
|
ADK Custom Tool Authentication
Author: Venkata Sudhakar
ADK agents call external APIs through tools. In production, these APIs require authentication - API keys, OAuth tokens, or service account credentials. ADK Custom Tool Authentication provides patterns for securely passing credentials to tools without exposing them in agent instructions or conversation history. ShopMax India uses this to connect agents to its payment and inventory APIs. The recommended approach is to inject credentials at tool construction time using closures or class-based tools. API keys are read from environment variables or Secret Manager, never hardcoded. For Google Cloud APIs, Application Default Credentials (ADC) handle authentication automatically. The below example shows three authentication patterns: API key injection, service account credentials, and Google Cloud ADC.
It gives the following output,
Inventory tool created with API key from environment.
Payment tool created with service account credentials.
The below example shows how to assemble the agent with authenticated tools and use Google Cloud Secret Manager for runtime credential retrieval.
It gives the following output,
Agent ready: shopmax_ops_agent
Tools: ['check_inventory', 'process_payment']
ShopMax India follows the principle that credentials must never appear in agent instructions, prompts, or logs. All API keys are stored in Google Cloud Secret Manager, rotated quarterly, and injected at tool creation time. Service accounts follow least-privilege - the inventory tool can only read stock, never modify it - keeping the security boundary tight even as agent capabilities expand.
|
|