Agent Development Kit (ADK) agents interact with external services outside of Google Cloud. Both agent identities and Identity and Access Management (IAM) let you authenticate with Google Cloud services. However, they can't prove identity to external platforms that don't support Google's identity federation.
ADK agents require access to various credentials to interact with external entities such as MCP services, ADK tools, and APIs. Common examples include the following:
- API keys for payment processing platforms
- Username and password combinations for legacy on-premises databases
- Private keys for mutual TLS (mTLS) connections
SecretManagerClient module
within the google.adk.integrations.secret_manager.secret_client package. This module provides a standard
interface for agents to retrieve secrets from Secret Manager at runtime.
This document explains how to manage secrets for external services in ADK using Secret Manager.
Advantages of using Secret Manager with ADK
Manual secret management can introduce security risks and increase developer toil. Secret Manager can help resolve these issues through the following:
- If you embed secrets in agent code, you create a significant security risk. This practice can lead to unauthorized access to production systems. Using Secret Manager removes sensitive data from your source code. This helps make your application more secure.
- If you embed static secrets through environment variables, credential rotation becomes complicated. To apply updates, you must restart deployment containers. Secret Manager retrieves credentials dynamically at runtime, which allows for updates without system downtime.
- If you write custom
SecretManagerServiceClientboilerplate code for every tool, you increase developer toil and the risk of errors. The standardized ADK integration provides a clean, reusable approach to retrieve credentials.
Before you begin
Before you integrate Secret Manager with ADK, complete the following:
- Set up an agent using ADK. This feature requires ADK version 1.29 or later for Python.
- Grant the
Secret Manager Secret AccessorIAM role to the agent identity. This role allows your agent to retrieve secrets at runtime. - Create a secret and add a secret version, such as an API key, in Secret Manager.
How an ADK agent retrieves secrets at runtime
The secret_client.SecretManagerClient module retrieves credentials
into the Python agent code logic at runtime. The agent orchestration logic
sends prompts to the large language model (LLM) to decide which tool to execute,
but the system doesn't send the secret to the LLM.
The agent executes the following steps during the runtime phase:
- Before an ADK agent invokes a third-party tool, the agent initializes the
SecretManagerClientmodule and callsget_secret()function. - The ADK agent uses the agent identity to authenticate with Secret Manager.
- The
SecretManagerClientmodule returns the plaintext secret to the ADK agent. - The ADK agent uses the secret to make an authenticated call to the third-party tool.
Retrieve secrets within an ADK agent at runtime
The following code sample shows how you can use
SecretManagerClient module to retrieve a secret securely within an ADK
agent. The agent retrieves the secret internally to prevent exposing sensitive
credentials to the LLM's context window or conversation history.
Python
To run this code, first set up a Python development environment and install the Secret Manager Python SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
What's next
- Explore Agent Development Kit.