How tdav/myharness works
Purpose and solution shape
MyHarness is an autonomous ReAct coding/research agent backed by Ollama Cloud or compatible Ollama servers. Shared agent behavior lives in the net10.0 library; WinForms and terminal applications are presentation shells over it. Solution entry points are MyHarness/Program.cs and HarnessCli/Program.cs; core assembly and orchestration begin at Harness.Core/AgentHost.cs.
Agent host and model boundary
AgentHost constructs the Microsoft Agent Framework/Harness agent, configures OllamaSharp with Bearer authentication, registers tools, and owns workspace-scoped runtime dependencies. Settings resolve from secret.json and environment variables, with model/context-window changes requiring host recreation while preserving sessions.
• Harness.Core/AgentHost.cs
• Harness.Core/IAgentHost.cs
• Harness.Core/AppSettings.cs
The external model boundary is Ollama’s API: model listing/context discovery and streaming completion traffic go to Ollama Cloud or a local compatible endpoint.
ReAct execution and workspace safety
The agent iterates reasoning, tool selection, execution, and observation. It operates against a selected working directory and exposes file access/search, PowerShell execution, Hyperlight-isolated Python CodeAct, todo/mode/memory capabilities, and optional web tools. UI supplies approval decisions; read-only file operations are auto-approved, while mutations and execution require policy approval.
• Harness.Core/AgentHost.cs
• Harness.Core/Runtime/RunLoop.cs
• Harness.Core/Runtime/TaskQueue.cs
Shell and filesystem execution are a critical trust boundary: workspace scoping, command deny-listing, timeouts, sandboxing, and approval policy protect the host.
Sessions, long-running work, and recovery
Runtime services model queued work, progress, health, notifications, automated recovery, and long-running agent runs. Session persistence preserves conversation state across UI session changes and application restarts; memory services compact/prune context and retain longer-lived information.
• Harness.Core/Persistence/SessionStore.cs
• Harness.Core/Runtime/LongRunManager.cs
• Harness.Core/Runtime/AutoRecovery.cs
• Harness.Core/Memory/LongTermMemory.cs
• Harness.Core/Memory/ContextCompactor.cs
Goal planning and self-improvement
For multi-step work, goals are decomposed into a tree and prioritized for scheduling. Post-run analysis can refine execution strategy and optimize prompts, forming a feedback loop around agent outcomes rather than UI behavior.
• Harness.Core/Goals/GoalDecomposer.cs
• Harness.Core/Goals/GoalTree.cs
• Harness.Core/Goals/PriorityScheduler.cs
• Harness.Core/Evolution/RunAnalyzer.cs
• Harness.Core/Evolution/PromptOptimizer.cs
Extensibility, packaged knowledge, and workflows
Runtime plugins are C# source files compiled with Roslyn and loaded as one-shot tools or resident services. Plugins may call back into the agent through persistent plugin sessions; examples include web search and Telegram. This feature depends on JIT and is unavailable under NativeAOT. Shipped skill/persona documents and .NET scripts are runtime-discovered/copied resources, not compiled agent logic.
• Harness.Core/Plugins/PluginContracts.cs
• Harness.Core/Plugins/PluginManager.cs
• Harness.Core/Workflows/Magentic.cs
• Harness.Core/agents/
• Harness.Core/skills/
UI adapters and observability
WinForms provides WebView2 Markdown rendering and interactive tool approval; SharpConsoleUI provides the equivalent terminal workflow. Both create and drive AgentHost instances, stream transcripts, manage sessions/models/modes, and surface plugin logs. OpenTelemetry spans—including HTTP instrumentation—are file-exported; Serilog application logging is configured by the app hosts.
• MyHarness/UI/MainForm.cs
• MyHarness/UI/MarkdownViewer.cs
• HarnessCli/UI/MainWindow.cs
• Harness.Core/Tracing/HarnessTracing.cs
• Harness.Core/Tracing/FileSpanExporter.cs
Main entry points: AgentHost.cs Agent host · RunLoop.cs ReAct run loop · MainForm.cs WinForms app · MainWindow.cs Terminal app
Components 20
Presentation shells
Interactive WinForms and terminal adapters.
- WinForms app · Drives agent sessions and tool approvals.
MyHarness/UI/MainForm.cs - Markdown viewer
MyHarness/UI/MarkdownViewer.cs - Terminal app · Terminal equivalent of the interactive workflow.
HarnessCli/UI/MainWindow.cs
Agent runtime
Shared net10.0 agent orchestration and state.
- Agent host · Builds the framework agent and workspace-scoped dependencies.
Harness.Core/AgentHost.cs - Agent host contract
Harness.Core/IAgentHost.cs - Settings · Resolves secret.json and environment settings.
Harness.Core/AppSettings.cs - ReAct run loop · Coordinates reasoning, tool execution, and observations.
Harness.Core/Runtime/RunLoop.cs - Task queue
Harness.Core/Runtime/TaskQueue.cs - Workspace tool boundary · Scopes filesystem and shell access; mutations and execution require approval.
Harness.Core/AgentHost.cs - Long-run manager · Tracks progress, health, notifications, and long-running work.
Harness.Core/Runtime/LongRunManager.cs - Auto recovery
Harness.Core/Runtime/AutoRecovery.cs - Session store · Persists conversation state across UI changes and restarts.
Harness.Core/Persistence/SessionStore.cs - Memory services · Compacts context and retains long-lived information.
Harness.Core/Memory/LongTermMemory.cs - Goal planning · Builds goal trees and prioritizes multi-step work.
Harness.Core/Goals/GoalDecomposer.cs - Run evolution · Analyzes outcomes to refine strategy and prompts.
Harness.Core/Evolution/RunAnalyzer.cs - Tracing export · Exports spans, including HTTP instrumentation, to files.
Harness.Core/Tracing/FileSpanExporter.cs
Extensibility
Runtime-loaded capabilities and packaged resources.
- Plugin manager · Compiles C# plugins into one-shot tools or resident services; requires JIT.
Harness.Core/Plugins/PluginManager.cs - Magentic workflows
Harness.Core/Workflows/Magentic.cs - Skills and personas · Discovered packaged documents and scripts, not compiled agent logic.
Other components
- Ollama API · Cloud or compatible local endpoint for discovery and streaming completions.
Connections 23
- WinForms app → Agent host: creates and drives
- Terminal app → Agent host: creates and drives
- WinForms app → Markdown viewer: renders transcripts
- Agent host → Agent host contract: implements
- Agent host → Settings: loads
- Agent host → Ollama API: streams completions
- Agent host → ReAct run loop: runs
- ReAct run loop → Workspace tool boundary: selects tools through
- WinForms app → Workspace tool boundary: supplies approvals
- Terminal app → Workspace tool boundary: supplies approvals
- ReAct run loop → Task queue: queues work
- Task queue → Long-run manager: tracks execution
- Long-run manager → Auto recovery: triggers recovery
- Agent host → Session store: preserves sessions
- ReAct run loop → Memory services: compacts and recalls context
- ReAct run loop → Goal planning: plans multi-step work
- ReAct run loop → Run evolution: sends outcomes
- Run evolution → ReAct run loop: refines prompts and strategy
- Agent host → Plugin manager: registers runtime tools
- Plugin manager → ReAct run loop: adds tools and services
- Agent host → Magentic workflows: hosts
- Agent host → Skills and personas: discovers resources
- Agent host → Tracing export: emits spans