Skip to content

.NET: Refactor harness console to be more extensible and easy to understand with better UX#5573

Merged
westey-m merged 4 commits intomicrosoft:feature-harnessfrom
westey-m:harness-console-refactor
Apr 30, 2026
Merged

.NET: Refactor harness console to be more extensible and easy to understand with better UX#5573
westey-m merged 4 commits intomicrosoft:feature-harnessfrom
westey-m:harness-console-refactor

Conversation

@westey-m
Copy link
Copy Markdown
Contributor

Motivation and Context

The harness console code was hard to understand and a bit spaghetti-ish, so refactoring so that it is more structured and easier to understand and extend.

Description

  • Separated out most code into Observers which can take action based on the agent output.
  • Main loop stays in HarnessConsole.
  • Ensured that ConsoleWriter is responsible for dealing with the spinner and line breaks, so other code doesn't have to.
  • Introduced better UX with pickers for option selection
  • Introduced a planning mode observer that uses structured output to require the agent to provide either follow up questions or ask for approval.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@moonbox3 moonbox3 added the .NET label Apr 29, 2026
@github-actions github-actions Bot changed the title Refactor harness console to be more extensible and easy to understand with better UX .NET: Refactor harness console to be more extensible and easy to understand with better UX Apr 29, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 3 | Confidence: 94% | Result: All clear

Reviewed: Correctness, Test Coverage, Design Approach


Automated review by westey-m's agents

@westey-m westey-m marked this pull request as ready for review April 29, 2026 18:20
Copilot AI review requested due to automatic review settings April 29, 2026 18:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors the .NET harness interactive console into a more extensible, observer-driven architecture and introduces improved UX (including selection pickers and a structured planning mode).

Changes:

  • Reworked HarnessConsole into a loop that fans out streaming updates to pluggable ConsoleObservers.
  • Added structured planning UX (clarifications + approval flow) and a centralized ConsoleWriter that manages spinner/formatting.
  • Introduced command handlers (/todos, /mode) and added Spectre.Console for interactive selection prompts.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
dotnet/samples/02-agents/Harness/Harness_Step01_Research/Program.cs Enables planning UX via HarnessConsoleOptions and updates the planning instructions text.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/ToolCallFormatter.cs Moves tool call formatter into the Observers namespace.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/UsageDisplayObserver.cs Adds an observer to render token usage details.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/ToolCallDisplayObserver.cs Adds an observer to render tool call notifications.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/ToolApprovalObserver.cs Adds an observer to collect & prompt for tool approval decisions after streaming.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/TextOutputObserver.cs Adds an observer to stream normal text output.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/ReasoningDisplayObserver.cs Adds an observer to render reasoning content.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/PlanningResponseType.cs Defines enum for structured planning response types.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/PlanningResponse.cs Defines JSON-serializable schema for planning responses/questions.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/PlanningOutputObserver.cs Implements planning-mode structured output parsing + UX for clarifications/approval + mode switching.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/ErrorDisplayObserver.cs Adds an observer to render error content.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Observers/ConsoleObserver.cs Introduces the observer base class and streaming lifecycle hooks.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Harness_Shared_Console.csproj Adds Spectre.Console package dependency.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/HarnessConsoleOptions.cs Adds options for token budgets, planning UX, and mode colors.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/HarnessConsole.cs Refactors the harness loop to use observers + command handlers + options.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/ConsoleWriter.cs Centralizes spinner management, formatted output, and selection prompts.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Commands/TodoCommandHandler.cs Extracts /todos behavior into a command handler.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Commands/ModeCommandHandler.cs Extracts /mode behavior into a command handler.
dotnet/samples/02-agents/Harness/Harness_Shared_Console/Commands/ICommandHandler.cs Defines an interface for console commands.
dotnet/Directory.Packages.props Pins Spectre.Console package version.

Comment thread dotnet/samples/02-agents/Harness/Harness_Step01_Research/Program.cs Outdated
Comment thread dotnet/samples/02-agents/Harness/Harness_Step01_Research/Program.cs Outdated
Comment thread dotnet/samples/02-agents/Harness/Harness_Shared_Console/ConsoleWriter.cs Outdated
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 2 | Confidence: 90% | Result: All clear

Reviewed: Test Coverage, Design Approach


Automated review by westey-m's agents

@westey-m westey-m merged commit 97228e4 into microsoft:feature-harness Apr 30, 2026
12 checks passed
pull Bot pushed a commit to nagyist/ms-agent-framework that referenced this pull request May 1, 2026
* .NET: Add a TODO AIContextProvider (microsoft#5233)

* Add a TODO AIContextProvider

* Add unit tests

* Address PR comments

* Address PR comments

* Fix test after removing one tool

* .NET: Add a ModeProvider for managing agent modes (microsoft#5247)

* Add a ModeProvider for managing agent modes

* Fix typo

* Fix typo

* Fix typo

* Address PR comments

* .NET: Add sample to show how to build a harness (microsoft#5268)

* Add sample to show how to build a harness

* Improve sample

* Sample max output tokens and model

* Fix encoding

* Fix model name in readme

* Address PR comments

* .NET: Add context window size compaction strategy for harness (microsoft#5304)

* Add context window size compaction strategy for harness

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Address PR comments

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* .NET: Add a file memory provider (microsoft#5315)

* Add a file memory provider

* Address PR comments

* Fix review comments.

* Add additional unit tests

* Addressing PR comments.

* .NET:  Harness: Improve prompts and add FileSystem store (microsoft#5365)

* Harness: Improve prompts and add FileSystem store

* Address PR comments

* .NET: Harness: Improve path validation (microsoft#5404)

* Harness: Improve path validation

* Address PR comments

* .NET: Add always approve helpers, improve sample and fix bug (microsoft#5451)

* Add always approve helpers, improve sample and fix bug

* Address PR comments

* .NET: Make Todo, Mode and FileMemory providers more configurable (microsoft#5477)

* Make Todo, Mode and FileMemory providers more configurable

* Address PR comments.

* .NET: Add subagents provider and sample (microsoft#5518)

* Add subagents provider and sample

* Addressing PR comments.

* .NET: Harness filememory index plus instructions consistency (microsoft#5540)

* Add FileMemoryProvider index and improve instruction consistency

* Address PR comments.

* Address PR comments

* Address PR comments.

* Apply suggestion from @rogerbarreto

Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>

---------

Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>

* .NET: Refactor harness console to be more extensible and easy to understand with better UX (microsoft#5573)

* Refactor harness console to be more extensible and easy to understand with better UX.

* Fix formatting issues.

* Allow multiple clarifications in one response

* Address PR comments

* .NET: Add FileAccessProvdider and concurrency fix for FileMemoryProvider (microsoft#5583)

* Add FileAccessProvdider and concurrency fix for FileMemoryProvider

* Address PR comments

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants