Skip to content

[dotnet-code] Cache agent mode display internals #911

Description

@github-actions

Summary

Cache the agent-mode provider's supported-mode display string during construction instead of rebuilding it each time tools are created. This mirrors the .NET provider's stored mode-name display field and keeps future .NET-to-Go ports structurally easier to compare without changing public APIs or behavior.

.NET Reference

  • dotnet/src/Microsoft.Agents.AI/Harness/AgentMode/AgentModeProvider.cs - stores _modeNamesDisplay during provider construction and reuses it in tool descriptions and validation errors.

Public API and Behavior

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

Tests

  • go test ./agent/harness/agentmode

Notes

Rejected candidates:

  • dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSessionStateBagValue.cs overlapped with the existing open PR [dotnet-code] Consolidate portable value delayed decode helper #900.
  • dotnet/src/Microsoft.Agents.AI.Workflows/HandoffToolCallFilteringBehavior.cs has no matching Go implementation; adding it would be a feature.
  • dotnet/src/Microsoft.Agents.AI.Workflows/Configured.cs did not expose a similarly small, behavior-preserving Go cleanup after comparison with workflow executor internals.

Generated by .NET-to-Go Code Portability Refactoring Agent · gpt55 · 78.8 AIC · ⌖ 15.8 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-agentmode-display-1787697166-0d28664376ddac17.

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 (90 of 90 lines)
From 37f098b92bf12b8171b81271b0a0da6878022e6c Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Tue, 25 Aug 2026 22:32:46 +0000
Subject: [PATCH] Cache agent mode display internals

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 agent/harness/agentmode/agentmode.go | 32 +++++++++++++---------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/agent/harness/agentmode/agentmode.go b/agent/harness/agentmode/agentmode.go
index cfad5f890..46de188be 100644
--- a/agent/harness/agentmode/agentmode.go
+++ b/agent/harness/agentmode/agentmode.go
@@ -130,6 +130,7 @@ func New(cfg Config) *Provider {
 
 	// Validate modes: no empty names, no duplicates.
 	validModes := make(map[string]struct{}, len(modes))
+	modeNames := make([]string, 0, len(modes))
 	for i, m := range modes {
 		if strings.TrimSpace(m.Name) == "" {
 			panic(fmt.Sprintf("agentmode: mode at index %d has an empty name", i))
@@ -138,16 +139,18 @@ func New(cfg Config) *Provider {
 			panic(fmt.Sprintf("agentmode: duplicate mode name %q", m.Name))
 		}
 		validModes[m.Name] = struct{}{}
+		modeNames = append(modeNames, m.Name)
 	}
 	if _, ok := validModes[defaultMode]; !ok {
 		panic(fmt.Sprintf("agentmode: default mode %q is not in the configured modes list", defaultMode))
 	}
 
 	p := &Provider{
-		modes:        modes,
-		defaultMode:  defaultMode,
-		instructions: instructions,
-		validModes:   validModes,
+		modes:            modes,
+		defaultMode:      defaultMode,
+		instructions:     instructions,
+		validModes:       validModes,
+		modeNamesDisplay: strings.Join(modeNames, "\", \""),
 	}
 
 	p.provider = agent.NewContextProvider(agent.ContextProviderConfig{
@@ -160,11 +163,12 @@ func New(cfg Config) *Provider {
 // Provider is an agent mode context provider.
 // Use [New] to create. Provider can be used directly in agent configuration.
 type Provider struct {
-	provider     agent.ContextProvider
-	modes     
... (truncated)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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