Files
westey 96d242fa7f .NET: Remove required token params from HarnessAgent, make compaction opt-in (#6409)
* Move token params from HarnessAgent constructor to options

Remove the required maxContextWindowTokens and maxOutputTokens
constructor parameters from HarnessAgent and AsHarnessAgent, replacing
them with optional MaxContextWindowTokens and MaxOutputTokens properties
on HarnessAgentOptions.

When both values are provided, compaction is enabled as before (in-loop
CompactionProvider and chat reducer on the default InMemoryChatHistory
Provider). When either is null, compaction is disabled entirely, making
it opt-in.

New constructor: HarnessAgent(IChatClient, HarnessAgentOptions?,
ILoggerFactory?, IServiceProvider?)

Closes #6333

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

* Improving comments.

* feat: Add custom CompactionStrategy and DisableCompaction to HarnessAgentOptions

Allow users to provide their own CompactionStrategy via options, with
a clear priority system:
1. DisableCompaction=true: no compaction regardless of other settings
2. Custom CompactionStrategy provided: use it (token params ignored)
3. Both MaxContextWindowTokens and MaxOutputTokens set: default strategy
4. Otherwise: no compaction

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

* fix: Address PR review comments on compaction opt-in

- Update chatClient param XML doc to reflect compaction is opt-in
- Strengthen compaction tests to assert ChatReducer is null/not-null
  rather than just asserting construction succeeds

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

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
96d242fa7f · 2026-06-09 13:06:00 +00:00
History
..

Harness Step 04 — Code Execution (Hyperlight + Skills)

This sample demonstrates a HarnessAgent with all features enabled, plus:

  • Hyperlight CodeAct — sandboxed Python code execution via execute_code (requires KVM)
  • Skills — file-based skill discovery (a regex-tester skill is included)

The agent can plan tasks, manage modes, store memories, read/write files, search the web, approve sensitive operations, discover and use skills, and execute arbitrary Python code — all pre-configured by the HarnessAgent.

Prerequisites

  • .NET 10 SDK
  • An Azure AI Foundry project endpoint
  • KVM-capable host (the Hyperlight sandbox runs code in micro-VMs)

Environment Variables

Variable Description
AZURE_AI_PROJECT_ENDPOINT Your Azure AI Foundry project endpoint
AZURE_AI_MODEL_DEPLOYMENT_NAME Model deployment name (default: gpt-5.4)

Running

dotnet run

What to Try

  • Regex testing: "Help me write a regex that matches valid email addresses, then test it against some examples."
  • Code execution: "Calculate the first 20 prime numbers using the Sieve of Eratosthenes."
  • Skill + code combo: "I need a regex for ISO 8601 dates — test it thoroughly with edge cases."

Included Skill

The skills/regex-tester/ skill instructs the agent to validate regex patterns by executing Python test code in the Hyperlight sandbox. It includes a regex cheatsheet as reference material.

Features Enabled

Feature Description
TodoProvider Task planning and tracking (/todos command)
AgentModeProvider Mode switching (/mode command)
FileMemoryProvider Persistent memory stored as files
FileAccessProvider Read/write files in a working directory
ToolApproval Don't-ask-again approval for sensitive tools
WebSearch Built-in hosted web search
AgentSkillsProvider Discovers and uses skills from the skills/ folder
HyperlightCodeActProvider Sandboxed Python execution via execute_code
OpenTelemetry Trace logging to a text file