refactor(fantasy): update tool runtime dag and parallel
This commit is contained in:
parent
388c0952fb
commit
c9de7266c7
2 changed files with 8 additions and 7 deletions
|
|
@ -4,11 +4,12 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
jsonv2 "github.com/go-json-experiment/json"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
jsonv2 "github.com/go-json-experiment/json"
|
||||
)
|
||||
|
||||
// DAGToolRuntime executes tool calls according to an explicit dependency DAG.
|
||||
|
|
@ -222,7 +223,7 @@ func executeDAGNode(ctx context.Context, toolMap map[string]AgentTool, toolCall
|
|||
}
|
||||
tc := toolCall
|
||||
tc.Input = resolvedInput
|
||||
res, critical := executeSingleToolCompat(ctx, toolMap, tc, nil)
|
||||
res, critical := executeSingleTool(ctx, toolMap, tc, nil)
|
||||
return res, critical, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func (r ParallelToolRuntime) Execute(ctx context.Context, tools []AgentTool, too
|
|||
barrierWaits++
|
||||
emit()
|
||||
logEvent(ToolRuntimeLogEvent{Event: "barrier_start", ToolCallID: toolCalls[i].ToolCallID, ToolName: toolCalls[i].ToolName})
|
||||
res, critical := executeSingleToolCompat(ctx, toolMap, toolCalls[i], toolResultCallback)
|
||||
res, critical := executeSingleTool(ctx, toolMap, toolCalls[i], toolResultCallback)
|
||||
logEvent(ToolRuntimeLogEvent{Event: "barrier_finish", ToolCallID: toolCalls[i].ToolCallID, ToolName: toolCalls[i].ToolName})
|
||||
results[i] = res
|
||||
if critical {
|
||||
|
|
@ -119,7 +119,7 @@ func (r ParallelToolRuntime) Execute(ctx context.Context, tools []AgentTool, too
|
|||
emit()
|
||||
}()
|
||||
|
||||
res, critical := executeSingleToolCompat(ctx, toolMap, tc, nil)
|
||||
res, critical := executeSingleTool(ctx, toolMap, tc, nil)
|
||||
outcomes[localIndex] = outcome{res: res, critical: critical}
|
||||
logEvent(ToolRuntimeLogEvent{Event: "finish", ToolCallID: tc.ToolCallID, ToolName: tc.ToolName})
|
||||
}()
|
||||
|
|
@ -145,9 +145,9 @@ func (r ParallelToolRuntime) Execute(ctx context.Context, tools []AgentTool, too
|
|||
return results, nil
|
||||
}
|
||||
|
||||
// executeSingleToolCompat mirrors the legacy sequential agent tool execution
|
||||
// semantics, but is packaged as a helper so tool runtimes can share it.
|
||||
func executeSingleToolCompat(ctx context.Context, toolMap map[string]AgentTool, toolCall ToolCallContent, toolResultCallback func(result ToolResultContent) error) (ToolResultContent, bool) {
|
||||
// executeSingleTool executes a single tool call and returns the result.
|
||||
// This helper is shared by all tool runtimes (sequential, parallel, DAG).
|
||||
func executeSingleTool(ctx context.Context, toolMap map[string]AgentTool, toolCall ToolCallContent, toolResultCallback func(result ToolResultContent) error) (ToolResultContent, bool) {
|
||||
result := ToolResultContent{
|
||||
ToolCallID: toolCall.ToolCallID,
|
||||
ToolName: toolCall.ToolName,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue