1
0

config.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. // Agent Iteration Configuration
  27. MaxIterations int
  28. }
  29. // LoadConfig loads configuration from environment variables
  30. func LoadConfig() (*Config, error) {
  31. cfg := &Config{
  32. ARPURL: os.Getenv("ARP_URL"),
  33. ARPUsername: os.Getenv("ARP_USERNAME"),
  34. ARPPassword: os.Getenv("ARP_PASSWORD"),
  35. OpenAIKey: os.Getenv("OPENAI_API_KEY"),
  36. }
  37. // Required fields
  38. if cfg.ARPURL == "" {
  39. return nil, fmt.Errorf("ARP_URL environment variable is required")
  40. }
  41. if cfg.ARPUsername == "" {
  42. return nil, fmt.Errorf("ARP_USERNAME environment variable is required")
  43. }
  44. if cfg.ARPPassword == "" {
  45. return nil, fmt.Errorf("ARP_PASSWORD environment variable is required")
  46. }
  47. if cfg.OpenAIKey == "" {
  48. return nil, fmt.Errorf("OPENAI_API_KEY environment variable is required")
  49. }
  50. // Optional fields with defaults
  51. cfg.OpenAIModel = getEnvWithDefault("OPENAI_MODEL", "gpt-4")
  52. cfg.OpenAITemperature = getEnvFloatWithDefault("OPENAI_TEMPERATURE", 0.0)
  53. cfg.OpenAIBaseURL = os.Getenv("OPENAI_BASE_URL") // Empty means use default OpenAI API
  54. cfg.OpenAIMaxTokens = getEnvIntWithDefault("OPENAI_MAX_TOKENS", 4096)
  55. // Agent Identity Configuration with defaults
  56. cfg.AgentName = getEnvWithDefault("ARP_AGENT_NAME", "AI Assistant")
  57. cfg.Specialization = getEnvWithDefault("ARP_AGENT_SPECIALIZATION", "general assistance")
  58. cfg.Values = getEnvWithDefault("ARP_AGENT_VALUES", "helpfulness, accuracy, and collaboration")
  59. cfg.Goals = getEnvWithDefault("ARP_AGENT_GOALS", "help teammates accomplish their goals and contribute to the team's success")
  60. // Queue Configuration with defaults
  61. cfg.MaxQueueSize = getEnvIntWithDefault("ARP_MAX_QUEUE_SIZE", 100)
  62. // Agent Iteration Configuration with defaults
  63. cfg.MaxIterations = getEnvIntWithDefault("ARP_MAX_ITERATIONS", 10)
  64. return cfg, nil
  65. }
  66. // getEnvWithDefault returns the environment variable value or a default
  67. func getEnvWithDefault(key, defaultValue string) string {
  68. if value := os.Getenv(key); value != "" {
  69. return value
  70. }
  71. return defaultValue
  72. }
  73. // getEnvFloatWithDefault returns the environment variable as float64 or a default
  74. func getEnvFloatWithDefault(key string, defaultValue float64) float64 {
  75. if value := os.Getenv(key); value != "" {
  76. if f, err := strconv.ParseFloat(value, 64); err == nil {
  77. return f
  78. }
  79. }
  80. return defaultValue
  81. }
  82. // getEnvIntWithDefault returns the environment variable as int or a default
  83. func getEnvIntWithDefault(key string, defaultValue int) int {
  84. if value := os.Getenv(key); value != "" {
  85. if i, err := strconv.Atoi(value); err == nil {
  86. return i
  87. }
  88. }
  89. return defaultValue
  90. }