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"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
jsonv2 "github.com/go-json-experiment/json"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
jsonv2 "github.com/go-json-experiment/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DAGToolRuntime executes tool calls according to an explicit dependency DAG.
|
// 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 := toolCall
|
||||||
tc.Input = resolvedInput
|
tc.Input = resolvedInput
|
||||||
res, critical := executeSingleToolCompat(ctx, toolMap, tc, nil)
|
res, critical := executeSingleTool(ctx, toolMap, tc, nil)
|
||||||
return res, critical, nil
|
return res, critical, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ func (r ParallelToolRuntime) Execute(ctx context.Context, tools []AgentTool, too
|
||||||
barrierWaits++
|
barrierWaits++
|
||||||
emit()
|
emit()
|
||||||
logEvent(ToolRuntimeLogEvent{Event: "barrier_start", ToolCallID: toolCalls[i].ToolCallID, ToolName: toolCalls[i].ToolName})
|
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})
|
logEvent(ToolRuntimeLogEvent{Event: "barrier_finish", ToolCallID: toolCalls[i].ToolCallID, ToolName: toolCalls[i].ToolName})
|
||||||
results[i] = res
|
results[i] = res
|
||||||
if critical {
|
if critical {
|
||||||
|
|
@ -119,7 +119,7 @@ func (r ParallelToolRuntime) Execute(ctx context.Context, tools []AgentTool, too
|
||||||
emit()
|
emit()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
res, critical := executeSingleToolCompat(ctx, toolMap, tc, nil)
|
res, critical := executeSingleTool(ctx, toolMap, tc, nil)
|
||||||
outcomes[localIndex] = outcome{res: res, critical: critical}
|
outcomes[localIndex] = outcome{res: res, critical: critical}
|
||||||
logEvent(ToolRuntimeLogEvent{Event: "finish", ToolCallID: tc.ToolCallID, ToolName: tc.ToolName})
|
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
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// executeSingleToolCompat mirrors the legacy sequential agent tool execution
|
// executeSingleTool executes a single tool call and returns the result.
|
||||||
// semantics, but is packaged as a helper so tool runtimes can share it.
|
// This helper is shared by all tool runtimes (sequential, parallel, DAG).
|
||||||
func executeSingleToolCompat(ctx context.Context, toolMap map[string]AgentTool, toolCall ToolCallContent, toolResultCallback func(result ToolResultContent) error) (ToolResultContent, bool) {
|
func executeSingleTool(ctx context.Context, toolMap map[string]AgentTool, toolCall ToolCallContent, toolResultCallback func(result ToolResultContent) error) (ToolResultContent, bool) {
|
||||||
result := ToolResultContent{
|
result := ToolResultContent{
|
||||||
ToolCallID: toolCall.ToolCallID,
|
ToolCallID: toolCall.ToolCallID,
|
||||||
ToolName: toolCall.ToolName,
|
ToolName: toolCall.ToolName,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue