Agent Harness and Claw

ibobev2 pts0 comments

Meet your agent harness and claw | Microsoft Agent Framework

Skip to main content

Dev Blogs

AI

All .NET posts

.NET MAUI<br>ASP.NET Core<br>Blazor<br>Entity Framework

C++<br>C#<br>F#<br>TypeScript

NuGet<br>Servicing<br>.NET Blog in Chinese

Microsoft for Developers<br>Agent Framework<br>Develop from the cloud<br>Xcode<br>ISE Developer<br>TypeScript<br>PowerShell<br>Python<br>Java<br>Java Blog in Chinese<br>Go<br>Microsoft Edge Dev<br>Microsoft 365 Developer<br>Microsoft Entra Identity Developer<br>Microsoft Entra PowerShell

Visual Studio<br>Visual Studio Code<br>Aspire

All things Azure<br>Azure SDK<br>Azure VM Runtime Team<br>Microsoft Azure<br>Azure Cosmos DB<br>Azure DocumentDB<br>Azure Data Studio<br>Azure SQL<br>DevOps<br>DirectX<br>Microsoft Foundry<br>Power Platform

OData<br>Unified Data Model (IDEAs)

Windows Command Line<br>#ifdef Windows<br>Inside MSIX<br>MIDI and music<br>React Native<br>The Old New Thing<br>Windows Developer

Wes Steyn

Principal Software Engineer

Part 1 of Build your own claw and agent harness with Microsoft Agent Framework.

In the overview we said a "claw" is really just an agent harness: a loop around a model, wired up with tools, planning, memory, and more. In this first post we stand up that loop and give our personal finance assistant its first three abilities:

a custom tool (get_stock_price),

web search for market news, and

planning – so a vague request like "Review my watchlist and recommend some stocks to add" becomes a tracked, step-by-step

plan.

The remarkable part: we get almost all of this for free. Agent Framework’s harness bundles function invocation, history persistence, planning, and web search into a single call. We only supply what makes our agent ours – its instructions and its custom tool.

Let’s build it in three steps: construct a chat client, turn it into a harness, then run it through an interactive console.

Step 1 – Construct a chat client

Everything starts with a chat client – the thing that actually talks to a model. We point it at an endpoint, give it a credential for auth, and tell it which model deployment to use.

In this example we are using Microsoft Foundry with the Responses API.

.NET

// Read configuration from environment variables.<br>var endpoint = Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT")<br>?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT is not set.");<br>var deploymentName = Environment.GetEnvironmentVariable("FOUNDRY_MODEL") ?? "gpt-5.4";

// Build an IChatClient backed by a Microsoft Foundry project.<br>IChatClient chatClient =<br>new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential())<br>.GetProjectOpenAIClient()<br>.GetResponsesClient()<br>.AsIChatClient(deploymentName);

FOUNDRY_PROJECT_ENDPOINT – your Microsoft Foundry project endpoint.

FOUNDRY_MODEL – the model deployment to call (e.g. gpt-5.4).

DefaultAzureCredential – handles auth from your environment (e.g. run az login locally to use its session). In

production, prefer a specific credential such as ManagedIdentityCredential.

Python

# FoundryChatClient reads FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL from the environment.<br>client = FoundryChatClient(credential=AzureCliCredential())

FOUNDRY_PROJECT_ENDPOINT – your Microsoft Foundry project endpoint.

FOUNDRY_MODEL – the model deployment to call.

AzureCliCredential – uses your az login session; swap in any other credential you prefer.

Many clients, one harness. We used a Microsoft Foundry client here, but the harness works with any chat client – Azure OpenAI, OpenAI, Anthropic, Google Gemini, Ollama, and more.

See the provider samples for how to construct each one:

.NET AgentProviders ·

Python providers.

Also see the documentation for all providers.

Step 2 – Turn the chat client into a harness

Now we wrap that client in the harness. In .NET you call AsHarnessAgent; in Python you call create_harness_agent. For now, we supply just two things: instructions (what the agent is for) and a custom tool .

Instructions

The harness handles how to operate; our instructions describe what the agent is for.

.NET

var instructions =<br>"""<br>## Personal Finance Assistant Instructions

You are a personal finance and investing assistant. When asked about a stock, look up its<br>current price with the get_stock_price tool, and use web search for recent news, earnings,<br>or analyst commentary.

### Working style<br>- Always verify numbers with a tool rather than relying on memory. Stock prices change.<br>- Cite web sources inline when you use them.<br>- Keep the user's watchlist in a memory file called `watchlist.md`: read it when reviewing<br>the watchlist, and update it whenever the user adds or removes a ticker.<br>""";<br>Python

FINANCE_INSTRUCTIONS = """\<br>## Personal Finance Assistant Instructions

You are a personal finance and investing assistant. When asked about a stock, look up its current<br>price with the get_stock_price tool, and use web search for recent news, earnings, or analyst<br>commentary.

### Working style<br>- Always verify numbers with a tool rather than relying on memory. Stock prices change.<br>- Cite web sources inline...

microsoft agent harness azure client tool

Related Articles