mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-07-14 07:57:26 +02:00
Add files via upload
This commit is contained in:
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"cyberstrike-ai/internal/agent"
|
||||
"cyberstrike-ai/internal/config"
|
||||
"cyberstrike-ai/internal/multiagent"
|
||||
)
|
||||
|
||||
@@ -85,6 +87,11 @@ func runToolNode(ctx context.Context, args RunArgs, node graphNode, state *Workf
|
||||
executionID = result.ExecutionID
|
||||
isError = result.IsError
|
||||
}
|
||||
maxToolOutputBytes := config.MultiAgentEinoMiddlewareConfig{}.ReductionMaxLengthForTruncEffective()
|
||||
if args.AppCfg != nil {
|
||||
maxToolOutputBytes = args.AppCfg.MultiAgent.EinoMiddleware.ReductionMaxLengthForTruncEffective()
|
||||
}
|
||||
output = truncateWorkflowToolOutput(output, maxToolOutputBytes, executionID)
|
||||
out := toolOutputMap(node, output, toolName, toolArgs, executionID, isError)
|
||||
if key := cfgString(node.Config, "output_key"); key != "" {
|
||||
state.Outputs[key] = output
|
||||
@@ -99,6 +106,30 @@ func runToolNode(ctx context.Context, args RunArgs, node graphNode, state *Workf
|
||||
return out, true, "completed", ""
|
||||
}
|
||||
|
||||
func truncateWorkflowToolOutput(output string, maxBytes int, executionID string) string {
|
||||
if maxBytes <= 0 || len(output) <= maxBytes {
|
||||
return output
|
||||
}
|
||||
marker := fmt.Sprintf("\n\n...[workflow tool output truncated; full result is stored in execution %s]...\n\n", strings.TrimSpace(executionID))
|
||||
if strings.TrimSpace(executionID) == "" {
|
||||
marker = "\n\n...[workflow tool output truncated; full result remains in the tool execution record]...\n\n"
|
||||
}
|
||||
budget := maxBytes - len(marker)
|
||||
if budget <= 0 {
|
||||
return marker
|
||||
}
|
||||
head := budget / 2
|
||||
tail := budget - head
|
||||
for head > 0 && !utf8.RuneStart(output[head]) {
|
||||
head--
|
||||
}
|
||||
tailStart := len(output) - tail
|
||||
for tailStart < len(output) && !utf8.RuneStart(output[tailStart]) {
|
||||
tailStart++
|
||||
}
|
||||
return output[:head] + marker + output[tailStart:]
|
||||
}
|
||||
|
||||
func runAgentNode(ctx context.Context, args RunArgs, node graphNode, state *WorkflowLocalState) (map[string]any, bool, string, string) {
|
||||
if args.AppCfg == nil || args.Agent == nil {
|
||||
errText := "Agent 节点执行失败:应用配置或 Agent 为空"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package workflow
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTruncateWorkflowToolOutputBoundsBytesAndKeepsExecutionReference(t *testing.T) {
|
||||
out := truncateWorkflowToolOutput(strings.Repeat("响应正文", 1000), 256, "exec-123")
|
||||
if len(out) > 256 {
|
||||
t.Fatalf("workflow output bytes=%d, want <=256", len(out))
|
||||
}
|
||||
if !strings.Contains(out, "exec-123") || !strings.Contains(out, "truncated") {
|
||||
t.Fatalf("missing truncation reference: %q", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTruncateWorkflowToolOutputLeavesBoundedContentUntouched(t *testing.T) {
|
||||
const want = "small-result"
|
||||
if got := truncateWorkflowToolOutput(want, 256, "exec-123"); got != want {
|
||||
t.Fatalf("got %q want %q", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user