Users can revoke or update the secret at any time through the GUI.
Quickstart
1
Import the Secrets extension
Import the necessary components from the BeeAI SDK secrets extension.
2
Add secrets parameter to your agent
Inject the Secrets extension into your agent function using the
Annotated
type hint.3
Define your secret demands
Create
SecretDemand
objects for each secret your agent needs.4
Handle secret fulfillment
Check if secrets are provided and request them dynamically if needed.
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 beeai_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.
Secrets are securely stored in the platform and automatically provided to your agent on subsequent runs, so users only need to provide them once.
Always check if the secrets extension is available before using it to comply with plain A2A clients.
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.