Skip to content

[dotnet-code] Consolidate agent host request dispatch internals #811

Description

@github-actions

Summary

Consolidates the duplicated hosted-agent request tracking and dispatch loops used for tool approval requests and unterminated function calls into one unexported helper. This keeps the Go hosting internals structurally closer to the .NET host option model where request interception is handled through common host behavior, while preserving the existing public Go config shape and dispatch semantics.

.NET Reference

  • dotnet/src/Microsoft.Agents.AI.Workflows/AIAgentHostOptions.cs - host options describing intercepted user-input requests, intercepted unterminated function calls, forwarded messages, and agent response/update emission.

Public API and Behavior

No public Go API changed. No intentional behavior change was made.

Tests

  • go test ./workflow/agentworkflow

Notes

Rejected sampled candidates:

Generated by .NET-to-Go Code Portability Refactoring Agent · gpt55 · 112.1 AIC · ⌖ 32.4 AIC · ⊞ 23.2K ·


Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch dotnet-code/agent-host-request-dispatch-f2801c8f8cc41e6e.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ

Show patch preview (82 of 82 lines)
From 7eeac5113d758c7bce7fe56eaa0b5ae034da2b84 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Fri, 7 Aug 2026 00:33:39 +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 f206b1818..43f7944de 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)

... (truncated)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions