config.go 3.2 KB

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