Skip to content

Commit d5ecc15

Browse files
tsukiga-kireilyingbug
authored andcommitted
feat(agent): support customizable LLM call timeout and add docker-compose mapping
1 parent f63c9f6 commit d5ecc15

5 files changed

Lines changed: 39 additions & 0 deletions

File tree

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ WEKNORA_SANDBOX_TIMEOUT=60
265265
# 自定义 Sandbox Docker 镜像
266266
WEKNORA_SANDBOX_DOCKER_IMAGE=wechatopenai/weknora-sandbox:latest
267267

268+
# ========== Agent 配置 ==========
269+
# 智能体大模型调用默认超时时间(秒),默认 120
270+
# 对于复杂的推理行为,建议调大此值(如 300 或 600)
271+
# 注:此值为全局默认值。若单个智能体在数据库中配置了独立的 llm_call_timeout,则以智能体配置为准(优先级更高)。
272+
# WEKNORA_AGENT_LLM_TIMEOUT=300
273+
268274
# APK 镜像源设置(可选)
269275
APK_MIRROR_ARG=mirrors.tencent.com
270276

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ services:
122122
- WEKNORA_SANDBOX_MODE=${WEKNORA_SANDBOX_MODE:-docker}
123123
- WEKNORA_SANDBOX_TIMEOUT=${WEKNORA_SANDBOX_TIMEOUT:-60}
124124
- WEKNORA_SANDBOX_DOCKER_IMAGE=${WEKNORA_SANDBOX_DOCKER_IMAGE:-wechatopenai/weknora-sandbox:${WEKNORA_VERSION:-latest}}
125+
# Agent LLM call timeout
126+
- WEKNORA_AGENT_LLM_TIMEOUT=${WEKNORA_AGENT_LLM_TIMEOUT:-}
125127
- APK_MIRROR_ARG=${APK_MIRROR_ARG:-}
126128
depends_on:
127129
redis:

internal/application/service/session_agent_qa.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ func (s *sessionService) buildAgentConfig(
219219
MCPServices: customAgent.Config.MCPServices,
220220
Thinking: customAgent.Config.Thinking,
221221
RetrieveKBOnlyWhenMentioned: customAgent.Config.RetrieveKBOnlyWhenMentioned,
222+
LLMCallTimeout: customAgent.Config.LLMCallTimeout,
223+
}
224+
225+
// Falls back to global configuration if no specific timeout is set for the agent.
226+
if agentConfig.LLMCallTimeout == 0 && s.cfg.Agent != nil && s.cfg.Agent.LLMCallTimeout > 0 {
227+
agentConfig.LLMCallTimeout = s.cfg.Agent.LLMCallTimeout
222228
}
223229

224230
// Configure skills based on CustomAgentConfig

internal/config/config.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ type Config struct {
2929
WebSearch *WebSearchConfig `yaml:"web_search" json:"web_search"`
3030
PromptTemplates *PromptTemplatesConfig `yaml:"prompt_templates" json:"prompt_templates"`
3131
IM *IMConfig `yaml:"im" json:"im"`
32+
Agent *AgentConfig `yaml:"agent" json:"agent"`
33+
}
34+
35+
// AgentConfig represents the global agent settings.
36+
type AgentConfig struct {
37+
// LLMCallTimeout is the default timeout for a single LLM call in seconds.
38+
// Default: 120 (standard agents) or 300 (can be overridden by Env).
39+
LLMCallTimeout int `yaml:"llm_call_timeout" json:"llm_call_timeout"`
3240
}
3341

3442
// IMConfig configures the IM integration service.
@@ -408,6 +416,7 @@ func LoadConfig() (*Config, error) {
408416

409417
// Validate configuration values
410418
applyOIDCEnvOverrides(&cfg)
419+
applyAgentEnvOverrides(&cfg)
411420

412421
if err := ValidateConfig(&cfg); err != nil {
413422
return nil, err
@@ -535,6 +544,20 @@ func applyOIDCEnvOverrides(cfg *Config) {
535544
}
536545
}
537546

547+
func applyAgentEnvOverrides(cfg *Config) {
548+
if cfg.Agent == nil {
549+
cfg.Agent = &AgentConfig{}
550+
}
551+
if value := strings.TrimSpace(os.Getenv("WEKNORA_AGENT_LLM_TIMEOUT")); value != "" {
552+
if timeout, err := time.ParseDuration(value); err == nil {
553+
cfg.Agent.LLMCallTimeout = int(timeout.Seconds())
554+
} else if sec, err := time.ParseDuration(value + "s"); err == nil {
555+
// Handle case where user just provides a number like "300"
556+
cfg.Agent.LLMCallTimeout = int(sec.Seconds())
557+
}
558+
}
559+
}
560+
538561
// backfillConversationDefaults resolves prompt template ID references
539562
// into actual prompt text content. Only xxx_id fields are used;
540563
// no fallback to default templates.

internal/types/custom_agent.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ type CustomAgentConfig struct {
9191
// ===== Agent Mode Settings =====
9292
// Maximum iterations for ReAct loop (only for agent type)
9393
MaxIterations int `yaml:"max_iterations" json:"max_iterations"`
94+
// Timeout for a single LLM call in seconds (0 = use global default)
95+
LLMCallTimeout int `yaml:"llm_call_timeout" json:"llm_call_timeout,omitempty"`
9496
// Allowed tools (only for agent type)
9597
AllowedTools []string `yaml:"allowed_tools" json:"allowed_tools"`
9698
// MCP service selection mode: "all" = all enabled MCP services, "selected" = specific services, "none" = no MCP

0 commit comments

Comments
 (0)