CyberStrikeAI/internal/multiagent/pi_control.go

30 lines
1.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package multiagent
import (
"context"
"cyberstrike-ai/internal/agentruntime"
"cyberstrike-ai/internal/config"
"github.com/google/uuid"
"path/filepath"
)
// RunNativeControl uses the same Pi SDK for planner/reviewer tool loops. Its only
// tools are the explicit task-local catalog; it cannot discover user extensions.
func RunNativeControl(ctx context.Context, cfg *config.Config, storageKey, instruction string, native agentruntime.NativeWorkflow, definitions []agentruntime.Tool, execute agentruntime.ToolExecutor, emit func(agentruntime.Event)) (*agentruntime.Result, error) {
if native.CompletionTool != "" && native.WrapupPrompt == "" {
native.WrapupPrompt = "本轮控制会话即将到达回合上限,禁止继续查询工具;请立即调用 " + native.CompletionTool + " 提交结构化结果(禁止返回纯文本 JSON)。"
if native.WrapupTurns <= 0 {
native.WrapupTurns = 2
}
}
req := agentruntime.Request{RunID: uuid.NewString(), SystemPrompt: instruction, Message: "Continue the assessment using the latest host state. Submit a structured decision with the provided tool.", Model: piModelConfig(cfg.OpenAI, nil, storageKey), Tools: definitions, SessionDir: filepath.Join(cfg.AgentSessionDir(), "deep-assessments", agentruntime.ConversationStorageKey(storageKey)), MaxTurns: 16, NativeWorkflow: &native}
req.RetryMax = cfg.MultiAgent.Runtime.ModelRetryMaxRetries
req.RetryMaxDelayMS = cfg.MultiAgent.Runtime.ModelRetryMaxBackoffSec * 1000
for _, id := range cfg.MultiAgent.Runtime.ModelFailoverChannels {
if ch, _, ok := cfg.ResolveAIChannel(id); ok {
req.FallbackModels = append(req.FallbackModels, piModelConfig(ch, nil, storageKey))
}
}
return (agentruntime.Pi{NodePath: cfg.AgentRuntime.NodePath, WorkerPath: cfg.AgentRuntime.WorkerPath}).Run(ctx, req, execute, emit, nil)
}