Microsoft Agent Framework、エージェントの能力拡張「Agent Harness」を公開
本文の状態
日本語全文を表示中
詳細モードで約16分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Microsoft Agent Framework
Microsoft は Agent Framework の新バージョンで、スキル・シェル・コード実行・背景エージェントの 4 つの軸を強化し、エージェントの拡張性と自律性を高める仕組みを発表した。
AI深層分析を開く2026年8月4日 17:29
AI深層分析
キーポイント
スキルによるオンデマンド学習の実装
システムプロンプトへの情報埋め込みではなく、SKILL.md ファイルとして知識をパッケージ化し、必要な時にのみ読み込む機構を導入した。
シェルツールとコード実行の統合
ファイルの整理や再構成を行うシェルツールの利用に加え、Agent が自らコードを書き実行して計算結果を得る CodeAct 機能を追加した。
並列処理による背景エージェントの活用
複数のサブエージェントを同時に稼働させて作業を行い、その結果を集約する「Background agents」機能を実装した。
Foundry スキルの中央管理と動的更新
ファイルベースのスキルとは異なり、Foundry スキルはプロジェクト内で中央に公開・更新され、エージェントはランタイムで取得する。これにより、評価手法の変更やガバナンスルールの強化を再デプロイせずに全エージェントへ即時反映できる。
MCP エンドポイントによる統合と最適化
.NET と Python の両方で MCP エンドポイントを接続し、ローカルファイルソースと Foundry スキルソースを統一的なプロバイダーに結合する。この構成により、エージェントはスキルの出所(ディスクかクラウドか)を意識することなく単一のセットとして扱う。
重要な引用
Stuffing every instruction the assistant might ever need into its system prompt doesn't scale – it bloats the context and dilutes its focus.
Skills solve this: each skill is a small SKILL.md file with a name, a one-line description, and instructions
The harness provides the machinery.
The valuation method can evolve without anyone touching the claw.
編集コメントを表示
編集コメント
エージェントの能力をプロンプトに詰め込む従来のアプローチから、モジュール化されたスキルへ移行する設計思想は実用性が高い。開発者が独自のカスタマイズを容易に行える仕組みが整ったことで、特定の業務領域に特化した自律型エージェントの実装が加速すると予想される。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
Microsoft Agent Framework を用いた「爪(Claw)」と「ハーネス」の構築シリーズ、第 3 部です。
前回の第 2 部では、パーソナルファイナンスアシスタントがデータを安全に扱う方法を学びました。ポートフォリオを読み込み、取引を行う前に確認し、セッションを超えて重要な情報を記憶する能力を持っています。有用な機能ですが、その知識はすべて一つのプロンプトに埋め込まれており、処理も一度に一つずつしか行えません。ファイルアクセスツールを越えて実際にファイルを再編成するようなことはできません。
今回の第 3 部では、「爪」の機能を以下の 4 つの軸で強化します。
- スキル:評価やリスクスコアリングなどのノウハウを、エージェントがオンデマンドで読み込む検索性のあるファイル(SKILL.md)としてパッケージ化します。これには、中央管理された Foundry スキルも含まれます。
- Shell:ファイルを整理・再構築するためのシェルツールを提供します。
- CodeAct:エージェントにコードの記述と実行を許可し、単なる参照では得られない計算結果を導き出させます。
- バックグラウンドエージェント:複数のサブエージェントに並列で処理を分散させ、その結果を集約する仕組みです。
前回の構成と同様に、エージェント固有の機能は私たちが提供し、基盤となる機械的な部分はハーネスが担います。それでは順に見ていきましょう。
オンデマンドで学習させる:スキル
アシスタントが必要とするすべての指示をシステムプロンプトに詰め込むことは、スケーラブルではありません。コンテキストが肥大化し、焦点がぼやけてしまうからです。そこで登場するのが「スキル」です。各スキルは、名前、1 行の説明、そして指示(必要に応じて参照ドキュメントやスクリプトも)を含む小さな SKILL.md ファイルとして定義されます。エージェントは最初に見た目には名前のリストと説明だけを表示し、リクエストが特定のスキルに一致したときにのみ、そのスキルの完全な内容を段階的に読み込みます。
Agent Harness では、skills/ フォルダ内に 2 つのファイルベースのスキルを追加できます。これらのスキルは、エージェントに対してリスク評価やバリュエーション(価値算定)の実行方法を指示するものです。
スキルの詳細については、Microsoft Agent Framework の「Give Your Agents Domain Expertise with Agent Skills」および「What's New in Agent Skills: Code Skills, Script Execution, and Approval for Python」をご覧ください。
使用法
Harness はデフォルトでスキルプロバイダーを有効化します(作業ディレクトリから SKILL.md ファイルを検出)。ここでは、サンプルの skills/ フォルダを指してスキルのスクリプトを実行できるよう、独自のプロバイダーを作成します。
.NET では、AgentSkillsProviderBuilder を用いてプロバイダーを組み立て、デフォルトのプロバイダーを無効化します:
var skillsProvider = new AgentSkillsProviderBuilder()
// File-based skills; SubprocessScriptRunner runs their Python scripts.
.UseFileSkills([skillsDir], scriptRunner: SubprocessScriptRunner.RunAsync)
.Build();
AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions
{
DisableAgentSkillsProvider = true, // we supply our own
AIContextProviders = [skillsProvider],
// … file access, tools …
});Python では、同じフォルダから SkillsProvider を構築して渡します。
from agent_framework import SkillsProvider
skills_provider = SkillsProvider.from_paths(
skill_paths=[str(skills_dir)],
script_runner=subprocess_script_runner, # lets the skills' scripts run
)
agent = create_harness_agent(
client=client,
skills_provider=skills_provider,
# … file access, tools …
)
「Value MSFT for me」と指示すると、エージェントはバリューエーション(企業価値評価)のスキルを読み込み、そのガイドを確認してスクリプトを実行し、適正価格の見積もりを報告します。同様に、「How risky is my portfolio?」と尋ねると、リスクスコアリングの機能が呼び出されます。システムプロンプトにはバリューエーションやリスクに関する記述は含まれていません。
中央管理型のスキル:Foundry スキル
ファイルベースのスキルはエージェントに同梱されており、1 つでも変更すれば再デプロイが必要です。一方、Foundry スキルはその仕組みを逆転させます。スキルは Foundry プロジェクト内で中央から公開・更新され、エージェントが実行時にそれを取得します。これにより、バリューエーション手法を変更しても、爪(claw)の部分を触る必要はありません。
Foundry エンドポイントが必要となるため、この機能はオプトイン方式となっています。サンプルコードはローカルのスキルのみでも正常に動作します。
Foundry スキルの公開方法や管理については、Foundry スキルドキュメントをご参照ください。
.NET では、Foundry Toolbox MCP エンドポイントから Foundry スキルがリアルタイムで検出されます。同じビルダーに MCP ソースを追加するだけです。
Toolbox エンドポイントが設定されている場合のみオプトインで有効化されます。
if (!string.IsNullOrWhiteSpace(toolboxUrl))
{
var (mcpClient, _) = await FoundrySkills.ConnectAsync(toolboxUrl, credential);
skillsBuilder.UseMcpSkills(mcpClient); // fold them into the same provider
}Python でも同様です。Foundry Toolbox の MCP エンドポイントに接続し、ローカルの FileSkillsSource と並行して MCPSkillsSource を追加します。
from agent_framework import (
AggregatingSkillsSource, DeduplicatingSkillsSource,
FileSkillsSource, MCPSkillsSource, SkillsProvider,
)
sources = [FileSkillsSource(str(skills_dir), script_runner=subprocess_script_runner)]
# Opt-in: only when a Toolbox endpoint is configured.
if toolbox_url:
session = await _connect_foundry_toolbox(stack, toolbox_url)
sources.append(MCPSkillsSource(client=session))
source = sources[0] if len(sources) == 1 else AggregatingSkillsSource(sources)
skills_provider = SkillsProvider(DeduplicatingSkillsSource(source))どちらのケースでも、エージェントは統合された単一のスキルセットを認識します。ディスクから読み込まれたものか、Foundry で管理されているものかを区別することなく、また気にすることもありません。
スキルはドメイン固有のハウツーだけでなく、エージェントがどのように振る舞うべきかという一般的なルールを担うこともできます。Foundry スキルは中央で更新されるため、このようなガバナンスルールを管理する場所としてまさに最適です。ポリシーを一度厳格化すれば、すべての稼働中の Claw が即座に反映され、再デプロイの必要はありません。
試すには、financial-agent-rules という名前のスキルを Foundry ツールボックスに登録してください:
name: financial-agent-rules
description: General rules about how you should behave as a financial agent. Use this skill for all requests.
金融関連の質問やポートフォリオ管理、確認処理に関するもの以外への回答は、丁寧に拒否する必要があります。
記述に「すべてのリクエストでこのスキルを使用する」とあるため、エージェントは各ターンごとにこれをロードします。一度公開し、Foundry スキルを有効化(FOUNDRY_TOOLBOX_MCP_SERVER_URL を設定)すれば、Claw に「フランスの首都はどこか?」といった本題から外れた質問を投げかけると、丁寧に断りながら金融関連へと誘導してくれます。
ファイルシステムへのアクセス:shell
ファイルアクセス機能を使えば、Claw は個別のファイルを読み書きできますが、散らかったフォルダの整理整頓——移動、リネーム、バッチ処理など——はまさに shell の得意とするところです。ユーザーの取引確認書類は、名前の統一性がないまま平面的に積み重なった状態になっています:
working/confirmations/
trade confirmation 1.txt
conf_AAPL.txt
copy of trade 3.txt
SPY sell.txt
…
ハルネス機能では、シェルを「承認ゲート付きの run_shell ツール」として公開できます。エージェントにシェルコマンドを実行させるのは強力ですが危険も伴うため、私たちは2つの方法で制限を設けています。1つ目は作業ディレクトリを限定することです。すべてのコマンドは確認用 vault 内に再アングルされ、そこから脱出できません。2つ目は拒否リストポリシーの適用です。明らかに破壊的なコマンドを事前にフィルタリングします。
.NET では、LocalShellExecutor を設定し、それを ShellExecutor として渡します。
await using var shell = new LocalShellExecutor(new LocalShellExecutorOptions
{
WorkingDirectory = vaultDir,
ConfineWorkingDirectory = true, // can't escape the vault
Policy = new ShellPolicy(denyList:
[
@"\brm\s+-rf\b", @"\bsudo\b", @":\(\)\s*\{", @"\bmkfs\b", @">\s*/dev/sd",
]),
Timeout = TimeSpan.FromSeconds(15),
});
AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions
{
ShellExecutor = shell, // exposed as the approval-gated run_shell tool
// … skills, file access, tools …
});Python では、LocalShellTool が同じ役割を果たします。
agent_framework_tools.shell モジュールから LocalShellTool と ShellPolicy をインポートします。
shell = LocalShellTool(
workdir=str(vault_dir),
confine_workdir=True, # can't escape the vault
policy=ShellPolicy(denylist=[
r"\brm\s+-rf\b", r"\bsudo\b", r":()\s*{", r"\bmkfs\b", r">\s*/dev/sd",
]),
timeout=15,
)
agent = create_harness_agent(
client=client,
shell_executor=shell, # exposed as the approval-gated run_shell tool
# … skills, file access, tools …
)ここで定義されたポリシーは、ユーザー体験(UX)上の安全装置であり、セキュリティの境界線ではありません。拒否リスト(deny-list)は明らかなミスを防ぐことができますが、悪意のある攻撃や巧妙に書き換えられたコマンドを完全に阻止できるわけではありません。真の隔離を実現するのは、制限された作業ディレクトリと、実行前にユーザーの承認を求めるプロンプトです。さらに信頼できない入力に対しては、DockerShellExecutor(.NET 用)や DockerShellTool(Python 用)のようなサンドボックス化されたエグゼキューターを使用する必要があります。
例えば、「取引確認書を整理して」という指示に対し、エージェントはまずフォルダ内のファイルを調査し、実行計画を提案します。その後、ユーザーが各コマンドの承認を行うことで、ファイルは年/月の階層構造に移動され、ファイル名は YYYY-MM-DD_TICKER_BUY|SELL.txt という形式でリネームされます。
計算も任せる:CodeAct
検索が必要な質問だけでなく、計算を要する問いもあります。「ポートフォリオの評価額は?」や「このポジションの収益率は?」といった問いには、モデルが頭の中で算数を行うよりも、コードを実行させる方が適切です。CodeAct は、エージェントが安全な環境でコードを書き、実行できるインタプリタを提供します。
CodeAct はサンドボックス内でモデルが生成したコードを実行し、両言語のコンテキストプロバイダーとして連携します。
.NET では CodeAct に Hyperlight(マイクロ VM であり、ハードウェア仮想化が必要です)を使用します。ゲストモジュールのパスは、Hyperlight.HyperlightSandbox.Guest.Python NuGet パッケージから自動的に解決されます:
using HyperlightSandbox.Guest.Python;
using Microsoft.Agents.AI.Hyperlight;
var codeAct = new HyperlightCodeActProvider(
HyperlightCodeActProviderOptions.CreateForWasm(PythonGuestModule.GetModulePath()));
AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions
{
AIContextProviders = [skillsProvider, codeAct],
// … shell, file access, tools …
});
Python では、Monty は純粋なクロスプラットフォームのインタープリターであり、ハイパーバイザーを必要としません。これをコンテキストプロバイダーとして追加します:
from agent_framework_monty import MontyCodeActProvider
context_providers = [skills_provider, MontyCodeActProvider(approval_mode="never_require")]
agent = create_harness_agent(
client=client,
context_providers=context_providers,
# … shell, file access, tools …
)
CodeAct を有効にすると、「ポートフォリオの総額を計算して」という指示に対して、エージェントが保有銘柄を読み取り、数行の Python コードで株式数と単価を掛け合わせて合計し、実行結果を報告します。推測ではなく、計算過程を示すことができます。
CodeAct の活用アイデアについては、『Agent Framework における CodeAct:モデルのターン数を減らして高速化』をご覧ください。
同時に多くの処理を実行する:バックグラウンドエージェント
ティッカーを一つずつ「Research MSFT, NVDA and SPY」と検索するのでは遅く、またすべてのウェブ検索をメインエージェントに統合するとコンテキストが混乱してしまいます。そこで本ハレスはバックグラウンドエージェントをサポートしています。これはクローブ(爪)に任せるサブエージェントで、並行して実行される作業単位を委任し、結果を報告させることができます。
私たちは軽量なウェブ検索専用リサーチエージェントを構築しました。これはウェブ検索ツールのみを持つシンプルなチャットクライアント型のエージェントであり、ハレスの複雑な機構は必要ありません。
// ResearchAgent.Create(...)
AIAgent research = chatClient.AsAIAgent(
name: "TickerResearchAgent",
description: "Searches the web for recent news about a single stock ticker.",
instructions: "You research a single ticker and return 3-4 factual bullet points.",
tools: [new HostedWebSearchTool()]); // the only tool it needs
次に、これをメインのクローブに BackgroundAgents を通じて渡します。
AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions
{
BackgroundAgents = [research], // exposes the background_agents_* tools
// … skills, shell, file access, tools …
});
Python では、これは background_agents 引数として実装されます。
research_agent = Agent(
client,
name="TickerResearchAgent",
description="Searches the web for recent news about a single stock ticker.",
instructions="You research a single ticker and return 3-4 factual bullet points.",
tools=[client.get_web_search_tool()], # the only tool it needs
)
agent = create_harness_agent(
client=client,
background_agents=[research_agent], # exposes the background_agents_* tools
# … skills, shell, file access, tools …
)
この構成により、メインのエージェントは background_agents_* ツール群を利用可能になります。各ティッカーごとに調査タスクを開始し、並列実行させ、進行状況を確認して結果を収集、最後にそれらをまとめて要約することが可能です。フォークアウト(分散)の判断はエージェントが行い、ハッチス側がインフラ(配管)を担当します。
実行方法
.NET
cd dotnet
dotnet run --project samples/02-agents/Harness/BuildYourOwnClaw/Claw_Step03_ScalingCapabilities
Python
uv run python/samples/02-agents/harness/build_your_own_claw/claw_step03_scaling_capabilities.py
以下のコマンドを順番に試してみてください(サンプルは実行モードで開始されるため、簡単な照会には計画立案は不要です)。
- "Value MSFT for me." – エージェントがバリューエーションスキルを読み込み、スクリプトを実行して適正価値の見積もりを報告します。
- "How risky is my portfolio?" – portfolio.csv ファイルを読み込んでリスク評価スキルをロードします。
まずプランを立てて、取引確認を整理しましょう。プランモードに切り替えることで、エージェントがまず working/confirmations/ディレクトリを検査し、ファイルに触れる前に再編成の提案を行います。承認いただければ実行モードへ移行し、シェルを使ってファイルを移動・名前変更します。各コマンドの実行には再度ご確認を求めます。
ポートフォリオの総額を計算しましょう。Python スクリプトを作成して実行し、答えを導き出します。
MSFT、NVDA、SPY について調査し、最新ニュースを要約してください。エージェントはこれらのティッカーシンボルを背景のリサーチエージェントに分散させ、得られた知見を集約します。
フランスの首都はどこですか?金融エージェントルール「Foundry スキル」が公開され有効化されている場合(下記参照)、このスキルを読み込みます。質問が対象外と判断すると、丁寧に断り、金融関連の話題へ誘導します。
オプトイン型の Foundry スキルを有効にするには、FOUNDRY_TOOLBOX_MCP_SERVER_URL 環境変数を設定してください。
実行可能なサンプル
.NET: dotnet/samples/02-agents/Harness/BuildYourOwnClaw/Claw_Step03_ScalingCapabilities
Python: python/samples/02-agents/harness/build_your_own_claw
これらのビルディングブロックを、あなた自身のアージェントで活用できます。
ご存知の通り、これらはハッチャー内部に閉じ込められているわけではありません。各機能は、単なるコンテキストプロバイダーまたは実行ツール(エグゼキューター/ツール)として提供されており、個別に利用可能です。詳細は以下の通りです:
- Feature:.NET (型 — ネームスペース) / Python (import)
- Skills:AgentSkillsProvider / AgentSkillsProviderBuilder — Microsoft.Agents.AI (MCP skills via Microsoft.Agents.AI.Mcp) / from agent_framework import SkillsProvider, MCPSkillsSource
Shell
LocalShellExecutor / ShellPolicy — Microsoft.Agents.AI.Tools.Shell
from agent_framework_tools.shell import LocalShellTool, ShellPolicy
CodeAct
HyperlightCodeActProvider — Microsoft.Agents.AI.Hyperlight
from agent_framework_monty import MontyCodeActProvider
Background agents
BackgroundAgentsProvider — Microsoft.Agents.AI
from agent_framework import BackgroundAgentsProvider
.NET では、スキルと背景エージェントは Microsoft.Agents.AI パッケージに同梱され、シェルは Microsoft.Agents.AI.Tools.Shell に、Hyperlight CodeAct は Microsoft.Agents.AI.Hyperlight に含まれます。Python の場合、スキルと背景エージェントは agent-framework から、シェルは agent-framework-tools から、Monty CodeAct は agent-framework-monty から提供されます。プロバイダーはエージェントのコンテキストプロバイダーを通じて接続され(シェルはエグゼキューターとして)、ハッチがユーザーに代わって行う配線と同じ仕組みです。
今後の展望
現在のクローは、新しいスキルの習得やファイル構造の再構築、自身で計算した回答の生成、並列処理が可能になりました。最終章では、トレースとログによる観測性、ガバナンスとデータ保護、評価機能、そしてホストされた Foundry エージェントとしてのデプロイを行い、本番環境での運用を可能にします。
image シリーズについて
Microsoft Agent Framework を用いたクローの自作シリーズの一部です:
概要:Microsoft Agent Framework で独自のクローとエージェントハッチを構築する
パート 1 – エージェントハッチとクローとの出会い
パート 2 – データを安全に扱う
第3部:ハッチング機能の拡張(現在位置)
第4部:本番環境対応(近日公開)
この記事「Agent Harness: Scaling the claw or harness capabilities」は、Microsoft Agent Framework で最初に掲載されました。
原文を表示
Part 3 of Build your own claw and harness with Microsoft Agent Framework.
In Part 2 our personal finance assistant learned to work with your data safely: it reads your portfolio, asks before it trades, and remembers what matters across sessions. It’s useful – but everything it knows is baked into one prompt, it does its work one step at a time, and it can’t reach past the file-access tools to actually reorganize anything.
This part makes the claw more capable along four axes:
Skills – package know-how (valuation, risk-scoring) as discoverable files the agent loads on demand, including centrally-managed Foundry skills.
Shell – shell tools, to tidy and restructure files.
CodeAct – let the agent write and run code to compute answers it can’t just look up.
Background agents – fan work out to sub-agents that run concurrently, then aggregate.
As before, we only supply what makes our agent ours; the harness provides the machinery. Let’s take them in turn.
Teach it on demand: skills
Stuffing every instruction the assistant might ever need into its system prompt doesn’t scale – it bloats the context and dilutes its focus. Skills solve this: each skill is a small SKILL.md file with a name, a one-line description, and instructions (plus optional reference docs and scripts). The agent sees only the names and descriptions up front, and progressively loads a skill’s full content only when a request matches it.
Our claw gets two file-based skills under the skills/ folder. The skills instruct the agent in how to do risk scoring and valuations.
For more information on skills see Give Your Agents Domain Expertise with Agent Skills in Microsoft Agent Framework and What’s New in Agent Skills: Code Skills, Script Execution, and Approval for Python
Usage
The harness turns a skills provider on by default (it discovers SKILL.md files from the working directory). Here we build our own provider so we can point it at this sample’s skills/ folder and run the skills’ scripts.
In .NET, compose a provider with AgentSkillsProviderBuilder and turn the default one off:
var skillsProvider = new AgentSkillsProviderBuilder()
// File-based skills; SubprocessScriptRunner runs their Python scripts.
.UseFileSkills([skillsDir], scriptRunner: SubprocessScriptRunner.RunAsync)
.Build();
AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions
{
DisableAgentSkillsProvider = true, // we supply our own
AIContextProviders = [skillsProvider],
// … file access, tools …
});
In Python, build a SkillsProvider from the same folder and pass it in:
from agent_framework import SkillsProvider
skills_provider = SkillsProvider.from_paths(
skill_paths=[str(skills_dir)],
script_runner=subprocess_script_runner, # lets the skills' scripts run
)
agent = create_harness_agent(
client=client,
skills_provider=skills_provider,
# … file access, tools …
)
Now “Value MSFT for me” makes the agent load the valuation skill, read its guide, run its script, and report a fair-value estimate – and “How risky is my portfolio?” pulls in risk-scoring instead. Nothing about valuation or risk was in the system prompt.
Skills you manage centrally: Foundry skills
File-based skills ship with the agent – to change one, you redeploy. Foundry skills flip that around: skills are published and updated centrally in your Foundry project, and the agent picks them up at runtime. The valuation method can evolve without anyone touching the claw.
Because it needs a Foundry endpoint, we make it opt-in – the sample runs fine on the local skills alone.
For how to publish and manage Foundry skills, see the Foundry skills docs.
In .NET, Foundry skills are discovered live from a Foundry Toolbox MCP endpoint; just add an MCP source to the same builder:
// Opt-in: only when a Toolbox endpoint is configured.
if (!string.IsNullOrWhiteSpace(toolboxUrl))
{
var (mcpClient, _) = await FoundrySkills.ConnectAsync(toolboxUrl, credential);
skillsBuilder.UseMcpSkills(mcpClient); // fold them into the same provider
}
In Python, it’s the same story: connect to the Foundry Toolbox MCP endpoint and add an MCPSkillsSource alongside the local FileSkillsSource:
from agent_framework import (
AggregatingSkillsSource, DeduplicatingSkillsSource,
FileSkillsSource, MCPSkillsSource, SkillsProvider,
)
sources = [FileSkillsSource(str(skills_dir), script_runner=subprocess_script_runner)]
Opt-in: only when a Toolbox endpoint is configured.
if toolbox_url:
session = await _connect_foundry_toolbox(stack, toolbox_url)
sources.append(MCPSkillsSource(client=session))
source = sources[0] if len(sources) == 1 else AggregatingSkillsSource(sources)
skills_provider = SkillsProvider(DeduplicatingSkillsSource(source))
Either way the agent sees one unified set of skills; it neither knows nor cares which ones came from disk and which were managed in Foundry.
Skills aren’t only for domain how-tos – a skill can just as easily carry general rules about how the agent should behave. Because Foundry skills update centrally, governance rules like this are exactly the kind of thing you’d manage there: tighten the policy once and every running claw picks it up, no redeploy. To try it, publish a skill named financial-agent-rules to your Foundry toolbox:
name: financial-agent-rules
description: General rules about how you should behave as a financial agent. Use this skill for all requests.
You should politely refuse to answer any questions unrelated to finance, managing portfolios or managing confirmations.
Because its description says “Use this skill for all requests”, the agent loads it on every turn. Once it’s published and Foundry skills are enabled (set FOUNDRY_TOOLBOX_MCP_SERVER_URL), ask the claw something off-topic like “What’s the capital of France?” and it will politely decline and steer you back to finance.
Reach into the file system: shell
File access lets the claw read and write individual files, but reorganizing a messy folder – moving, renaming, batching – is exactly what a shell is for. The user’s trade confirmations pile up as a flat heap of inconsistently-named files:
working/confirmations/
trade confirmation 1.txt
conf_AAPL.txt
copy of trade 3.txt
SPY sell.txt
…
The harness can expose a shell as an (approval-gated) run_shell tool. Letting an agent run shell commands is powerful and dangerous, so we hem it in two ways: a confined working directory (every command is re-anchored to the confirmations vault and can’t escape it) and a deny-list policy that pre-filters obviously destructive commands.
In .NET, configure a LocalShellExecutor and pass it as the ShellExecutor:
await using var shell = new LocalShellExecutor(new LocalShellExecutorOptions
{
WorkingDirectory = vaultDir,
ConfineWorkingDirectory = true, // can't escape the vault
Policy = new ShellPolicy(denyList:
[
@"\brm\s+-rf\b", @"\bsudo\b", @":\(\)\s*\{", @"\bmkfs\b", @">\s*/dev/sd",
]),
Timeout = TimeSpan.FromSeconds(15),
});
AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions
{
ShellExecutor = shell, // exposed as the approval-gated run_shell tool
// … skills, file access, tools …
});
In Python, a LocalShellTool plays the same role:
from agent_framework_tools.shell import LocalShellTool, ShellPolicy
shell = LocalShellTool(
workdir=str(vault_dir),
confine_workdir=True, # can't escape the vault
policy=ShellPolicy(denylist=[
r"\brm\s+-rf\b", r"\bsudo\b", r":\(\)\s*\{", r"\bmkfs\b", r">\s*/dev/sd",
]),
timeout=15,
)
agent = create_harness_agent(
client=client,
shell_executor=shell, # exposed as the approval-gated run_shell tool
# … skills, file access, tools …
)
The policy is a UX guardrail, not a security boundary. A deny-list catches obvious mistakes, but it won’t stop a determined or cleverly-worded command. Real isolation comes from the confined working directory and the approval prompt – and for untrusted input, a sandboxed executor like DockerShellExecutor (.NET) or DockerShellTool (Python).
Now “Tidy up my trade confirmations” lets the agent inspect the folder, propose a plan, and (with your approval on each command) move the files into a year/month layout renamed to YYYY-MM-DD_TICKER_BUY|SELL.txt.
Let it compute: CodeAct
Some questions aren’t a lookup – they’re a calculation. “What’s my portfolio worth?” or “what was my return on this position?” are better answered by running a little code than by asking the model to do arithmetic in its head. CodeAct gives the agent a sandboxed interpreter it can write and run code in.
CodeAct runs model-authored code in a sandbox, and we wire it in as a context provider in both languages.
In .NET, CodeAct uses Hyperlight (a micro-VM, so it needs hardware virtualization). The guest module path is resolved automatically from the Hyperlight.HyperlightSandbox.Guest.Python NuGet package:
using HyperlightSandbox.Guest.Python;
using Microsoft.Agents.AI.Hyperlight;
var codeAct = new HyperlightCodeActProvider(
HyperlightCodeActProviderOptions.CreateForWasm(PythonGuestModule.GetModulePath()));
AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions
{
AIContextProviders = [skillsProvider, codeAct],
// … shell, file access, tools …
});
In Python, Monty is a pure, cross-platform interpreter – no hypervisor required – added as a context provider:
from agent_framework_monty import MontyCodeActProvider
context_providers = [skills_provider, MontyCodeActProvider(approval_mode="never_require")]
agent = create_harness_agent(
client=client,
context_providers=context_providers,
# … shell, file access, tools …
)
With CodeAct on, “Work out the total value of my portfolio” lets the agent read the holdings, write a few lines of Python to multiply shares by price and sum them, run it, and report the result – arithmetic it can show its working for, rather than guess.
For more ideas on how to use CodeAct, read CodeAct in Agent Framework: Faster Agents with Fewer Model Turns
Do many things at once: background agents
Asking “Research MSFT, NVDA and SPY” one ticker at a time is slow, and folding all that web searching into the main agent muddies its context. The harness supports background agents: sub-agents you hand to the claw so it can delegate units of work that run concurrently and report back.
We build a lean, web-search-only research agent – a plain chat-client agent with just the web search tool (no harness machinery needed):
// ResearchAgent.Create(...)
AIAgent research = chatClient.AsAIAgent(
name: "TickerResearchAgent",
description: "Searches the web for recent news about a single stock ticker.",
instructions: "You research a single ticker and return 3-4 factual bullet points.",
tools: [new HostedWebSearchTool()]); // the only tool it needs
Then we hand it to the main claw via BackgroundAgents:
AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions
{
BackgroundAgents = [research], // exposes the background_agents_* tools
// … skills, shell, file access, tools …
});
In Python it’s the background_agents argument:
research_agent = Agent(
client,
name="TickerResearchAgent",
description="Searches the web for recent news about a single stock ticker.",
instructions="You research a single ticker and return 3-4 factual bullet points.",
tools=[client.get_web_search_tool()], # the only tool it needs
)
agent = create_harness_agent(
client=client,
background_agents=[research_agent], # exposes the background_agents_* tools
# … skills, shell, file access, tools …
)
This gives the main agent a set of background_agents_* tools: it can start a research task per ticker, let them run in parallel, check on them, and collect the results – then summarize all three together. The fan-out is the agent’s decision; the harness handles the plumbing.
Run it
.NET
cd dotnet
dotnet run --project samples/02-agents/Harness/BuildYourOwnClaw/Claw_Step03_ScalingCapabilities
Python
uv run python/samples/02-agents/harness/build_your_own_claw/claw_step03_scaling_capabilities.py
Then try these in order (the sample starts in execute mode – quick lookups don’t need a plan):
Value MSFT for me. – the agent loads the valuation skill, runs its script, and reports a
fair-value estimate.
How risky is my portfolio? – it reads portfolio.csv and loads the risk-scoring skill.
/mode plan, then Tidy up my trade confirmations. – switching to plan mode first makes the agent inspect working/confirmations/ and propose a reorganization plan before touching anything; once you approve it switches to execute and uses the shell to move and rename the files, prompting you to approve each command.
Work out the total value of my portfolio. – it writes and runs Python to compute the answer.
Research MSFT, NVDA and SPY and summarize the latest news. – it fans the tickers out to the background research agent and aggregates the findings.
What's the capital of France? – with the financial-agent-rules Foundry skill published and enabled (see below), the agent loads it, recognizes the question is off-topic, and politely declines, steering you back to finance.
To enable the opt-in Foundry skills: set FOUNDRY_TOOLBOX_MCP_SERVER_URL.
The runnable samples
.NET: dotnet/samples/02-agents/Harness/BuildYourOwnClaw/Claw_Step03_ScalingCapabilities
Python: python/samples/02-agents/harness/build_your_own_claw
Use these building blocks in your own agent
As always, none of this is locked inside the harness. Each capability is a plain context provider or an executor/tool you can pick up on its own. Here’s where to find them:
Feature
.NET (type — namespace)
Python (import)
Skills
AgentSkillsProvider / AgentSkillsProviderBuilder — Microsoft.Agents.AI (MCP skills via Microsoft.Agents.AI.Mcp)
from agent_framework import SkillsProvider, MCPSkillsSource
Shell
LocalShellExecutor / ShellPolicy — Microsoft.Agents.AI.Tools.Shell
from agent_framework_tools.shell import LocalShellTool, ShellPolicy
CodeAct
HyperlightCodeActProvider — Microsoft.Agents.AI.Hyperlight
from agent_framework_monty import MontyCodeActProvider
Background agents
BackgroundAgentsProvider — Microsoft.Agents.AI
from agent_framework import BackgroundAgentsProvider
In .NET, skills and background agents ship in the Microsoft.Agents.AI package, the shell in Microsoft.Agents.AI.Tools.Shell, and Hyperlight CodeAct in Microsoft.Agents.AI.Hyperlight. In Python, skills and background agents come from agent-framework, the shell from agent-framework-tools, and Monty CodeAct from agent-framework-monty. The providers plug in through an agent’s context providers (and the shell as an executor) – the same wiring the harness does on your behalf.
What’s next
Our claw can now teach itself new skills, restructure files, compute answers it writes itself, and work in parallel. In the final part we make it production-ready: observability with traces and logs, governance and data protection, evaluation, and deployment as a hosted Foundry agent.
image The series
Part of Build your own claw with Microsoft Agent Framework:
Overview: Build your own claw and agent harness with Microsoft Agent Framework
Part 1 – Meet your agent harness and claw
Part 2 – Working with your data, safely
Part 3 – Scaling the harness capabilities (you are here)
Part 4 – Production-ready (coming soon)
The post Agent Harness: Scaling the claw or harness capabilities appeared first on Microsoft Agent Framework.
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み