AI エージェントループの3つの実行方式とプロバイダー経済を解説するオープンソースコース
本文の状態
日本語全文を表示中
詳細モードで約8分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
MarkTechPost
LangChain の実験結果が示す通り、AI エージェントの品質はモデル選択よりも実行ループの実装に依存し、Decode はこの知見に基づきインタラクティブ・オフライン・非同期の 3 つのモードを定義した。
AI深層分析を開く2026年8月22日 23:00
AI深層分析
キーポイント
ハーンエンジニアリングの重要性
LangChain の Terminal-Bench 実験により、同一モデルでも実行環境(ハーン)の変更でコーディングエージェントの順位が大幅に変化することが示された。
3 つの実行モードの定義
Paul Iusztin が公開した「Decode」は、インタラクティブ・オンライン、リモート・オフライン、非同期・オンラインの 3 つの形状(モード)を明確に区別している。
各モードの最適化戦略
インタラクティブモードは低遅延 API を要し、リモートモードはスループットとコスト効率を重視する一方、非同期モードは両者の中間的な特性を持つ。
ステアリングとリカバリの仕組み
インタラクティブモードでは入力バッファリングと優先ゲートにより操作の破損を防ぎ、リモートモードではステップごとの記録により中断からの再開を可能にしている。
インタラクティブと非同期の経済モデルの違い
インタラクティブな作業は人間の待ち時間を伴うためトークン課金となり、オフライン・非同期作業はスループットが目的であるためGPU時間課金が有利になる。
重要な引用
In LangChain's Terminal-Bench experiment, changing only the harness—same model throughout—moved a coding agent from roughly 30th place into the top 5.
If the harness decides quality, then how you run the loop becomes an architecture decision, not a deployment detail.
The metric that matters is throughput per dollar, not time-to-first-token.
Interactive work pays per token because a human is waiting. Offline and async work pays per GPU-hour because throughput is the objective and idle time is the enemy.
編集コメントを表示
編集コメント
エージェント開発の文脈において、ハードウェアやモデルの性能だけでなく、ソフトウェアの実行環境設計が成否を分けるという視点は極めて示唆に富む。各ユースケースに応じたモード選択とインフラ選定が、実運用におけるコストと品質のバランスを決定する鍵となるだろう。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
多くのチームは「どのモデルを選ぶか」を最重要の判断事項と捉えています。しかし、ハーン(実行基盤)に関するエンジニアリング文献が指し示すのは別の方向です。LangChain の Terminal-Bench 実験では、モデルは同一のままハーンのみを変更した結果、コーディングエージェントの順位が約 30 位からトップ 5 へと劇的に向上しました。
この結果は問いを再定義します。もし品質を決めるのがハーンなら、ループの実行方法はデプロイの詳細ではなく、アーキテクチャ上の決断となります。Paul Iusztin が Decoding AI を通じて公開したオープンソースコース『Building a Coding Agent From Scratch』では、Python で構築されたエージェント Decode が紹介されています。このコースは 3 つの異なる実行モードを明確に区別しており、それぞれが独自のレイテンシ特性を持っています。つまり、各モードには最適な推論プロバイダーが異なります。
1 つのコアに 3 つの形状
システムの中心となるのは、独自インターフェースを持たないヘッドレスなハーンです。この内部で、すべてのハーンが共有するエージェントループが稼働しています。LLM がアクションを選択し、ツールが実行され、その観測結果がフィードバックされます。すべての処理はコンテキストウィンドウの読み書きを通じて行われます。
エージェント自体は非常に小型です。Decode では、モデル・ツール・出力型を組み合わせる Pydantic AI の定義が約 20 行で構成されています。一方、Claude Code のリークされたソースコードでは、コアループは約 150 行程度です。それ以外の機能——メモリ管理、スキルセット、サンドボックス、権限制御、LSP フィードバック、コンパクションなど——はすべてハーンが担います。
インターフェースはこのコアに接続されます。ここで 3 つのモードが現れます:
モード 1: インタラクティブ、オンライン
ターミナル UI は、同じプロセス内のメモリ上にある 1 つのライブセッションに接続されています。トークンが到着するたびに、イベントは非同期ジェネレーターを通じてストリーミングされます。
ここで難しいのはステアリング(操作)です。ツール呼び出しが実行されている間にタイプしてメッセージを即座に注入すると、そのターンが破損します。Decode の解決策は、ステアリングキューと優先度ゲートです。入力は到着時にバッファされ、安全な境界でのみ注入されます。このループでは 2 つの境界が公開されています。1 つ目は MODEL_REQUEST で、次のモデル呼び出しの前です。2 つ目は WOULD_STOP で、ターンが終了する直前です。
これら 3 つの入力モードがこの仕組みにマッピングされます。通常の Enter キーは現在のターン内で操作します。Alt+Enter は、ターンが停止するまでフォローアップをキューイングします。Esc キーは、次の境界で協調的な中止トリガーとなり、両方のキューをクリアして履歴を保持したままにします。
人間がすべてのトークンを読み取っているこのモードは、レイテンシに依存します。そのため、低遅延のホスト API で実行する必要があります。
モード 2:リモート・オフライン
リモートモードでは、ハーンレス(ヘッドレス)でサーバー上でエージェントランタイムを通じて実行されます。Decode では、Kitaru を使用しています。これは ZenML のエージェントランタイムで、GCP にデプロイされており、エージェント自体は Modal で実行されています。
誰も監視していません。チケットのバックログが N 個のハーンに並列に展開され、それぞれが独自の PR を生成します。ランタイムがステップごとに進捗を記録するため、タスク途中で沙箱が停止した場合でも、最初から再起動するのではなく、最後に記録されたステップから再開されます。人間の入力を待って一時停止した実行は、待機中は計算リソースを消費しません。
ツールは、リモート環境では Modal のサンドボックス内で、ローカル環境では Docker 内で実行されます。重要なのは「初回トークンまでの時間」ではなく、「1 ドルあたりの処理スループット」です。
モード 3:非同期・オンライン型
この第 3 の形状は、前述の 2 つの中間に位置します。ライブセッションで作業をジョブキューへ引き渡し、即座に応答を返す仕組みです。バックグラウンドでワークフローが展開され、LLM(大規模言語モデル)への呼び出しを並列実行し、結果は後ほど投稿されます。
ユーザーはオンライン状態ですが、各ステップを常に見守っているわけではありません。キューが作業を管理するため、処理はクライアント側が切断された後も継続します。このパターンは、Slack のトリガーで動作するエージェントや、バックグラウンドで行われる PR(プルリクエスト)レビューに採用されており、課金体系もチャット型ではなくバッチ処理型と同じです。
インタラクティブな解説:なぜモードによってプロバイダーが変わるのか
コストモデルはレイテンシ要件に依存しており、その差は甚大です。
例えば、1,000 件のドキュメントを処理する場合を考えましょう。各ドキュメントの入力トークン数は約 30,000、出力トークンは平均 500 です。最先端 API のレート(入力 100 万トークンあたり 3 ドル、出力 100 万トークンあたり 15 ドル)で計算すると、総コストは約 97 ドルに達します。プロンプトキャッシングはこのケースでは効果を発揮しません。なぜなら、各ドキュメントのプレフィックス(前段部分)が異なるためです。
一方、サーバーレス GPU でバッチ処理する場合、スループットは秒間約 3,000 トークンと仮定すると、同じ作業にかかる GPU 時間は 3 時間未満。コストは約 13 ドルに抑えられます。
逆のケースも同様に深刻です。Decode のデフォルトテストモデルである Qwen3.6 35B は、単一の H200 グラフィックボード上で動作します。Modal が公表する価格によると、H200 SXM の料金は秒間 0.001261 ドル(時間あたり約 4.54 ドル)です。インタラクティブなエージェントを夜間にアイドル状態(待機中)にしておき、ユーザーからの確認(y confirmation)を待つ場合、10 時間の待機で請求額が約 45 ドル増加します。
これが主張の核心です。対話型の作業は、人間が待機しているためトークン数に応じて課金されます。一方、オフラインや非同期の作業ではスループットが目的であり、アイドル時間が敵となるため、GPU 使用時間(GPU-hour)に対して課金されます。
もう一つの軸として、「サーバーレス」と「予約済み容量」の違いがあります。Modal の価格分析はこれを単純な比較に落とし込んでいます。予約型は契約期間中ずっとピーク時の単価で請求されるのに対し、サーバーレスは需要曲線に沿って変動します。ピークと平均の比率が予約割引を上回る場合、サーバーレスの方が安くなります。Modal のレポートによると、推論、トレーニング、エージェント開発における典型的なピーク対平均比は 5〜10 倍である一方、予約割引は通常 2〜5 倍です。同社が引用する業界調査では、予約リソースの利用率は 30% を下回り、場合によっては 10% に満たないことも示されています。
重要なポイント
- ハルネスの重要性: モデルそのものよりもハルネス(制御枠組み)が重要で、ハルネスを差し替えただけで、Terminal-Bench の評価順位が約 30 位からトップ 5 に躍進しました。
- 対話型モード: レイテンシに制約されるため、MODEL_REQUEST や WOULD_STOP の境界点でキューが排水されるように制御されます。
- リモート・非同期モード: スループットに制約されるため、大量処理ではトークン課金よりも GPU 時間課金が有利になります。
- 1,000 ドキュメントの処理コストは、最先端 API のレートでは約$97 ですが、バッチ処理された GPU 時間では約$13 です。
- ピーク対平均の需要が予約割引を上回る場合(通常 5〜10 倍に対し 2〜5 倍)、サーバーレスが勝利します。
参考資料
- Building a Coding Agent From Scratch (Lesson 1)
- The Bare-Bones Coding Agent Loop (Lesson 2)
- From a Raw Shell to a Sandboxed Coding Agent (Lesson 3)
- Course repository · Modal pricing
- How to price serverless GPUs
- LangChain: The anatomy of an agent harness
AI のオープンソースコースが解明する、エージェントループを実行する 3 つの方法と、それぞれの背後にあるプロバイダー経済の仕組み
原文を表示
Most teams treat ‘which model’ as the important decision. The harness engineering literature keeps pointing somewhere else. In LangChain’s Terminal-Bench experiment, changing only the harness—same model throughout—moved a coding agent from roughly 30th place into the top 5.
That result reframes the question. If the harness decides quality, then how you run the loop becomes an architecture decision, not a deployment detail. Paul Iusztin’s open-source course Building a Coding Agent From Scratch builds a Python agent called Decode. Published through Decoding AI, it separates three run modes. Each mode has a different latency profile. Each one therefore wants a different inference provider.
One headless core, three shapes
The center of the system is a headless harness with no interface of its own. Inside it runs the agent loop every harness shares: the LLM picks an action, a tool executes, the observation feeds back. Everything reads from and writes to the context window.
The agent itself is small. In Decode it is a ~20-line Pydantic AI definition composing a model, tools, and an output type. In Claude Code’s leaked source, the core loop is roughly 150 lines. Everything else—memory, skills, sandbox, permissions, LSP feedback, compaction—is harness.
Interfaces then plug into that core. That is where the three modes appear:
Mode 1: Interactive, online
A terminal UI is wired to one live session, in memory, in the same process. Events stream back through async generators as tokens arrive.
The hard problem here is steering. If you type while a tool call is in flight, injecting the message immediately corrupts the turn. Decode’s answer is a steering queue plus a priority gate. Input is buffered on arrival and injected only at a safe boundary. The loop exposes two: MODEL_REQUEST, before the next model call, and WOULD_STOP, when the turn would end.
Three input modes map onto that. Plain Enter steers within the turn. Alt+Enter queues a follow-up until the turn stops. Esc triggers a cooperative abort at the next boundary, clearing both queues so history stays intact.
A human is reading every token. This mode is latency-bound, which is why it belongs on a low-latency hosted API.
Mode 2: Remote, offline
Remote mode keeps the harness headless and runs it on a server through an agent runtime. Decode uses Kitaru, ZenML’s agent runtime, deployed to GCP, with the agents themselves executing on Modal.
Nobody is watching. A backlog of tickets fans out to N harnesses in parallel, each producing its own PR. Because the runtime records progress step by step, a sandbox that dies mid-task resumes from its last recorded step instead of restarting. A run that pauses for human input freezes and consumes no compute while it waits.
Tools execute inside Modal Sandboxes remotely, Docker locally. The metric that matters is throughput per dollar, not time-to-first-token.
Mode 3: Async, online
The third shape sits between the two. A live session hands work to a job queue and returns immediately. Background workflows fan out LLM calls and post results back later.
The user is online but not watching each step. The queue owns the work, so the run outlives the client that started it. This is the pattern behind Slack-triggered agents and background PR review, and it bills like batch, not like chat.
The interactive explainer
Why the provider changes with the mode
The cost model follows the latency requirement, and the gap is large.
Take 1,000 documents at 30,000 input tokens each, roughly 500 output tokens per document. At frontier API rates of $3 per million input and $15 per million output, the lesson's arithmetic lands near $97. Prompt caching does not rescue it, because every document is a different prefix. Batched on a serverless GPU at around 3,000 tokens per second, the same work is under three hours of GPU time—roughly $13.
The reverse case is just as sharp. Decode's default test model, Qwen3.6 35B, runs on a single H200. Modal's published pricing lists H200 SXM at $0.001261 per second, or about $4.54 per hour. Leave an interactive agent idle overnight waiting on a y confirmation, and ten idle hours add roughly $45 to the bill.
That is the whole argument. Interactive work pays per token because a human is waiting. Offline and async work pays per GPU-hour because throughput is the objective and idle time is the enemy.
There is a second axis: serverless versus reserved capacity. Modal's pricing analysis reduces it to one comparison. Reservations charge the peak rate for the whole contract; serverless follows the demand curve. When the peak-to-average ratio exceeds the reservation discount, serverless is cheaper. Modal reports typical discounts of 2–5× against peak-to-average ratios of 5–10× for inference, training, and agentic development. Industry surveys it cites put reservation utilization below 30%, often under 10%.
Key Takeaways
Harness beats model: swapping only the harness moved an agent from ~30th to top 5 on Terminal-Bench.
Interactive mode is latency-bound and steers via a queue draining at MODEL_REQUEST and WOULD_STOP boundaries.
Remote and async modes are throughput-bound, so GPU-hour billing beats per-token billing at volume.
1,000 documents cost ~$97 on frontier API rates versus ~$13 of batched GPU time.
Serverless wins whenever peak-to-average demand exceeds the reservation discount, typically 5–10× against 2–5×.
Sources:
Building a Coding Agent From Scratch (Lesson 1)
The Bare-Bones Coding Agent Loop (Lesson 2)
From a Raw Shell to a Sandboxed Coding Agent (Lesson 3)
Course repository · Modal pricing
How to price serverless GPUs
LangChain: The anatomy of an agent harness
The post Decoding AI’s Open-Source Course Maps Three Ways to Run an Agent Loop and the Provider Economics Behind Each appeared first on MarkTechPost.
関連記事
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み