Configuration

Configuration Guide

โš™๏ธ Configuration Overview

SAM Framework uses environment variables for configuration with sensible defaults. Configuration is loaded automatically on startup and can be validated using the CLI.

Environment-Based

Configuration via environment variables with .env file support

Secure by Default

Encrypted key storage and secure credential management

Runtime Validation

Configuration validation with helpful error messages

๐Ÿ“ Configuration Methods

SAM supports multiple configuration methods with automatic loading priority:

Configuration Priority

  1. Environment Variables (highest priority)
  2. TOML Configuration File (sam.toml or $XDG_CONFIG_HOME/sam/sam.toml)
  3. .env File (auto-loaded)
  4. Interactive Settings (runtime configuration)
  5. Sensible Defaults (lowest priority)

Configuration Files

TOML Configuration

# sam.toml
[llm]
provider = "anthropic"
model = "claude-3-5-sonnet-latest"

[safety]
max_transaction_sol = 5.0
default_slippage = 2.0

[tools]
enable_solana_tools = true
enable_pump_fun_tools = true
enable_jupiter_tools = true
enable_dexscreener_tools = true
enable_search_tools = false

Environment File

# .env
LLM_PROVIDER=anthropic
ANTHROPIC_API_KEY=sk-ant-your-key-here
SAM_FERNET_KEY=your-generated-key
SAM_SOLANA_RPC_URL=https://api.mainnet-beta.solana.com

๐Ÿ“ Environment Variables

LLM Provider Configuration

OpenAI Configuration

| Variable | Description | Default | Required | |----------|-------------|---------|----------| | LLM_PROVIDER | Set to openai | - | Yes | | OPENAI_API_KEY | Your OpenAI API key | - | Yes | | OPENAI_MODEL | Model name | gpt-4o-mini | No | | OPENAI_BASE_URL | Custom endpoint | OpenAI default | No |

LLM_PROVIDER=openai
OPENAI_API_KEY=sk-your-openai-api-key-here
OPENAI_MODEL=gpt-4o-mini

Core System Configuration

Security & Encryption

| Variable | Description | Default | Required | |----------|-------------|---------|----------| | SAM_FERNET_KEY | Fernet encryption key | auto-generated | Yes | | SAM_WALLET_PRIVATE_KEY | Solana private key | - | No* |

# Generate encryption key
sam key generate

# Import private key securely (recommended)
sam key import

*Private key can be imported via sam key import for better security

๐Ÿ”ง Middleware Configuration

SAM uses a configurable middleware pipeline for tool execution, logging, rate limiting, and error handling.

Middleware JSON Configuration

# Set middleware configuration
export SAM_MIDDLEWARE_JSON='{
  "logging": {
    "include_args": false,
    "include_result": false,
    "only": [],
    "exclude": []
  },
  "rate_limit": {
    "enabled": true,
    "map": {
      "search_web": {"type": "search", "identifier_field": "query"},
      "search_news": {"type": "search", "identifier_field": "query"},
      "get_swap_quote": {"type": "jupiter"},
      "jupiter_swap": {"type": "jupiter"},
      "pump_fun_buy": {"type": "pump_fun_buy", "identifier_field": "mint"},
      "pump_fun_sell": {"type": "pump_fun_sell", "identifier_field": "mint"}
    }
  },
  "retry": [
    {"only": ["search_web", "search_news"], "max_retries": 2, "base_delay": 0.25},
    {"only": ["get_swap_quote", "jupiter_swap"], "max_retries": 3, "base_delay": 0.25},
    {"only": ["pump_fun_buy", "pump_fun_sell"], "max_retries": 2, "base_delay": 0.25}
  ]
}'

Middleware Types

Logging Middleware

{
  "logging": {
    "include_args": true,
    "include_result": true,
    "only": ["get_balance", "transfer_sol"],
    "exclude": ["search_web"]
  }
}

Rate Limiting Middleware

{
  "rate_limit": {
    "enabled": true,
    "map": {
      "tool_name": {
        "type": "category_name",
        "identifier_field": "field_name"
      }
    }
  }
}

Retry Middleware

{
  "retry": [
    {
      "only": ["tool_name"],
      "max_retries": 3,
      "base_delay": 0.25
    }
  ]
}

TOML Middleware Configuration

# sam.toml
[middleware.logging]
include_args = false
include_result = false

[middleware.rate_limit]
enabled = true

[middleware.rate_limit.map.search_web]
type = "search"
identifier_field = "query"

