長時間実行エージェントのための効果的なハーネス
多くのコンテキストウィンドウをまたぐエージェントの課題に対し、人間のエンジニアから着想を得て、より効果的なハーネスの開発を目指す。
キーポイント
Anthropicが長期間実行するAIエージェントの課題(複数コンテキストウィンドウにまたがる作業の一貫性維持)を特定し、2段階アプローチ(初期化エージェント+コーディングエージェント)で解決策を提案
Claude Agent SDKの既存機能(コンテキスト圧縮)だけでは不十分で、エージェントが一度にやりすぎる(ワンショット試行)や途中で進捗を誤認する失敗パターンが明らかに
人間のエンジニアリングチームのシフト勤務に着想を得た「セッション間の明確な成果物引き継ぎ」が、長時間タスクにおけるエージェント実用化の鍵と位置付け
影響分析・編集コメントを表示
影響分析
この記事は、AIエージェントが単発タスクから長時間・複雑なプロジェクトへ進化する上での核心的課題(セッション間の継続性)に具体的な解決アプローチを示しており、実用レベルの自律エージェント開発の進展を加速させる可能性がある。Anthropicの実践的知見は、業界全体のエージェント設計パターンに影響を与える重要な示唆を含んでいる。
編集コメント
エージェントが「人間のシフト勤務」のように作業を引き継ぐ発想は実用的で、AI開発の現場課題を深く理解した上でのソリューション提案として説得力がある。
長期間動作するAIエージェントのための効果的なハーネス開発
AIエージェントが複雑なタスクを担うようになるにつれ、数時間から数日にわたる作業を要するケースが増えている。しかし、エージェントが複数のコンテキストウィンドウ(処理可能な入力範囲)をまたいで一貫した進捗を維持することは、依然として未解決の課題である。
中核的な課題は、エージェントが個別のセッションで作業せざるを得ず、各新規セッションが以前の内容を記憶せずに開始される点にある。 これは、勤務交代するエンジニアが、前のシフトで何が起こったかを全く覚えていない状態でプロジェクトに参加するようなものだ。コンテキストウィンドウには限界があり、ほとんどの複雑なプロジェクトは単一のウィンドウ内では完了できないため、セッション間の隔たりを埋める手段が必要となる。
Anthropicはこの問題に対処するため、Claude Agent SDKを効果的に機能させる二段階のソリューションを開発した。
- 初期化エージェント: 最初の実行時に環境をセットアップする。
- コーディングエージェント: 各セッションで漸進的な進捗を図り、次のセッションのために明確な成果物を残す。
Claude Agent SDKは、ツールを使って情報収集、計画、実行を行うコーディングやその他タスクに適した強力な汎用ハーネスであり、コンテキストウィンドウを枯渇させずに作業を進める「圧縮」機能などのコンテキスト管理能力を備える。理論上、この仕組みによりエージェントは無限に長期にわたって有用な作業を継続できる可能性がある。
しかし、圧縮機能だけでは不十分であることが判明した。例えば「claude.aiのクローンを作成せよ」といった高レベルな指示のみを与えられた場合、最先端のOpus 4.5モデルでさえ、複数のコンテキストウィンドウをループ処理しても、本番品質のWebアプリを構築するには至らなかった。
Claudeの失敗は主に二つのパターンで現れた。
第一に、エージェントは一度に多くのことを成し遂げようとし、事実上アプリを一発で完成させようとした。これにより、実装の途中でコンテキストが不足し、次のセッションでは中途半端で文書化されていない機能から開始せざるを得なくなる。エージェントは過去の状況を推測し、基本的なアプリを再度動作させるために多大な時間を費やすことになった。これは、圧縮機能が次のエージェントに常に完全に明確な指示を引き継ぐわけではないためである。
第二の失敗パターンは、プロジェクトの後半によく発生した。いくつかの機能が既に構築された後、後のエージェントインスタンスが周囲を確認し、進捗があったことを見て「仕事は完了した」と宣言してしまうのである。
これらの観察から、問題は二つの部分に分解できることが明らかになった。第一に、全ての後続作業の基盤を築く初期環境を設定する必要がある。第二に、各セッションが明確な次のステップを残し、確実に漸進的
原文を表示
Engineering at AnthropicEffective harnesses for long-running agents
Agents still face challenges working across many context windows. We looked to human engineers for inspiration in creating a more effective harness for long-running agents.
As AI agents become more capable, developers are increasingly asking them to take on complex tasks requiring work that spans hours, or even days. However, getting agents to make consistent progress across multiple context windows remains an open problem.
The core challenge of long-running agents is that they must work in discrete sessions, and each new session begins with no memory of what came before. Imagine a software project staffed by engineers working in shifts, where each new engineer arrives with no memory of what happened on the previous shift. Because context windows are limited, and because most complex projects cannot be completed within a single window, agents need a way to bridge the gap between coding sessions.
We developed a two-fold solution to enable the Claude Agent SDK to work effectively across many context windows: an initializer agent that sets up the environment on the first run, and a coding agent that is tasked with making incremental progress in every session, while leaving clear artifacts for the next session. You can find code examples in the accompanying quickstart.
The Claude Agent SDK is a powerful, general-purpose agent harness adept at coding, as well as other tasks that require the model to use tools to gather context, plan, and execute. It has context management capabilities such as compaction, which enables an agent to work on a task without exhausting the context window. Theoretically, given this setup, it should be possible for an agent to continue to do useful work for an arbitrarily long time.
However, compaction isn’t sufficient. Out of the box, even a frontier coding model like Opus 4.5 running on the Claude Agent SDK in a loop across multiple context windows will fall short of building a production-quality web app if it’s only given a high-level prompt, such as “build a clone of claude.ai.”
Claude’s failures manifested in two patterns. First, the agent tended to try to do too much at once—essentially to attempt to one-shot the app. Often, this led to the model running out of context in the middle of its implementation, leaving the next session to start with a feature half-implemented and undocumented. The agent would then have to guess at what had happened, and spend substantial time trying to get the basic app working again. This happens even with compaction, which doesn’t always pass perfectly clear instructions to the next agent.
A second failure mode would often occur later in a project. After some features had already been built, a later agent instance would look around, see that progress had been made, and declare the job done.
This decomposes the problem into two parts. First, we need to set up an initial environment that lays the foundation for all the features that a given prompt requires, which sets up the agent to work step-by-step and feature-by-feature. Second, we should prompt each agent to make incremental progress towards its goal while also leaving the environment in a clean state at the end of a session. By “clean state” we mean the kind of code that would be appropriate for merging to a main branch: there are no major bugs, the code is orderly and well-documented, and in general, a developer could easily begin work on a new feature without first having to clean up an unrelated mess.
When experimenting internally, we addressed these problems using a two-part solution:
Initializer agent: The very first agent session uses a specialized prompt that asks the model to set up the initial environment: an init.sh script, a claude-progress.txt file that keeps a log of what agents have done, and an initial git commit that shows what files were added.
Coding agent: Every subsequent session asks the model to make incremental progress, then leave structured updates.1
The key insight here was finding a way for agents to quickly understand the state of work when starting with a fresh context window, which is accomplished with the claude-progress.txt file alongside the git history. Inspiration for these practices came from knowing what effective software engineers do every day.
In the updated Claude 4 prompting guide, we shared some best practices for multi-context window workflows, including a harness structure that uses “a different prompt for the very first context window.” This “different prompt” requests that the initializer agent set up the environment with all the necessary context that future coding agents will need to work effectively. Here, we provide a deeper dive on some of the key components of such an environment.
To address the problem of the agent one-shotting an app or prematurely considering the project complete, we prompted the initializer agent to write a comprehensive file of feature requir
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み