From fbec1ad96604142f0de76c757573343b0e5ef5dc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 7 Aug 2026 00:39:32 +0000 Subject: [PATCH] Consolidate agent host request dispatch internals Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- workflow/agentworkflow/hosting.go | 46 +++++++++++++------------------ 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/workflow/agentworkflow/hosting.go b/workflow/agentworkflow/hosting.go index f206b181..43f7944d 100644 --- a/workflow/agentworkflow/hosting.go +++ b/workflow/agentworkflow/hosting.go @@ -581,44 +581,36 @@ func (h *hostExecutor) dispatchRequests(wctx *workflow.Context, msgs []*message. } } - var approvalDispatches []*message.ToolApprovalRequestContent - var callDispatches []*message.FunctionCallContent - for _, id := range approvalOrder { - approval, ok := approvalRequests[id] - if !ok { - continue - } - delete(approvalRequests, id) - added, err := h.approvalHandler.TrackRequest(wctx, approval) - if err != nil { - return err - } - if added { - approvalDispatches = append(approvalDispatches, approval) - } + if err := dispatchTrackedRequests(wctx, approvalOrder, approvalRequests, h.approvalHandler); err != nil { + return err } - for _, id := range callOrder { - call, ok := functionCalls[id] + return dispatchTrackedRequests(wctx, callOrder, functionCalls, h.callHandler) +} + +type requestDispatcher[T any] interface { + TrackRequest(*workflow.Context, T) (bool, error) + DispatchRequest(*workflow.Context, T) error +} + +func dispatchTrackedRequests[T any](wctx *workflow.Context, order []string, requests map[string]T, dispatcher requestDispatcher[T]) error { + dispatches := make([]T, 0, len(order)) + for _, id := range order { + request, ok := requests[id] if !ok { continue } - delete(functionCalls, id) - added, err := h.callHandler.TrackRequest(wctx, call) + delete(requests, id) + added, err := dispatcher.TrackRequest(wctx, request) if err != nil { return err } if added { - callDispatches = append(callDispatches, call) + dispatches = append(dispatches, request) } } - for _, approval := range approvalDispatches { - if err := h.approvalHandler.DispatchRequest(wctx, approval); err != nil { - return err - } - } - for _, call := range callDispatches { - if err := h.callHandler.DispatchRequest(wctx, call); err != nil { + for _, request := range dispatches { + if err := dispatcher.DispatchRequest(wctx, request); err != nil { return err } }