The Secrets Extension provides a secure way for agent builders to request sensitive values, such as API keys, directly from the user. Rather than hardcoding credentials or relying on local environment variables that may not exist in a production environment, the Secrets Extension allows your agent to demand specific values. These can be provided by the user before execution (pre-configured) or requested dynamically during the run if the agent hits a blocker. Once a secret is provided, the platform stores it securely so the user isn’t prompted repeatedly in future sessions.Documentation Index
Fetch the complete documentation index at: https://agentstack.beeai.dev/llms.txt
Use this file to discover all available pages before exploring further.
Basic Secrets Implementation
Here’s how to add secrets capabilities to your agent:Import the Secrets extension
Import
SecretsExtensionServer, SecretsExtensionSpec, SecretDemand, and SecretsServiceExtensionParams from agentstack_sdk.a2a.extensions.Add secrets parameter to your agent
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.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.