Secrets are a way for agent builders to request sensitive values for agent execution. A great example is API keys that your agent needs to access external services. The secrets extension allows you to demand specific secrets from users. Users can provide these secrets before running the agent, which is why secret fulfillment is optional. We don’t want to bother users unless absolutely necessary. When an agent can’t continue its work without a secret and the user hasn’t provided it beforehand, the agent may request the secret dynamically and, for example, reject the user request if not specified. Once a secret is provided by the user, it’s stored in the platform so subsequent runs don’t need to prompt the user again.Documentation Index
Fetch the complete documentation index at: https://ibm-8c0b5b62-gpt-researcher-integration.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Quickstart
Import the Secrets extension
Import the necessary components from the Agent Stack SDK secrets extension.
Add secrets parameter to your agent
Inject the Secrets extension into your agent function using the
Annotated type hint.Basic Secrets Example
Here’s how to add secrets capabilities to your agent:How to work with secrets
Here’s what you need to know to add secrets capabilities to your agent: Import the secrets extension: ImportSecretsExtensionServer, SecretsExtensionSpec, SecretDemand, and SecretsServiceExtensionParams from agentstack_sdk.a2a.extensions.auth.secrets.
Inject the extension: Add a secrets parameter to your agent function using the Annotated type hint with SecretsExtensionServer and SecretsExtensionSpec.
Define your secret demands: Create SecretDemand objects for each secret your agent needs, specifying the name and description.
Check for pre-configured secrets: Always check if secrets are already provided before requesting them dynamically.
Request secrets dynamically: Use await secrets.request_secrets() to ask for secrets during runtime if they weren’t provided beforehand.
Handle missing secrets: Implement appropriate fallback behavior when secrets are not available.
Usage Patterns
There are two main patterns for working with secrets in your agents:Pre-configured Secrets
When secrets are provided before the agent runs, they’re available immediately in thesecrets.data.secret_fulfillments object. This is the preferred approach as it provides a smoother user experience.
Dynamic Secret Requests
When secrets aren’t pre-configured, you can request them during runtime usingawait secrets.request_secrets(). This is useful when your agent needs to ask for secrets based on user input or when the secret requirement is conditional.