Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
feat(flow): add WaitTaskCompletion method and associated tools for assistant
Dmitry Ng1bb7f8a9a0ab
diff --git a/backend/pkg/controller/flow.go b/backend/pkg/controller/flow.goindex 641cc099..8eefcbe1 100644--- a/backend/pkg/controller/flow.go+++ b/backend/pkg/controller/flow.go@@ -50,6 +50,7 @@ type FlowWorker interface {Finish(ctx context.Context) errorStop(ctx context.Context) errorRename(ctx context.Context, title string) error+ WaitTaskCompletion(ctx context.Context) error}type flowWorker struct {@@ -62,6 +63,8 @@ type flowWorker struct {taskMX *sync.MutextaskST context.CancelFunctaskWG *sync.WaitGroup+ taskCMX sync.Mutex+ taskCCH chan struct{}input chan flowInputflowCtx *FlowContextdataDir string@@ -250,6 +253,7 @@ func NewFlowWorker(taskMX: &sync.Mutex{},taskST: func() {},taskWG: &sync.WaitGroup{},+ taskCCH: make(chan struct{}),input: make(chan flowInput),flowCtx: flowCtx,dataDir: fwc.cfg.DataDir,@@ -403,6 +407,7 @@ func LoadFlowWorker(ctx context.Context, flow database.Flow, fwc flowWorkerCtx)taskMX: &sync.Mutex{},taskST: func() {},taskWG: &sync.WaitGroup{},+ taskCCH: make(chan struct{}),input: make(chan flowInput),flowCtx: flowCtx,dataDir: fwc.cfg.DataDir,@@ -879,6 +884,35 @@ func (fw *flowWorker) finish() error {return nil}+// signalTaskComplete broadcasts task completion to all goroutines currently+// blocked in WaitTaskCompletion. It replaces the shared channel so that future+// callers block on a fresh channel until the next task finishes.+func (fw *flowWorker) signalTaskComplete() {+ fw.taskCMX.Lock()+ old := fw.taskCCH+ fw.taskCCH = make(chan struct{})+ fw.taskCMX.Unlock()+ close(old)+}++// WaitTaskCompletion blocks until the currently running task completes,+// the supplied context expires, or the flow worker itself is stopped.+// Multiple concurrent callers are all unblocked at once when a task finishes.+func (fw *flowWorker) WaitTaskCompletion(ctx context.Context) error {+ fw.taskCMX.Lock()+ ch := fw.taskCCH+ fw.taskCMX.Unlock()++ select {+ case <-ctx.Done():+ return ctx.Err()+ case <-ch:+ return nil+ case <-fw.ctx.Done():+ return nil+ }+}+func (fw *flowWorker) worker() {defer fw.wg.Done()@@ -986,6 +1020,7 @@ func (fw *flowWorker) runTask(spanName, input string, task TaskWorker) error {fw.taskWG.Add(1)defer fw.taskWG.Done()+ defer fw.signalTaskComplete()if err := task.Run(ctx); err != nil {// if task is stopped by user and it's not finished yetdiff --git a/backend/pkg/providers/assistant.go b/backend/pkg/providers/assistant.goindex 3b64013c..64fa3f1b 100644--- a/backend/pkg/providers/assistant.go+++ b/backend/pkg/providers/assistant.go@@ -49,6 +49,7 @@ type FlowWorker interface {PutResources(ctx context.Context, resources []database.UserResource) errorStop(ctx context.Context) errorRename(ctx context.Context, title string) error+ WaitTaskCompletion(ctx context.Context) error}type assistantProvider struct {@@ -327,39 +328,40 @@ func (ap *assistantProvider) getAssistantSystemPrompt(ctx context.Context) (stri}systemAssistantTmpl, err := ap.fp.Prompter().RenderTemplate(templates.PromptTypeAssistant, map[string]any{- "SearchToolName": tools.SearchToolName,- "PentesterToolName": tools.PentesterToolName,- "CoderToolName": tools.CoderToolName,- "AdviceToolName": tools.AdviceToolName,- "MemoristToolName": tools.MemoristToolName,- "MaintenanceToolName": tools.MaintenanceToolName,- "TerminalToolName": tools.TerminalToolName,- "FileToolName": tools.FileToolName,- "GoogleToolName": tools.GoogleToolName,- "DuckDuckGoToolName": tools.DuckDuckGoToolName,- "TavilyToolName": tools.TavilyToolName,- "TraversaalToolName": tools.TraversaalToolName,- "PerplexityToolName": tools.PerplexityToolName,- "BrowserToolName": tools.BrowserToolName,- "SearchInMemoryToolName": tools.SearchInMemoryToolName,- "SearchGuideToolName": tools.SearchGuideToolName,- "SearchAnswerToolName": tools.SearchAnswerToolName,- "SearchCodeToolName": tools.SearchCodeToolName,- "SummarizationToolName": cast.SummarizationToolName,- "SummarizedContentPrefix": strings.ReplaceAll(csum.SummarizedContentPrefix, "\n", "\\n"),- "UseAgents": useAgents,- "DockerImage": ap.fp.Image(),- "Cwd": docker.WorkFolderPathInContainer,- "ContainerPorts": ap.fp.getContainerPortsDescription(),- "ExecutionContext": executionContext,- "Lang": ap.fp.Language(),- "CurrentTime": getCurrentTime(),- "FlowManagerEnabled": ap.flowWorker != nil,- "GetFlowStatusToolName": tools.GetFlowStatusToolName,- "StopFlowToolName": tools.StopFlowToolName,- "SubmitFlowInputToolName": tools.SubmitFlowInputToolName,- "PatchFlowSubtasksToolName": tools.PatchFlowSubtasksToolName,- "UserFiles": ap.fp.userFilesListing(),+ "SearchToolName": tools.SearchToolName,+ "PentesterToolName": tools.PentesterToolName,+ "CoderToolName": tools.CoderToolName,+ "AdviceToolName": tools.AdviceToolName,+ "MemoristToolName": tools.MemoristToolName,+ "MaintenanceToolName": tools.MaintenanceToolName,+ "TerminalToolName": tools.TerminalToolName,+ "FileToolName": tools.FileToolName,+ "GoogleToolName": tools.GoogleToolName,+ "DuckDuckGoToolName": tools.DuckDuckGoToolName,+ "TavilyToolName": tools.TavilyToolName,+ "TraversaalToolName": tools.TraversaalToolName,+ "PerplexityToolName": tools.PerplexityToolName,+ "BrowserToolName": tools.BrowserToolName,+ "SearchInMemoryToolName": tools.SearchInMemoryToolName,+ "SearchGuideToolName": tools.SearchGuideToolName,+ "SearchAnswerToolName": tools.SearchAnswerToolName,+ "SearchCodeToolName": tools.SearchCodeToolName,+ "SummarizationToolName": cast.SummarizationToolName,+ "SummarizedContentPrefix": strings.ReplaceAll(csum.SummarizedContentPrefix, "\n", "\\n"),+ "UseAgents": useAgents,+ "DockerImage": ap.fp.Image(),+ "Cwd": docker.WorkFolderPathInContainer,+ "ContainerPorts": ap.fp.getContainerPortsDescription(),+ "ExecutionContext": executionContext,+ "Lang": ap.fp.Language(),+ "CurrentTime": getCurrentTime(),+ "FlowManagerEnabled": ap.flowWorker != nil,+ "GetFlowStatusToolName": tools.GetFlowStatusToolName,+ "StopFlowToolName": tools.StopFlowToolName,+ "SubmitFlowInputToolName": tools.SubmitFlowInputToolName,+ "PatchFlowSubtasksToolName": tools.PatchFlowSubtasksToolName,+ "WaitFlowCompletionToolName": tools.WaitFlowCompletionToolName,+ "UserFiles": ap.fp.userFilesListing(),})if err != nil {logger.WithError(err).Error("failed to get system prompt for assistant template")@@ -428,6 +430,7 @@ func (ap *assistantProvider) buildFlowManagerHandlers() tools.FlowManagerHandlerStopFlow: ap.stopAssistantFlow,SendFlowInput: ap.sendAssistantFlowInput,PatchSubtasks: ap.patchAssistantFlowSubtasks,+ WaitFlow: ap.waitAssistantFlowCompletion,}}@@ -491,6 +494,24 @@ func (ap *assistantProvider) stopAssistantFlow(ctx context.Context, reason strinreturn nil}+func (ap *assistantProvider) waitAssistantFlowCompletion(ctx context.Context) error {+ logger := logrus.WithContext(ctx).WithFields(logrus.Fields{+ "provider": ap.fp.Type(),+ "assistant_id": ap.id,+ "flow_id": ap.fp.ID(),+ "msg_chain_id": ap.msgChainID,+ })++ logger.Debug("waiting for flow task completion from assistant")++ if ap.flowWorker == nil {+ logger.Error("flow worker is not set")+ return fmt.Errorf("flow worker is not set")+ }++ return ap.flowWorker.WaitTaskCompletion(ctx)+}+func (ap *assistantProvider) sendAssistantFlowInput(ctx context.Context, input string) error {logger := logrus.WithContext(ctx).WithFields(logrus.Fields{"provider": ap.fp.Type(),diff --git a/backend/pkg/templates/prompts/assistant.tmpl b/backend/pkg/templates/prompts/assistant.tmplindex 2aa05427..a5f0ce05 100644--- a/backend/pkg/templates/prompts/assistant.tmpl+++ b/backend/pkg/templates/prompts/assistant.tmpl@@ -340,6 +340,12 @@ Flow states and what each allows:- Targets subtasks with status `created`; you can also explicitly include the ID of the currently active subtask to modify or remove it, which resets it to `created`- After patching, the response lists the new subtask IDs — use those IDs for any subsequent references- Obtain the `task_id` via `{{.GetFlowStatusToolName}}` with `detail=tasks`++**`{{.WaitFlowCompletionToolName}}`** — block until the currently running automation task finishes or the timeout expires.+- Use when you need to wait for the automation to complete before inspecting results or taking further action+- `timeout` — seconds to wait; 0 or negative → 60 s default; values above 3600 are capped at 1 hour+- Returns immediately (without blocking) if no tasks exist or if no task is running+- Always call `{{.GetFlowStatusToolName}}` with `detail='summary'` after this tool returns to see the final state</flow_management_tools><flow_management_protocols>@@ -347,6 +353,11 @@ Flow states and what each allows:1. `{{.GetFlowStatusToolName}}` with `detail=summary`2. Drill deeper as needed: `detail=running` for the active chain, `detail=tasks` or `detail=subtasks` for history+**User asks you to wait until the automation finishes:**+1. `{{.GetFlowStatusToolName}}` with `detail=summary` to confirm the flow is running+2. `{{.WaitFlowCompletionToolName}}` with an appropriate `timeout` (default 60 s; up to 3600 s)+3. After it returns, call `{{.GetFlowStatusToolName}}` with `detail=summary` to report the final state to the user+**User asks what was found or accomplished:**1. `{{.GetFlowStatusToolName}}` with `detail=subtasks` to see completed work with results2. Use `{{.MemoristToolName}}` to retrieve findings stored in long-term memory@@ -376,6 +387,7 @@ Flow states and what each allows:- `{{.SubmitFlowInputToolName}}` and `{{.PatchFlowSubtasksToolName}}` are rejected when flow is `running` — stop first- `{{.PatchFlowSubtasksToolName}}` requires at least one existing task — if no tasks exist yet, use `{{.SubmitFlowInputToolName}}` to create the first one- `{{.PatchFlowSubtasksToolName}}` recreates the planned subtask list with new IDs — always use the IDs from the response for any further operations on those subtasks+- `{{.WaitFlowCompletionToolName}}` returns immediately if no task is running — always verify the flow state with `{{.GetFlowStatusToolName}}` first when unsure- `finished` and `failed` are terminal states — no tool can restart the flow; report the final state to the user</flow_management_constraints>{{end}}diff --git a/backend/pkg/templates/templates.go b/backend/pkg/templates/templates.goindex 57c0f7ed..d1833212 100644--- a/backend/pkg/templates/templates.go+++ b/backend/pkg/templates/templates.go@@ -121,6 +121,7 @@ var PromptVariables = map[PromptType][]string{"StopFlowToolName","SubmitFlowInputToolName","PatchFlowSubtasksToolName",+ "WaitFlowCompletionToolName","UserFiles",},PromptTypePentester: {diff --git a/backend/pkg/templates/validator/testdata.go b/backend/pkg/templates/validator/testdata.goindex 3b4612e4..0d623391 100644--- a/backend/pkg/templates/validator/testdata.go+++ b/backend/pkg/templates/validator/testdata.go@@ -25,47 +25,48 @@ func CreateDummyTemplateData() map[string]any {return map[string]any{// Tool names - exact values from tools package constants- "FinalyToolName": tools.FinalyToolName,- "SearchToolName": tools.SearchToolName,- "PentesterToolName": tools.PentesterToolName,- "CoderToolName": tools.CoderToolName,- "AdviceToolName": tools.AdviceToolName,- "MemoristToolName": tools.MemoristToolName,- "MaintenanceToolName": tools.MaintenanceToolName,- "GraphitiSearchToolName": tools.GraphitiSearchToolName,- "GraphitiEnabled": true,- "TerminalToolName": tools.TerminalToolName,- "FileToolName": tools.FileToolName,- "BrowserToolName": tools.BrowserToolName,- "GoogleToolName": tools.GoogleToolName,- "DuckDuckGoToolName": tools.DuckDuckGoToolName,- "SploitusToolName": tools.SploitusToolName,- "TavilyToolName": tools.TavilyToolName,- "TraversaalToolName": tools.TraversaalToolName,- "PerplexityToolName": tools.PerplexityToolName,- "SearchInMemoryToolName": tools.SearchInMemoryToolName,- "SearchGuideToolName": tools.SearchGuideToolName,- "SearchAnswerToolName": tools.SearchAnswerToolName,- "SearchCodeToolName": tools.SearchCodeToolName,- "StoreGuideToolName": tools.StoreGuideToolName,- "StoreAnswerToolName": tools.StoreAnswerToolName,- "StoreCodeToolName": tools.StoreCodeToolName,- "SearchResultToolName": tools.SearchResultToolName,- "EnricherToolName": tools.EnricherResultToolName,- "MemoristResultToolName": tools.MemoristResultToolName,- "MaintenanceResultToolName": tools.MaintenanceResultToolName,- "CodeResultToolName": tools.CodeResultToolName,- "HackResultToolName": tools.HackResultToolName,- "EnricherResultToolName": tools.EnricherResultToolName,- "ReportResultToolName": tools.ReportResultToolName,- "SubtaskListToolName": tools.SubtaskListToolName,- "SubtaskPatchToolName": tools.SubtaskPatchToolName,- "AskUserToolName": tools.AskUserToolName,- "AskUserEnabled": true,- "GetFlowStatusToolName": tools.GetFlowStatusToolName,- "StopFlowToolName": tools.StopFlowToolName,- "SubmitFlowInputToolName": tools.SubmitFlowInputToolName,- "PatchFlowSubtasksToolName": tools.PatchFlowSubtasksToolName,+ "FinalyToolName": tools.FinalyToolName,+ "SearchToolName": tools.SearchToolName,+ "PentesterToolName": tools.PentesterToolName,+ "CoderToolName": tools.CoderToolName,+ "AdviceToolName": tools.AdviceToolName,+ "MemoristToolName": tools.MemoristToolName,+ "MaintenanceToolName": tools.MaintenanceToolName,+ "GraphitiSearchToolName": tools.GraphitiSearchToolName,+ "GraphitiEnabled": true,+ "TerminalToolName": tools.TerminalToolName,+ "FileToolName": tools.FileToolName,+ "BrowserToolName": tools.BrowserToolName,+ "GoogleToolName": tools.GoogleToolName,+ "DuckDuckGoToolName": tools.DuckDuckGoToolName,+ "SploitusToolName": tools.SploitusToolName,+ "TavilyToolName": tools.TavilyToolName,+ "TraversaalToolName": tools.TraversaalToolName,+ "PerplexityToolName": tools.PerplexityToolName,+ "SearchInMemoryToolName": tools.SearchInMemoryToolName,+ "SearchGuideToolName": tools.SearchGuideToolName,+ "SearchAnswerToolName": tools.SearchAnswerToolName,+ "SearchCodeToolName": tools.SearchCodeToolName,+ "StoreGuideToolName": tools.StoreGuideToolName,+ "StoreAnswerToolName": tools.StoreAnswerToolName,+ "StoreCodeToolName": tools.StoreCodeToolName,+ "SearchResultToolName": tools.SearchResultToolName,+ "EnricherToolName": tools.EnricherResultToolName,+ "MemoristResultToolName": tools.MemoristResultToolName,+ "MaintenanceResultToolName": tools.MaintenanceResultToolName,+ "CodeResultToolName": tools.CodeResultToolName,+ "HackResultToolName": tools.HackResultToolName,+ "EnricherResultToolName": tools.EnricherResultToolName,+ "ReportResultToolName": tools.ReportResultToolName,+ "SubtaskListToolName": tools.SubtaskListToolName,+ "SubtaskPatchToolName": tools.SubtaskPatchToolName,+ "AskUserToolName": tools.AskUserToolName,+ "AskUserEnabled": true,+ "GetFlowStatusToolName": tools.GetFlowStatusToolName,+ "StopFlowToolName": tools.StopFlowToolName,+ "SubmitFlowInputToolName": tools.SubmitFlowInputToolName,+ "PatchFlowSubtasksToolName": tools.PatchFlowSubtasksToolName,+ "WaitFlowCompletionToolName": tools.WaitFlowCompletionToolName,// Summarization related - using constants from proper packages"SummarizationToolName": cast.SummarizationToolName,diff --git a/backend/pkg/tools/args.go b/backend/pkg/tools/args.goindex ae837b89..881880b9 100644--- a/backend/pkg/tools/args.go+++ b/backend/pkg/tools/args.go@@ -271,6 +271,12 @@ type SubmitFlowInputAction struct {Message string `json:"message" jsonschema:"required,title=Input message" jsonschema_description:"Engagement-log entry — a 1-2 short sentence running commentary describing what is being submitted to the automation. Written in the engagement language declared by your system prompt."`}+// WaitFlowCompletionAction defines arguments for the wait_flow_completion tool.+type WaitFlowCompletionAction struct {+ Timeout Int64 `json:"timeout" jsonschema:"required,type=integer" jsonschema_description:"How long to wait for the running automation task to finish, in seconds. Use 0 or a negative value to apply the default timeout of 60 seconds. Values above 3600 are capped at 3600 seconds (1 hour)."`+ Message string `json:"message" jsonschema:"required,title=Wait message" jsonschema_description:"Engagement-log entry — a 1-2 short sentence running commentary explaining why you are waiting for the automation to finish. Written in the engagement language declared by your system prompt."`+}+// PatchFlowSubtasksAction defines arguments for the patch_flow_subtasks tool.type PatchFlowSubtasksAction struct {TaskID int64 `json:"task_id" jsonschema:"required,type=integer" jsonschema_description:"ID of the task whose subtask plan to modify. Obtain this from get_flow_status with detail='tasks'."`diff --git a/backend/pkg/tools/flow_manager.go b/backend/pkg/tools/flow_manager.goindex 6a3c7b3f..00845104 100644--- a/backend/pkg/tools/flow_manager.go+++ b/backend/pkg/tools/flow_manager.go@@ -23,21 +23,23 @@ func NewFlowStatusTool(flowID int64, db database.Querier, summarizer SummarizeHa}const (- msgLogLimitNormal = 10- msgLogLimitVerbose = 50- flowOperationTimeout = 15 * time.Second- taskReadyPollInterval = 5 * time.Second- taskReadyPollTimeout = 2 * time.Minute- msgLogsLimit = 16 * 1024 // 16 KB- summaryLimit = 32 * 1024 // 32 KB- taskListLimit = 32 * 1024 // 32 KB- subtasksListLimit = 48 * 1024 // 48 KB- plannedListLimit = 32 * 1024 // 32 KB- runningInfoLimit = 48 * 1024 // 48 KB- inputLimit = 8 * 1024 // 8 KB- descriptionLimit = 4 * 1024 // 4 KB- resultLimit = 8 * 1024 // 8 KB- summarizationLimit = 128 * 1024 // 128 KB hard limit+ msgLogLimitNormal = 10+ msgLogLimitVerbose = 50+ flowOperationTimeout = 15 * time.Second+ taskReadyPollInterval = 5 * time.Second+ taskReadyPollTimeout = 2 * time.Minute+ waitFlowDefaultTimeout = 1 * time.Minute+ waitFlowMaxTimeout = 1 * time.Hour+ msgLogsLimit = 16 * 1024 // 16 KB+ summaryLimit = 32 * 1024 // 32 KB+ taskListLimit = 32 * 1024 // 32 KB+ subtasksListLimit = 48 * 1024 // 48 KB+ plannedListLimit = 32 * 1024 // 32 KB+ runningInfoLimit = 48 * 1024 // 48 KB+ inputLimit = 8 * 1024 // 8 KB+ descriptionLimit = 4 * 1024 // 4 KB+ resultLimit = 8 * 1024 // 8 KB+ summarizationLimit = 128 * 1024 // 128 KB hard limit)func (t *flowStatusTool) Handle(ctx context.Context, name string, args json.RawMessage) (string, error) {@@ -499,6 +501,86 @@ func truncateText(s string, maxLen int) string {return s[:maxLen] + "..."}+// waitFlowCompletionTool implements wait_flow_completion — blocks until the+// currently running task finishes or the caller-supplied timeout expires.+type waitFlowCompletionTool struct {+ flowID int64+ db database.Querier+ handler func(ctx context.Context) error+}++func NewWaitFlowCompletionTool(+ flowID int64,+ db database.Querier,+ handler func(ctx context.Context) error,+) *waitFlowCompletionTool {+ return &waitFlowCompletionTool{flowID: flowID, db: db, handler: handler}+}++func (t *waitFlowCompletionTool) Handle(ctx context.Context, name string, args json.RawMessage) (string, error) {+ var action WaitFlowCompletionAction+ if err := json.Unmarshal(args, &action); err != nil {+ return "", fmt.Errorf("failed to parse %s args: %w", WaitFlowCompletionToolName, err)+ }++ timeout := time.Duration(action.Timeout.Int64()) * time.Second+ switch {+ case timeout <= 0:+ timeout = waitFlowDefaultTimeout+ case timeout > waitFlowMaxTimeout:+ timeout = waitFlowMaxTimeout+ }++ tasks, err := t.db.GetFlowTasks(ctx, t.flowID)+ if err != nil {+ return "", fmt.Errorf("failed to check flow status: %w", err)+ }++ if len(tasks) == 0 {+ return fmt.Sprintf(+ "The automation has not been created yet — no tasks exist. "++ "Use %s to submit the first task description and start the automation.",+ SubmitFlowInputToolName), nil+ }++ isRunning := false+ for _, task := range tasks {+ if task.Status == database.TaskStatusRunning {+ isRunning = true+ break+ }+ }++ if !isRunning {+ return fmt.Sprintf(+ "The automation is not currently running — no task has status 'running'. "++ "Call %s with detail='summary' to assess the current flow state before proceeding.",+ GetFlowStatusToolName), nil+ }++ waitCtx, waitCancel := context.WithTimeout(ctx, timeout)+ defer waitCancel()++ if err := t.handler(waitCtx); err != nil {+ if errors.Is(err, context.DeadlineExceeded) {+ return fmt.Sprintf(+ "The automation task is still running after waiting %s. "++ "Call %s with detail='running' to see what the agent is doing right now.",+ timeout, GetFlowStatusToolName), nil+ }+ if errors.Is(err, context.Canceled) {+ return "", fmt.Errorf(+ "wait cancelled — the assistant session was interrupted while waiting for the automation")+ }+ return "", fmt.Errorf("wait for flow completion failed: %w", err)+ }++ return fmt.Sprintf(+ "The automation task has completed. "++ "Call %s with detail='summary' to see the final status and results.",+ GetFlowStatusToolName), nil+}+// stopFlowTool implements stop_flow.type stopFlowTool struct {flowID int64diff --git a/backend/pkg/tools/registry.go b/backend/pkg/tools/registry.goindex 9cf8296a..8041b5da 100644--- a/backend/pkg/tools/registry.go+++ b/backend/pkg/tools/registry.go@@ -9,45 +9,46 @@ import ()const (- FinalyToolName = "done"- AskUserToolName = "ask"- MaintenanceToolName = "maintenance"- MaintenanceResultToolName = "maintenance_result"- CoderToolName = "coder"- CodeResultToolName = "code_result"- PentesterToolName = "pentester"- HackResultToolName = "hack_result"- AdviceToolName = "advice"- MemoristToolName = "memorist"- MemoristResultToolName = "memorist_result"- BrowserToolName = "browser"- GoogleToolName = "google"- DuckDuckGoToolName = "duckduckgo"- TavilyToolName = "tavily"- TraversaalToolName = "traversaal"- PerplexityToolName = "perplexity"- SearxngToolName = "searxng"- SploitusToolName = "sploitus"- SearchToolName = "search"- SearchResultToolName = "search_result"- EnricherResultToolName = "enricher_result"- SearchInMemoryToolName = "search_in_memory"- SearchGuideToolName = "search_guide"- StoreGuideToolName = "store_guide"- SearchAnswerToolName = "search_answer"- StoreAnswerToolName = "store_answer"- SearchCodeToolName = "search_code"- StoreCodeToolName = "store_code"- GraphitiSearchToolName = "graphiti_search"- ReportResultToolName = "report_result"- SubtaskListToolName = "subtask_list"- SubtaskPatchToolName = "subtask_patch"- TerminalToolName = "terminal"- FileToolName = "file"- GetFlowStatusToolName = "get_flow_status"- StopFlowToolName = "stop_flow"- SubmitFlowInputToolName = "submit_flow_input"- PatchFlowSubtasksToolName = "patch_flow_subtasks"+ FinalyToolName = "done"+ AskUserToolName = "ask"+ MaintenanceToolName = "maintenance"+ MaintenanceResultToolName = "maintenance_result"+ CoderToolName = "coder"+ CodeResultToolName = "code_result"+ PentesterToolName = "pentester"+ HackResultToolName = "hack_result"+ AdviceToolName = "advice"+ MemoristToolName = "memorist"+ MemoristResultToolName = "memorist_result"+ BrowserToolName = "browser"+ GoogleToolName = "google"+ DuckDuckGoToolName = "duckduckgo"+ TavilyToolName = "tavily"+ TraversaalToolName = "traversaal"+ PerplexityToolName = "perplexity"+ SearxngToolName = "searxng"+ SploitusToolName = "sploitus"+ SearchToolName = "search"+ SearchResultToolName = "search_result"+ EnricherResultToolName = "enricher_result"+ SearchInMemoryToolName = "search_in_memory"+ SearchGuideToolName = "search_guide"+ StoreGuideToolName = "store_guide"+ SearchAnswerToolName = "search_answer"+ StoreAnswerToolName = "store_answer"+ SearchCodeToolName = "search_code"+ StoreCodeToolName = "store_code"+ GraphitiSearchToolName = "graphiti_search"+ ReportResultToolName = "report_result"+ SubtaskListToolName = "subtask_list"+ SubtaskPatchToolName = "subtask_patch"+ TerminalToolName = "terminal"+ FileToolName = "file"+ GetFlowStatusToolName = "get_flow_status"+ StopFlowToolName = "stop_flow"+ SubmitFlowInputToolName = "submit_flow_input"+ PatchFlowSubtasksToolName = "patch_flow_subtasks"+ WaitFlowCompletionToolName = "wait_flow_completion")type ToolType int@@ -93,45 +94,46 @@ func GetToolType(name string) ToolType {}var toolsTypeMapping = map[string]ToolType{- FinalyToolName: BarrierToolType,- AskUserToolName: BarrierToolType,- MaintenanceToolName: AgentToolType,- MaintenanceResultToolName: StoreAgentResultToolType,- CoderToolName: AgentToolType,- CodeResultToolName: StoreAgentResultToolType,- PentesterToolName: AgentToolType,- HackResultToolName: StoreAgentResultToolType,- AdviceToolName: AgentToolType,- MemoristToolName: AgentToolType,- MemoristResultToolName: StoreAgentResultToolType,- BrowserToolName: SearchNetworkToolType,- GoogleToolName: SearchNetworkToolType,- DuckDuckGoToolName: SearchNetworkToolType,- TavilyToolName: SearchNetworkToolType,- TraversaalToolName: SearchNetworkToolType,- PerplexityToolName: SearchNetworkToolType,- SearxngToolName: SearchNetworkToolType,- SploitusToolName: SearchNetworkToolType,- SearchToolName: AgentToolType,- SearchResultToolName: StoreAgentResultToolType,- EnricherResultToolName: StoreAgentResultToolType,- SearchInMemoryToolName: SearchVectorDbToolType,- SearchGuideToolName: SearchVectorDbToolType,- StoreGuideToolName: StoreVectorDbToolType,- SearchAnswerToolName: SearchVectorDbToolType,- StoreAnswerToolName: StoreVectorDbToolType,- SearchCodeToolName: SearchVectorDbToolType,- StoreCodeToolName: StoreVectorDbToolType,- GraphitiSearchToolName: SearchVectorDbToolType,- ReportResultToolName: StoreAgentResultToolType,- SubtaskListToolName: StoreAgentResultToolType,- SubtaskPatchToolName: StoreAgentResultToolType,- TerminalToolName: EnvironmentToolType,- FileToolName: EnvironmentToolType,- GetFlowStatusToolName: EnvironmentToolType,- StopFlowToolName: EnvironmentToolType,- SubmitFlowInputToolName: EnvironmentToolType,- PatchFlowSubtasksToolName: EnvironmentToolType,+ FinalyToolName: BarrierToolType,+ AskUserToolName: BarrierToolType,+ MaintenanceToolName: AgentToolType,+ MaintenanceResultToolName: StoreAgentResultToolType,+ CoderToolName: AgentToolType,+ CodeResultToolName: StoreAgentResultToolType,+ PentesterToolName: AgentToolType,+ HackResultToolName: StoreAgentResultToolType,+ AdviceToolName: AgentToolType,+ MemoristToolName: AgentToolType,+ MemoristResultToolName: StoreAgentResultToolType,+ BrowserToolName: SearchNetworkToolType,+ GoogleToolName: SearchNetworkToolType,+ DuckDuckGoToolName: SearchNetworkToolType,+ TavilyToolName: SearchNetworkToolType,+ TraversaalToolName: SearchNetworkToolType,+ PerplexityToolName: SearchNetworkToolType,+ SearxngToolName: SearchNetworkToolType,+ SploitusToolName: SearchNetworkToolType,+ SearchToolName: AgentToolType,+ SearchResultToolName: StoreAgentResultToolType,+ EnricherResultToolName: StoreAgentResultToolType,+ SearchInMemoryToolName: SearchVectorDbToolType,+ SearchGuideToolName: SearchVectorDbToolType,+ StoreGuideToolName: StoreVectorDbToolType,+ SearchAnswerToolName: SearchVectorDbToolType,+ StoreAnswerToolName: StoreVectorDbToolType,+ SearchCodeToolName: SearchVectorDbToolType,+ StoreCodeToolName: StoreVectorDbToolType,+ GraphitiSearchToolName: SearchVectorDbToolType,+ ReportResultToolName: StoreAgentResultToolType,+ SubtaskListToolName: StoreAgentResultToolType,+ SubtaskPatchToolName: StoreAgentResultToolType,+ TerminalToolName: EnvironmentToolType,+ FileToolName: EnvironmentToolType,+ GetFlowStatusToolName: EnvironmentToolType,+ StopFlowToolName: EnvironmentToolType,+ SubmitFlowInputToolName: EnvironmentToolType,+ PatchFlowSubtasksToolName: EnvironmentToolType,+ WaitFlowCompletionToolName: EnvironmentToolType,}var reflector = &jsonschema.Reflector{@@ -418,6 +420,15 @@ var registryDefinitions = map[string]llms.FunctionDefinition{"Returns an error if a task is currently running — cancel it first.",Parameters: reflector.Reflect(&PatchFlowSubtasksAction{}),},+ WaitFlowCompletionToolName: {+ Name: WaitFlowCompletionToolName,+ Description: "Block until the currently running automation task completes (or the timeout expires). " ++ "Use this when you need to wait for the automation to finish before inspecting its results or taking further action. " ++ "Returns immediately with an informational message if no tasks exist or if no task is currently running — " ++ "use " + GetFlowStatusToolName + " first to confirm the flow state before calling this tool. " ++ "On return, always call " + GetFlowStatusToolName + " with detail='summary' to inspect the final status.",+ Parameters: reflector.Reflect(&WaitFlowCompletionAction{}),+ },}func getMessageType(name string) database.MsglogType {diff --git a/backend/pkg/tools/tools.go b/backend/pkg/tools/tools.goindex 9c677e18..c025d4dd 100644--- a/backend/pkg/tools/tools.go+++ b/backend/pkg/tools/tools.go@@ -204,11 +204,12 @@ type AssistantExecutorConfig struct {}// FlowManagerHandlers holds optional callbacks for automation flow control.-// When StopFlow is non-nil all four flow-management tools are registered.+// Each non-nil handler enables its corresponding flow-management tool in the assistant executor.type FlowManagerHandlers struct {StopFlow func(ctx context.Context, reason string) errorSendFlowInput func(ctx context.Context, input string) errorPatchSubtasks func(ctx context.Context, taskID int64, patch SubtaskPatch) error+ WaitFlow func(ctx context.Context) error}type PrimaryExecutorConfig struct {@@ -955,6 +956,12 @@ func (fte *flowToolsExecutor) GetAssistantExecutor(cfg AssistantExecutorConfig)handlers[PatchFlowSubtasksToolName] = patchSubtasks.Handle}+ if cfg.FlowManager.WaitFlow != nil {+ waitFlowCompletion := NewWaitFlowCompletionTool(fte.flowID, fte.db, cfg.FlowManager.WaitFlow)+ definitions = append(definitions, registryDefinitions[WaitFlowCompletionToolName])+ handlers[WaitFlowCompletionToolName] = waitFlowCompletion.Handle+ }+ce := &customExecutor{userID: fte.userID,flowID: fte.flowID,