[[middleware.retry]]
only = ["search_web", "search_news"]
max_retries = 2
base_delay = 0.25

๐Ÿ” Key Management

Secure Key Storage

SAM provides multiple ways to manage your Solana private key securely:

Import Private Key Securely

# Use the secure import command
uv run sam key import

# Follow the interactive prompts to import your key
# The key will be encrypted and stored in your OS keyring

Benefits:

  • Keys are encrypted with Fernet before storage
  • Stored in system keyring (more secure than files)
  • Automatic retrieval for transactions
  • No plain text keys in memory

๐Ÿงช Configuration Validation

Setup Status Check

# Check your configuration status
uv run sam setup

This command validates:

  • โœ… OpenAI API key presence and format
  • โœ… Fernet encryption key validity
  • โœ… Solana RPC connectivity
  • โœ… Wallet configuration status
  • โœ… Database accessibility

Health Diagnostics

# Run comprehensive health check
uv run sam health

Health Check Components:

  • Configuration validation
  • API connectivity testing
  • Database integrity checks
  • Wallet balance verification
  • Tool availability confirmation

๐Ÿ”ง Advanced Configuration

Custom RPC Endpoints

For production deployments, consider using dedicated RPC endpoints:

# High-performance RPC endpoints
SAM_SOLANA_RPC_URL=https://your-fast-rpc.com

# Alternative options:
# https://api.mainnet-beta.solana.com (default)
# https://solana-mainnet.g.alchemy.com/v2/YOUR_API_KEY
# https://rpc.ankr.com/solana

Database Configuration

# Custom database location
SAM_DB_PATH=/path/to/sam_database.db

# Use in-memory database (not recommended for production)
SAM_DB_PATH=:memory:

Logging Configuration

# Log levels: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_LEVEL=DEBUG  # Verbose logging for development
LOG_LEVEL=WARNING  # Minimal logging for production

# Disable all logging (not recommended)
LOG_LEVEL=NO

๐ŸŒ Optional Integrations

Brave Search API

For web search functionality:

# Get API key from https://brave.com/search/api/
BRAVE_API_KEY=your_brave_api_key_here

Features enabled:

  • Web search capabilities
  • News article search
  • General internet queries

๐Ÿš€ Production Configuration

Recommended Production Settings

# .env.production
OPENAI_API_KEY=sk-production-key
SAM_FERNET_KEY=production-encryption-key
SAM_SOLANA_RPC_URL=https://production-rpc-endpoint.com
RATE_LIMITING_ENABLED=true
MAX_TRANSACTION_SOL=10.0
DEFAULT_SLIPPAGE=5
LOG_LEVEL=WARNING
SAM_DB_PATH=/data/sam/production.db

Environment-Specific Configuration

# Development
cp .env.example .env.dev
export $(cat .env.dev | xargs)

# Production
cp .env.example .env.prod
export $(cat .env.prod | xargs)

๐Ÿ” Configuration Troubleshooting

Common Issues

Validation Commands

# Test OpenAI API connectivity
uv run sam setup

# Test Solana RPC connection
uv run sam health

# View current configuration
uv run sam config  # (if implemented)

Configuration File Examples

Minimal Configuration (.env.minimal)

OPENAI_API_KEY=sk-your-key
SAM_FERNET_KEY=your-generated-key

Development Configuration (.env.dev)

OPENAI_API_KEY=sk-dev-key
SAM_FERNET_KEY=dev-encryption-key
LOG_LEVEL=DEBUG
RATE_LIMITING_ENABLED=false

Production Configuration (.env.prod)

OPENAI_API_KEY=sk-prod-key
SAM_FERNET_KEY=prod-encryption-key
SAM_SOLANA_RPC_URL=https://production-rpc.com
RATE_LIMITING_ENABLED=true
MAX_TRANSACTION_SOL=5.0
LOG_LEVEL=WARNING

๐Ÿ“‹ Configuration Checklist

โœ… Setup Verification

  • โ€ข OPENAI_API_KEY - Valid OpenAI API key configured
  • โ€ข SAM_FERNET_KEY - Fernet encryption key generated
  • โ€ข Private key imported via sam key import
  • โ€ข sam setup passes all validation checks
  • โ€ข sam health shows green status
  • โ€ข Test transaction with small amount
  • โ€ข Verify wallet balance retrieval

Remember: Never commit your .env file or share your private keys. Use the secure key import feature for maximum security.