Sage uses a layered configuration system where settings are applied in the following order (later values override earlier ones):
graph TD
A[Default Values] --> B[Config Files]
B --> C[Environment Variables]
C --> D[CLI Arguments]
D --> E[Runtime Updates]
style A fill:#f0f0f0
style E fill:#ffeb3b
Default Values: Built-in defaults in the code
Config Files: YAML/JSON configuration files
Environment Variables: System environment variables
CLI Arguments: Command-line arguments
Runtime Updates: Dynamic updates during execution
🌍 Environment Variables
Core Settings
Variable
Type
Default
Description
OPENAI_API_KEY
string
None
OpenAI API key for model access
SAGE_DEBUG
boolean
false
Enable debug logging
SAGE_ENVIRONMENT
string
“production”
Runtime environment (development/production)
SAGE_LOG_LEVEL
string
“INFO”
Logging level (DEBUG/INFO/WARNING/ERROR)
SAGE_CONFIG_PATH
string
”./config”
Path to configuration files
Model Settings
Variable
Type
Default
Description
SAGE_MODEL_NAME
string
“gpt-3.5-turbo”
Default model name
SAGE_BASE_URL
string
None
Custom API base URL
SAGE_MAX_TOKENS
integer
4096
Maximum tokens per request
SAGE_TEMPERATURE
float
0.7
Model temperature (0-1)
SAGE_TIMEOUT
integer
60
Request timeout in seconds
Agent Settings
Variable
Type
Default
Description
SAGE_MAX_ITERATIONS
integer
10
Maximum agent iterations
SAGE_DEEP_THINKING
boolean
true
Enable task analysis by default
SAGE_DEEP_RESEARCH
boolean
true
Enable deep research mode in streaming by default
SAGE_SUMMARY_MODE
boolean
true
Generate summaries by default
SAGE_STREAMING
boolean
false
Enable streaming by default
Tool Settings
Variable
Type
Default
Description
SAGE_TOOLS_PATH
string
”./agents/tool”
Path to tool directories
SAGE_MCP_SERVERS_PATH
string
”./mcp_servers”
Path to MCP server configs
SAGE_TOOL_TIMEOUT
integer
30
Tool execution timeout
SAGE_MAX_CONCURRENT_TOOLS
integer
5
Max parallel tool executions
Example .env File
# .env file for Sage configuration# API ConfigurationOPENAI_API_KEY=sk-your-openai-api-key-here
SAGE_BASE_URL=https://api.openai.com/v1
# Model SettingsSAGE_MODEL_NAME=gpt-4
SAGE_MAX_TOKENS=8192
SAGE_TEMPERATURE=0.3
# Agent BehaviorSAGE_DEEP_THINKING=true
SAGE_DEEP_RESEARCH=true
SAGE_SUMMARY_MODE=true
SAGE_MAX_ITERATIONS=15
# Development SettingsSAGE_DEBUG=true
SAGE_ENVIRONMENT=development
SAGE_LOG_LEVEL=DEBUG
# Tool SettingsSAGE_TOOLS_PATH=/custom/tools:/default/tools
SAGE_TOOL_TIMEOUT=60
# Basic usage with API key
python examples/sage_demo.py --api_key sk-your-key
# Advanced configuration
python examples/sage_demo.py \--api_key sk-your-key \--model gpt-4 \--max_tokens 8192 \--temperature 0.3 \--tools_folders ./custom_tools ./external_tools \--debug\--streaming# Web interface with custom port
python examples/sage_demo.py \--api_key sk-your-key \--web\--port 8080
# Using configuration file
python examples/sage_demo.py \--config_file ./config/production.yaml \--api_key sk-your-key
⚡ Runtime Configuration
Dynamic Updates
fromagents.configimportSettings,update_settings# Get current settings
settings=Settings()print(f"Current model: {settings.model.name}")# Update settings at runtime
update_settings(model_name="gpt-4",temperature=0.2,max_tokens=8192)# Access updated settings
updated_settings=Settings()print(f"Updated model: {updated_settings.model.name}")
Configuration Context Manager
fromagents.configimportconfig_context# Temporary configuration override
withconfig_context(temperature=0.1,debug=True):# This block uses the overridden settings
result=controller.run(messages,tool_manager)# Settings revert to previous values after context
Environment-specific Configuration
fromagents.configimportload_environment_config# Load configuration for specific environment
ifos.getenv('SAGE_ENVIRONMENT')=='development':load_environment_config('development')elifos.getenv('SAGE_ENVIRONMENT')=='production':load_environment_config('production')else:load_environment_config('default')
# Configure specific agents
agent_configs={"task_analysis":{"prompt_template":"custom_analysis_prompt.txt","complexity_threshold":0.8},"executor":{"tool_selection_strategy":"optimized","max_tool_calls":15}}# Apply to controller
controller=AgentController(model=model,model_config=model_config,agent_config=agent_configs)
frompydanticimportBaseModel,validatorfromtypingimportOptional,ListclassConfigValidator(BaseModel):"""Configuration validation model"""model_name:strmax_tokens:inttemperature:float@validator('temperature')defvalidate_temperature(cls,v):ifnot0<=v<=2:raiseValueError('Temperature must be between 0 and 2')returnv@validator('max_tokens')defvalidate_max_tokens(cls,v):ifv<=0:raiseValueError('Max tokens must be positive')returnv# Validate configuration
defvalidate_config(config_dict:dict):"""Validate configuration dictionary"""try:ConfigValidator(**config_dict)returnTrue,NoneexceptExceptionase:returnFalse,str(e)
# Directory structure
config/
├── base.yaml # Common settings
├── development.yaml # Dev overrides
├── staging.yaml # Staging overrides
└── production.yaml # Production overrides
2. Secure Credential Management
# Use environment variables for secrets
importosfromcryptography.fernetimportFernetdefget_encrypted_credential(key_name:str)->str:"""Get encrypted credential from environment"""encrypted=os.getenv(f"{key_name}_ENCRYPTED")key=os.getenv("ENCRYPTION_KEY")ifencryptedandkey:f=Fernet(key.encode())returnf.decrypt(encrypted.encode()).decode()returnos.getenv(key_name)
This configuration system provides maximum flexibility while maintaining simplicity for basic use cases. Start with environment variables for quick setup, then move to configuration files for complex deployments.