feat(agent): support customizable LLM call timeout and add docker-compose mapping

This commit is contained in:
AndyYang
2026-04-04 16:55:45 +08:00
committed by lyingbug
parent f63c9f6dbe
commit d5ecc150e0
5 changed files with 39 additions and 0 deletions
+23
View File
@@ -29,6 +29,14 @@ type Config struct {
WebSearch *WebSearchConfig `yaml:"web_search" json:"web_search"`
PromptTemplates *PromptTemplatesConfig `yaml:"prompt_templates" json:"prompt_templates"`
IM *IMConfig `yaml:"im" json:"im"`
Agent *AgentConfig `yaml:"agent" json:"agent"`
}
// AgentConfig represents the global agent settings.
type AgentConfig struct {
// LLMCallTimeout is the default timeout for a single LLM call in seconds.
// Default: 120 (standard agents) or 300 (can be overridden by Env).
LLMCallTimeout int `yaml:"llm_call_timeout" json:"llm_call_timeout"`
}
// IMConfig configures the IM integration service.
@@ -408,6 +416,7 @@ func LoadConfig() (*Config, error) {
// Validate configuration values
applyOIDCEnvOverrides(&cfg)
applyAgentEnvOverrides(&cfg)
if err := ValidateConfig(&cfg); err != nil {
return nil, err
@@ -535,6 +544,20 @@ func applyOIDCEnvOverrides(cfg *Config) {
}
}
func applyAgentEnvOverrides(cfg *Config) {
if cfg.Agent == nil {
cfg.Agent = &AgentConfig{}
}
if value := strings.TrimSpace(os.Getenv("WEKNORA_AGENT_LLM_TIMEOUT")); value != "" {
if timeout, err := time.ParseDuration(value); err == nil {
cfg.Agent.LLMCallTimeout = int(timeout.Seconds())
} else if sec, err := time.ParseDuration(value + "s"); err == nil {
// Handle case where user just provides a number like "300"
cfg.Agent.LLMCallTimeout = int(sec.Seconds())
}
}
}
// backfillConversationDefaults resolves prompt template ID references
// into actual prompt text content. Only xxx_id fields are used;
// no fallback to default templates.