mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-04-21 18:26:38 +02:00
Add files via upload
This commit is contained in:
+24
-10
@@ -1619,7 +1619,7 @@ type BatchTaskRequest struct {
|
||||
Title string `json:"title"` // 任务标题(可选)
|
||||
Tasks []string `json:"tasks" binding:"required"` // 任务列表,每行一个任务
|
||||
Role string `json:"role,omitempty"` // 角色名称(可选,空字符串表示默认角色)
|
||||
AgentMode string `json:"agentMode,omitempty"` // single | deep | plan_execute | supervisor(旧版 multi 视为 deep)
|
||||
AgentMode string `json:"agentMode,omitempty"` // single | eino_single | deep | plan_execute | supervisor(react 同 single;旧版 multi 视为 deep)
|
||||
ScheduleMode string `json:"scheduleMode,omitempty"` // manual | cron
|
||||
CronExpr string `json:"cronExpr,omitempty"` // scheduleMode=cron 时必填
|
||||
ExecuteNow bool `json:"executeNow,omitempty"` // 创建后是否立即执行(默认 false)
|
||||
@@ -1630,9 +1630,12 @@ func normalizeBatchQueueAgentMode(mode string) string {
|
||||
if m == "multi" {
|
||||
return "deep"
|
||||
}
|
||||
if m == "" || m == "single" {
|
||||
if m == "" || m == "single" || m == "react" {
|
||||
return "single"
|
||||
}
|
||||
if m == "eino_single" {
|
||||
return "eino_single"
|
||||
}
|
||||
switch config.NormalizeMultiAgentOrchestration(m) {
|
||||
case "plan_execute":
|
||||
return "plan_execute"
|
||||
@@ -2272,12 +2275,15 @@ func (h *AgentHandler) executeBatchQueue(queueID string) {
|
||||
// 使用队列配置的角色工具列表(如果为空,表示使用所有工具)
|
||||
// 注意:skills不会硬编码注入,但会在系统提示词中提示AI这个角色推荐使用哪些skills
|
||||
useBatchMulti := false
|
||||
useEinoSingle := false
|
||||
batchOrch := "deep"
|
||||
am := strings.TrimSpace(strings.ToLower(queue.AgentMode))
|
||||
if am == "multi" {
|
||||
am = "deep"
|
||||
}
|
||||
if batchQueueWantsEino(queue.AgentMode) && h.config != nil && h.config.MultiAgent.Enabled {
|
||||
if am == "eino_single" {
|
||||
useEinoSingle = true
|
||||
} else if batchQueueWantsEino(queue.AgentMode) && h.config != nil && h.config.MultiAgent.Enabled {
|
||||
useBatchMulti = true
|
||||
batchOrch = config.NormalizeMultiAgentOrchestration(am)
|
||||
} else if queue.AgentMode == "" {
|
||||
@@ -2287,12 +2293,20 @@ func (h *AgentHandler) executeBatchQueue(queueID string) {
|
||||
batchOrch = "deep"
|
||||
}
|
||||
}
|
||||
useRunResult := useBatchMulti || useEinoSingle
|
||||
var result *agent.AgentLoopResult
|
||||
var resultMA *multiagent.RunResult
|
||||
var runErr error
|
||||
if useBatchMulti {
|
||||
switch {
|
||||
case useBatchMulti:
|
||||
resultMA, runErr = multiagent.RunDeepAgent(ctx, h.config, &h.config.MultiAgent, h.agent, h.logger, conversationID, finalMessage, []agent.ChatMessage{}, roleTools, progressCallback, h.agentsMarkdownDir, batchOrch)
|
||||
} else {
|
||||
case useEinoSingle:
|
||||
if h.config == nil {
|
||||
runErr = fmt.Errorf("服务器配置未加载")
|
||||
} else {
|
||||
resultMA, runErr = multiagent.RunEinoSingleChatModelAgent(ctx, h.config, &h.config.MultiAgent, h.agent, h.logger, conversationID, finalMessage, []agent.ChatMessage{}, roleTools, roleSkills, progressCallback)
|
||||
}
|
||||
default:
|
||||
result, runErr = h.agent.AgentLoopWithProgress(ctx, finalMessage, []agent.ChatMessage{}, conversationID, progressCallback, roleTools, roleSkills)
|
||||
}
|
||||
// 任务执行完成,清理取消函数
|
||||
@@ -2306,10 +2320,10 @@ func (h *AgentHandler) executeBatchQueue(queueID string) {
|
||||
// 3. 检查 result.Response 中是否包含取消相关的消息
|
||||
errStr := runErr.Error()
|
||||
partialResp := ""
|
||||
if result != nil {
|
||||
partialResp = result.Response
|
||||
} else if resultMA != nil {
|
||||
if useRunResult && resultMA != nil {
|
||||
partialResp = resultMA.Response
|
||||
} else if result != nil {
|
||||
partialResp = result.Response
|
||||
}
|
||||
isCancelled := errors.Is(runErr, context.Canceled) ||
|
||||
strings.Contains(strings.ToLower(errStr), "context canceled") ||
|
||||
@@ -2348,7 +2362,7 @@ func (h *AgentHandler) executeBatchQueue(queueID string) {
|
||||
if err := h.db.SaveReActData(conversationID, result.LastReActInput, result.LastReActOutput); err != nil {
|
||||
h.logger.Warn("保存取消任务的ReAct数据失败", zap.String("queueId", queueID), zap.String("taskId", task.ID), zap.Error(err))
|
||||
}
|
||||
} else if resultMA != nil && (resultMA.LastReActInput != "" || resultMA.LastReActOutput != "") {
|
||||
} else if useRunResult && resultMA != nil && (resultMA.LastReActInput != "" || resultMA.LastReActOutput != "") {
|
||||
if err := h.db.SaveReActData(conversationID, resultMA.LastReActInput, resultMA.LastReActOutput); err != nil {
|
||||
h.logger.Warn("保存取消任务的ReAct数据失败", zap.String("queueId", queueID), zap.String("taskId", task.ID), zap.Error(err))
|
||||
}
|
||||
@@ -2379,7 +2393,7 @@ func (h *AgentHandler) executeBatchQueue(queueID string) {
|
||||
var resText string
|
||||
var mcpIDs []string
|
||||
var lastIn, lastOut string
|
||||
if useBatchMulti {
|
||||
if useRunResult {
|
||||
resText = resultMA.Response
|
||||
mcpIDs = resultMA.MCPExecutionIDs
|
||||
lastIn = resultMA.LastReActInput
|
||||
|
||||
@@ -57,7 +57,7 @@ type BatchTaskQueue struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Role string `json:"role,omitempty"` // 角色名称(空字符串表示默认角色)
|
||||
AgentMode string `json:"agentMode"` // single | deep | plan_execute | supervisor
|
||||
AgentMode string `json:"agentMode"` // single | eino_single | deep | plan_execute | supervisor
|
||||
ScheduleMode string `json:"scheduleMode"` // manual | cron
|
||||
CronExpr string `json:"cronExpr,omitempty"`
|
||||
NextRunAt *time.Time `json:"nextRunAt,omitempty"`
|
||||
|
||||
@@ -132,7 +132,7 @@ func RegisterBatchTaskMCPTools(mcpServer *mcp.Server, h *AgentHandler, logger *z
|
||||
|
||||
【何时用】用户明确要批量排队执行、Cron 周期跑同一批指令、或需要与任务管理页面对齐时调用。需要即时追问、强依赖当前对话上下文的分析/编码,应在本对话内直接完成,不要为了“委派”而创建队列。
|
||||
|
||||
【参数】tasks(字符串数组)或 tasks_text(多行,每行一条)二选一;每项是一条将来由系统按队列顺序执行的指令文案。agent_mode:single(默认)或 multi(仅表示队列内每条子任务使用的执行模式,需系统已启用多代理);非“把主对话拆给子代理”。schedule_mode:manual(默认)或 cron;cron 须填 cron_expr(5 段,如 "0 */6 * * *")。
|
||||
【参数】tasks(字符串数组)或 tasks_text(多行,每行一条)二选一;每项是一条将来由系统按队列顺序执行的指令文案。agent_mode:single(原生 ReAct,默认)、eino_single(Eino ADK 单代理)、deep / plan_execute / supervisor(需系统启用多代理);兼容旧值 multi(视为 deep)。非“把主对话拆给子代理”。schedule_mode:manual(默认)或 cron;cron 须填 cron_expr(5 段,如 "0 */6 * * *")。
|
||||
|
||||
【执行】默认创建后为 pending,不自动跑。execute_now=true 可创建后立即跑;否则之后调用 batch_task_start。Cron 自动下一轮需 schedule_enabled 为 true(可用 batch_task_schedule_enabled)。`,
|
||||
ShortDescription: "任务管理:创建批量任务队列(登记多条指令,可选立即或 Cron)",
|
||||
@@ -158,8 +158,8 @@ func RegisterBatchTaskMCPTools(mcpServer *mcp.Server, h *AgentHandler, logger *z
|
||||
},
|
||||
"agent_mode": map[string]interface{}{
|
||||
"type": "string",
|
||||
"description": "队列内子任务的执行模式:single 或 multi(multi 需系统启用多代理;非子代理委派语义)",
|
||||
"enum": []string{"single", "multi"},
|
||||
"description": "执行模式:single(原生 ReAct)、eino_single(Eino ADK)、deep/plan_execute/supervisor(Eino 编排,需启用多代理);multi 兼容为 deep",
|
||||
"enum": []string{"single", "eino_single", "deep", "plan_execute", "supervisor", "multi"},
|
||||
},
|
||||
"schedule_mode": map[string]interface{}{
|
||||
"type": "string",
|
||||
@@ -384,8 +384,8 @@ func RegisterBatchTaskMCPTools(mcpServer *mcp.Server, h *AgentHandler, logger *z
|
||||
},
|
||||
"agent_mode": map[string]interface{}{
|
||||
"type": "string",
|
||||
"description": "代理模式:single(单代理 ReAct)或 multi(多代理)",
|
||||
"enum": []string{"single", "multi"},
|
||||
"description": "代理模式:single、eino_single、deep、plan_execute、supervisor;multi 视为 deep",
|
||||
"enum": []string{"single", "eino_single", "deep", "plan_execute", "supervisor", "multi"},
|
||||
},
|
||||
},
|
||||
"required": []string{"queue_id"},
|
||||
|
||||
@@ -405,8 +405,8 @@ func (h *OpenAPIHandler) GetOpenAPISpec(c *gin.Context) {
|
||||
},
|
||||
"agentMode": map[string]interface{}{
|
||||
"type": "string",
|
||||
"description": "代理模式:single(ReAct)| deep | plan_execute | supervisor(Eino);旧值 multi 按 deep",
|
||||
"enum": []string{"single", "deep", "plan_execute", "supervisor", "multi"},
|
||||
"description": "代理模式:single(原生 ReAct)| eino_single(Eino ADK 单代理)| deep | plan_execute | supervisor;react 同 single;旧值 multi 按 deep",
|
||||
"enum": []string{"single", "eino_single", "deep", "plan_execute", "supervisor", "multi", "react"},
|
||||
},
|
||||
"scheduleMode": map[string]interface{}{
|
||||
"type": "string",
|
||||
|
||||
Reference in New Issue
Block a user