Configuration files
Config files
Config files enable granular, isolated control of development, staging, and production environments, and allow substitution of sensitive values using environment variables.
Usage
Auto-load
The simplest way to start is to place a config.json file next to your agent in the project directory.
It will be loaded automatically.
Declare path
If you want to specify the path to your config file, pass it in using the config_file parameter.
With AgentBase class
With a custom class
Structure
Configuration files support both JSON and YAML formats with environment variable substitution. Here’s a complete example showing the main configuration sections:
Service options
Security options
All services share the same security configuration options:
Here’s a comprehensive example:
Agent options
Skills options
Skills can be activated and configured via the config file:
Logging options
Prioritization
Services in the Agents SDK look for configuration files in the below locations, in this order:
- Service-specific:
{service_name}_config.json(e.g.,search_config.json) - Generic:
config.json - Hidden:
.swml/config.json - User home:
~/.swml/config.json - System:
/etc/swml/config.json
Configuration values are applied in this order (highest to lowest):
- Constructor parameters - Explicitly passed to service
- Config file values - From JSON configuration
- Environment variables - Direct env vars
- Defaults - Hard-coded defaults
The SDK validates config files on load, checking for required fields, correct types, and valid file paths (e.g., SSL certificates).
Environment variables
Substitution
The configuration system supports ${VAR|default} syntax:
${VAR}- Use environment variable VAR (error if not set)${VAR|default}- Use VAR or “default” if not set${VAR|}- Use VAR or empty string if not set
For example:
Set environment variables
Environment variables can be set in several ways depending on your deployment method. For example:
.env file
Command line
Docker
Docker Compose
Kubernetes
Create a .env file in your project root (add to .gitignore):
Optionally, use python-dotenv to load the .env variables:
For serverless deployment, refer to each provider’s docs on managing environment variables:
Examples
Development
This simple config sets up basic auth without SSL on port 3000.
Production
This config secures your service with SSL encryption, domain-based host restrictions, and environment variable substitution for sensitive credentials.
Best practices
- Use environment substitution for sensitive values
- Validate configurations before deploying to production
- Document custom configurations for your team
- Test configurations in staging environments first
- Version control non-sensitive configuration templates
- Monitor configuration loading in application logs
For detailed security configuration options, see the Security guide.