Add files via upload

This commit is contained in:
公明
2026-06-04 10:33:39 +08:00
committed by GitHub
parent 9b0efbb90f
commit e791782c46
4 changed files with 56 additions and 23 deletions
+1 -7
View File
@@ -160,13 +160,7 @@ func RunEinoSingleChatModelAgent(
handlers = append(handlers, capMw)
}
maxIter := ma.MaxIteration
if maxIter <= 0 {
maxIter = appCfg.Agent.MaxIterations
}
if maxIter <= 0 {
maxIter = 40
}
maxIter := agentMaxIterations(appCfg)
mainToolsCfg := adk.ToolsConfig{
ToolsNodeConfig: compose.ToolsNodeConfig{
+22
View File
@@ -0,0 +1,22 @@
package multiagent
import "cyberstrike-ai/internal/config"
const defaultAgentMaxIterations = 3000
// agentMaxIterations 全局上限:仅使用 config.agent.max_iterations;≤0 时与 config 默认一致为 3000。
func agentMaxIterations(appCfg *config.Config) int {
if appCfg != nil && appCfg.Agent.MaxIterations > 0 {
return appCfg.Agent.MaxIterations
}
return defaultAgentMaxIterations
}
// resolveMaxIterations 统一迭代上限:Markdown/子代理 front matter 中 max_iterations>0 可单独覆盖,否则使用 agent.max_iterations。
// multi_agent.max_iteration 与 sub_agent_max_iterations 已废弃,不再参与计算。
func resolveMaxIterations(appCfg *config.Config, markdownOverride int) int {
if markdownOverride > 0 {
return markdownOverride
}
return agentMaxIterations(appCfg)
}
@@ -0,0 +1,31 @@
package multiagent
import (
"testing"
"cyberstrike-ai/internal/config"
)
func TestAgentMaxIterations(t *testing.T) {
if got := agentMaxIterations(nil); got != defaultAgentMaxIterations {
t.Fatalf("nil cfg: got %d want %d", got, defaultAgentMaxIterations)
}
cfg := &config.Config{Agent: config.AgentConfig{MaxIterations: 12000}}
if got := agentMaxIterations(cfg); got != 12000 {
t.Fatalf("got %d want 12000", got)
}
cfg.Agent.MaxIterations = 0
if got := agentMaxIterations(cfg); got != defaultAgentMaxIterations {
t.Fatalf("zero: got %d want %d", got, defaultAgentMaxIterations)
}
}
func TestResolveMaxIterations(t *testing.T) {
cfg := &config.Config{Agent: config.AgentConfig{MaxIterations: 12000}}
if got := resolveMaxIterations(cfg, 0); got != 12000 {
t.Fatalf("global: got %d want 12000", got)
}
if got := resolveMaxIterations(cfg, 50); got != 50 {
t.Fatalf("override: got %d want 50", got)
}
}
+2 -16
View File
@@ -170,18 +170,7 @@ func RunDeepAgent(
}
reasoning.ApplyToEinoChatModelConfig(baseModelCfg, &appCfg.OpenAI, reasoningClient)
deepMaxIter := ma.MaxIteration
if deepMaxIter <= 0 {
deepMaxIter = appCfg.Agent.MaxIterations
}
if deepMaxIter <= 0 {
deepMaxIter = 40
}
subDefaultIter := ma.SubAgentMaxIterations
if subDefaultIter <= 0 {
subDefaultIter = 20
}
deepMaxIter := agentMaxIterations(appCfg)
var subAgents []adk.Agent
if orchMode != "plan_execute" {
@@ -230,10 +219,7 @@ func RunDeepAgent(
return nil, fmt.Errorf("子代理 %q eino 中间件: %w", id, err)
}
subMax := sub.MaxIterations
if subMax <= 0 {
subMax = subDefaultIter
}
subMax := resolveMaxIterations(appCfg, sub.MaxIterations)
subSumMw, err := newEinoSummarizationMiddleware(ctx, subModel, appCfg, &ma.EinoMiddleware, conversationID, logger)
if err != nil {