feat(agent): implement LLM call timeout and transient error handling

- Introduced a configurable LLM call timeout with a default value, allowing for better control over LLM call durations.
- Added logic to retry transient errors (e.g., timeouts, rate limits) up to a specified maximum number of retries, improving robustness in error handling.
- Implemented parameter casting for tool arguments to ensure correct types are used, addressing common LLM quirks.
- Enhanced tool execution error messages with guidance for retrying with different approaches.
- Added validation for configuration values to prevent runtime errors.
This commit is contained in:
wizardchen
2026-03-19 20:39:38 +08:00
committed by lyingbug
parent 00ac14aabb
commit e936e0b347
9 changed files with 408 additions and 49 deletions
+49
View File
@@ -379,9 +379,58 @@ func LoadConfig() (*Config, error) {
resolveBuiltinAgentPromptIDs(cfg.PromptTemplates)
}
// Validate configuration values
if err := ValidateConfig(&cfg); err != nil {
return nil, err
}
return &cfg, nil
}
// ValidateConfig performs basic validation of the loaded configuration.
// It checks for obviously invalid or missing values that would cause runtime failures.
func ValidateConfig(cfg *Config) error {
var errs []string
if cfg.Conversation != nil {
if cfg.Conversation.EmbeddingTopK < 0 {
errs = append(errs, "conversation.embedding_top_k must be >= 0")
}
if cfg.Conversation.RerankTopK < 0 {
errs = append(errs, "conversation.rerank_top_k must be >= 0")
}
if cfg.Conversation.VectorThreshold < 0 || cfg.Conversation.VectorThreshold > 1 {
errs = append(errs, "conversation.vector_threshold must be between 0 and 1")
}
if cfg.Conversation.RerankThreshold < 0 || cfg.Conversation.RerankThreshold > 1 {
errs = append(errs, "conversation.rerank_threshold must be between 0 and 1")
}
}
if cfg.KnowledgeBase != nil {
if cfg.KnowledgeBase.ChunkSize <= 0 {
errs = append(errs, "knowledge_base.chunk_size must be > 0")
}
if cfg.KnowledgeBase.ChunkOverlap < 0 {
errs = append(errs, "knowledge_base.chunk_overlap must be >= 0")
}
if cfg.KnowledgeBase.ChunkOverlap >= cfg.KnowledgeBase.ChunkSize {
errs = append(errs, "knowledge_base.chunk_overlap must be less than chunk_size")
}
}
if cfg.Server != nil {
if cfg.Server.Port <= 0 || cfg.Server.Port > 65535 {
errs = append(errs, "server.port must be between 1 and 65535")
}
}
if len(errs) > 0 {
return fmt.Errorf("config validation errors: %s", strings.Join(errs, "; "))
}
return nil
}
// backfillConversationDefaults resolves prompt template ID references
// into actual prompt text content. Only xxx_id fields are used;
// no fallback to default templates.