Skip to content

[dotnet-code] Refactor Copilot session event dispatch #376

Description

@github-actions

Summary

Extracted Copilot session event dispatch into an unexported helper so the run loop focuses on queueing and yielding updates. This mirrors the .NET Copilot provider's structure where session events are converted through dedicated response-update conversion paths, making future .NET-to-Go ports easier to compare without changing behavior.

.NET Reference

  • dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs - handles Copilot session events by converting each event kind to an agent response update and completing on idle/error events.

Public API and Behavior

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

Tests

  • go test ./agent/provider/copilotagent

Notes

Rejected candidates:

  • dotnet/src/Microsoft.Agents.AI/Harness/Loop/AIJudgeLoopEvaluatorOptions.cs - Go loop harness has completion-marker evaluators but no matching AI judge implementation to safely refactor without adding missing .NET features.
  • dotnet/src/Microsoft.Agents.AI.Workflows/ExternalResponse.cs - Go has the corresponding workflow.ExternalResponse, but adding .NET-style typed helper methods would expand the public API.
  • dotnet/src/Microsoft.Agents.AI.AGUI/Shared/ReasoningEndEvent.cs - Go AGUI hosting already emits reasoning end events through existing protocol constructors; no narrow internal cleanup was apparent from this sampled file.

Generated by .NET-to-Go Code Portability Refactoring Agent · 485 AIC · ⌖ 41.6 AIC · ⊞ 20.8K ·


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/copilot-event-dispatch-f1beb03e90e4da0a.

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 (78 of 78 lines)
From 12b8eda926bbd943c6cb1cc6c939c12c2311e400 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Fri, 26 Jun 2026 22:48:54 +0000
Subject: [PATCH] Refactor Copilot session event dispatch

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 agent/provider/copilotagent/copilot.go | 46 ++++++++++++--------------
 1 file changed, 22 insertions(+), 24 deletions(-)

diff --git a/agent/provider/copilotagent/copilot.go b/agent/provider/copilotagent/copilot.go
index 962c9f127..855492d4e 100644
--- a/agent/provider/copilotagent/copilot.go
+++ b/agent/provider/copilotagent/copilot.go
@@ -121,30 +121,7 @@ func (p *provider) run(ctx context.Context, messages []*message.Message, options
 				yield(nil, err)
 				return
 			}
-			var update *agent.ResponseUpdate
-			var done bool
-			var eventErr error
-			switch data := event.Data.(type) {
-			case *copilot.AssistantMessageDeltaData:
-				update = p.assistantMessageDeltaUpdate(event, data)
-			case *copilot.AssistantMessageData:
-				update = p.assistantMessageUpdate(event, data, isStreaming)
-			case *copilot.ToolExecutionStartData:
-				update = p.toolExecutionStartUpdate(event, data)
-			case *copilot.ToolExecutionCompleteData:
-				update = p.toolExecutionCompleteUpdate(event, data)
-			case *copilot.AssistantUsageData:
-				update = p.assistantUsageUpdate(event, data)
-			case *copilot.SessionIdleData:
-				update = rawEventUpdate(event)
-				done = true
-			case *copilot.SessionErrorData:
-				update = rawEventUpdate(event)
-				done = true
-				eventErr = fmt.Errorf("session error: %s", sessionErrorMessage(data))
-			default:
-				update = rawEventUpdate(event)
-			}
+			update, done, eventErr := p.responseUpdateForSessionEvent(event, isStreaming)
 			if update != nil {
 				if !yield(update, nil) {
 					return
@@ -161,6 +138,27 @@ func (p *provider) run(ctx context.Context, messages []*message.Message, options
 	}
 }
 
+func (p *provider) respons
... (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