feat(agent): support customizable LLM call timeout and add docker-compose mapping
This commit is contained in:
@@ -265,6 +265,12 @@ WEKNORA_SANDBOX_TIMEOUT=60
|
||||
# 自定义 Sandbox Docker 镜像
|
||||
WEKNORA_SANDBOX_DOCKER_IMAGE=wechatopenai/weknora-sandbox:latest
|
||||
|
||||
# ========== Agent 配置 ==========
|
||||
# 智能体大模型调用默认超时时间(秒),默认 120
|
||||
# 对于复杂的推理行为,建议调大此值(如 300 或 600)
|
||||
# 注:此值为全局默认值。若单个智能体在数据库中配置了独立的 llm_call_timeout,则以智能体配置为准(优先级更高)。
|
||||
# WEKNORA_AGENT_LLM_TIMEOUT=300
|
||||
|
||||
# APK 镜像源设置(可选)
|
||||
APK_MIRROR_ARG=mirrors.tencent.com
|
||||
|
||||
|
||||
@@ -122,6 +122,8 @@ services:
|
||||
- WEKNORA_SANDBOX_MODE=${WEKNORA_SANDBOX_MODE:-docker}
|
||||
- WEKNORA_SANDBOX_TIMEOUT=${WEKNORA_SANDBOX_TIMEOUT:-60}
|
||||
- WEKNORA_SANDBOX_DOCKER_IMAGE=${WEKNORA_SANDBOX_DOCKER_IMAGE:-wechatopenai/weknora-sandbox:${WEKNORA_VERSION:-latest}}
|
||||
# Agent LLM call timeout
|
||||
- WEKNORA_AGENT_LLM_TIMEOUT=${WEKNORA_AGENT_LLM_TIMEOUT:-}
|
||||
- APK_MIRROR_ARG=${APK_MIRROR_ARG:-}
|
||||
depends_on:
|
||||
redis:
|
||||
|
||||
@@ -219,6 +219,12 @@ func (s *sessionService) buildAgentConfig(
|
||||
MCPServices: customAgent.Config.MCPServices,
|
||||
Thinking: customAgent.Config.Thinking,
|
||||
RetrieveKBOnlyWhenMentioned: customAgent.Config.RetrieveKBOnlyWhenMentioned,
|
||||
LLMCallTimeout: customAgent.Config.LLMCallTimeout,
|
||||
}
|
||||
|
||||
// Falls back to global configuration if no specific timeout is set for the agent.
|
||||
if agentConfig.LLMCallTimeout == 0 && s.cfg.Agent != nil && s.cfg.Agent.LLMCallTimeout > 0 {
|
||||
agentConfig.LLMCallTimeout = s.cfg.Agent.LLMCallTimeout
|
||||
}
|
||||
|
||||
// Configure skills based on CustomAgentConfig
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -91,6 +91,8 @@ type CustomAgentConfig struct {
|
||||
// ===== Agent Mode Settings =====
|
||||
// Maximum iterations for ReAct loop (only for agent type)
|
||||
MaxIterations int `yaml:"max_iterations" json:"max_iterations"`
|
||||
// Timeout for a single LLM call in seconds (0 = use global default)
|
||||
LLMCallTimeout int `yaml:"llm_call_timeout" json:"llm_call_timeout,omitempty"`
|
||||
// Allowed tools (only for agent type)
|
||||
AllowedTools []string `yaml:"allowed_tools" json:"allowed_tools"`
|
||||
// MCP service selection mode: "all" = all enabled MCP services, "selected" = specific services, "none" = no MCP
|
||||
|
||||
Reference in New Issue
Block a user