1
0

config.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "strconv"
  6. )
  7. // Config holds the agent configuration
  8. type Config struct {
  9. // ARP Server Configuration
  10. ARPURL string
  11. ARPUsername string
  12. ARPPassword string
  13. // OpenAI Configuration
  14. OpenAIKey string
  15. OpenAIModel string
  16. OpenAITemperature float64
  17. OpenAIBaseURL string
  18. OpenAIMaxTokens int
  19. // Agent Identity Configuration
  20. AgentName string
  21. Specialization string
  22. Values string
  23. Goals string
  24. // Queue Configuration
  25. MaxQueueSize int
  26. }
  27. // LoadConfig loads configuration from environment variables
  28. func LoadConfig() (*Config, error) {
  29. cfg := &Config{
  30. ARPURL: os.Getenv("ARP_URL"),
  31. ARPUsername: os.Getenv("ARP_USERNAME"),
  32. ARPPassword: os.Getenv("ARP_PASSWORD"),
  33. OpenAIKey: os.Getenv("OPENAI_API_KEY"),
  34. }
  35. // Required fields
  36. if cfg.ARPURL == "" {
  37. return nil, fmt.Errorf("ARP_URL environment variable is required")
  38. }
  39. if cfg.ARPUsername == "" {
  40. return nil, fmt.Errorf("ARP_USERNAME environment variable is required")
  41. }
  42. if cfg.ARPPassword == "" {
  43. return nil, fmt.Errorf("ARP_PASSWORD environment variable is required")
  44. }
  45. if cfg.OpenAIKey == "" {
  46. return nil, fmt.Errorf("OPENAI_API_KEY environment variable is required")
  47. }
  48. // Optional fields with defaults
  49. cfg.OpenAIModel = getEnvWithDefault("OPENAI_MODEL", "gpt-4")
  50. cfg.OpenAITemperature = getEnvFloatWithDefault("OPENAI_TEMPERATURE", 0.0)
  51. cfg.OpenAIBaseURL = os.Getenv("OPENAI_BASE_URL") // Empty means use default OpenAI API
  52. cfg.OpenAIMaxTokens = getEnvIntWithDefault("OPENAI_MAX_TOKENS", 4096)
  53. // Agent Identity Configuration with defaults
  54. cfg.AgentName = getEnvWithDefault("ARP_AGENT_NAME", "AI Assistant")
  55. cfg.Specialization = getEnvWithDefault("ARP_AGENT_SPECIALIZATION", "general assistance")
  56. cfg.Values = getEnvWithDefault("ARP_AGENT_VALUES", "helpfulness, accuracy, and collaboration")
  57. cfg.Goals = getEnvWithDefault("ARP_AGENT_GOALS", "help teammates accomplish their goals and contribute to the team's success")
  58. // Queue Configuration with defaults
  59. cfg.MaxQueueSize = getEnvIntWithDefault("ARP_MAX_QUEUE_SIZE", 100)
  60. return cfg, nil
  61. }
  62. // getEnvWithDefault returns the environment variable value or a default
  63. func getEnvWithDefault(key, defaultValue string) string {
  64. if value := os.Getenv(key); value != "" {
  65. return value
  66. }
  67. return defaultValue
  68. }
  69. // getEnvFloatWithDefault returns the environment variable as float64 or a default
  70. func getEnvFloatWithDefault(key string, defaultValue float64) float64 {
  71. if value := os.Getenv(key); value != "" {
  72. if f, err := strconv.ParseFloat(value, 64); err == nil {
  73. return f
  74. }
  75. }
  76. return defaultValue
  77. }
  78. // getEnvIntWithDefault returns the environment variable as int or a default
  79. func getEnvIntWithDefault(key string, defaultValue int) int {
  80. if value := os.Getenv(key); value != "" {
  81. if i, err := strconv.Atoi(value); err == nil {
  82. return i
  83. }
  84. }
  85. return defaultValue
  86. }