Basic Secrets Implementation
Here’s how to add secrets capabilities to your agent:1
Import the Secrets extension
Import
SecretsExtensionServer, SecretsExtensionSpec, SecretDemand, and SecretsServiceExtensionParams from agentstack_sdk.a2a.extensions.2
Add secrets parameter to your agent
Add a secrets parameter to your agent function using the
Annotated type hint with SecretsExtensionServer and SecretsExtensionSpec.3
Define your secret demands
Create
SecretDemand objects for each secret your agent needs, specifying the name and description.4
Handle secret fulfillment
Check if secrets are provided and use
await secrets.request_secrets(params=...) to request them dynamically if missing. Ensure your agent handles cases where secrets are not provided.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.