Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

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

AndyYangd5ecc150e07a
diff --git a/.env.example b/.env.example
index cf5623690..ac3f14499 100644
--- a/.env.example
+++ b/.env.example
@@ -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
diff --git a/docker-compose.yml b/docker-compose.yml
index e3a5ffc93..f10f339bd 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -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:
diff --git a/internal/application/service/session_agent_qa.go b/internal/application/service/session_agent_qa.go
index b429e659d..b3d4382b8 100644
--- a/internal/application/service/session_agent_qa.go
+++ b/internal/application/service/session_agent_qa.go
@@ -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
diff --git a/internal/config/config.go b/internal/config/config.go
index 1ccbfd227..720393875 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -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.
diff --git a/internal/types/custom_agent.go b/internal/types/custom_agent.go
index a90c0d6f7..8fd0c9eb4 100644
--- a/internal/types/custom_agent.go
+++ b/internal/types/custom_agent.go
@@ -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