エージェント型手動テスト
Simon Willisonは、LLMが生成したコードの信頼性を確保するため、単なる自動テストだけでなくエージェントに「手動テスト」を実行させるAgentic Engineeringのパターンを提案している。
キーポイント
コード実行と検証の重要性
コーディングエージェントの本質的な価値は、生成したコードを実行し、その動作を検証・反復できる点にある。LLMが出力したコードは実行前に信用してはいけないという原則を強調する。
自動テストの限界と手動テストの必要性
自動テストがパスしても、サーバークラッシュやUI表示不全など意図しない動作が発生する可能性があるため、人間の目での確認(手動テスト)は不可欠である。
エージェントによる手動テストの実践手法
Pythonライブラリには`python -c`、Web APIには`curl`を用いてエージェントに直接コードやAPIを探索・実行させるプロンプトパターンを示している。
/tmpディレクトリの活用
エージェントに一時ファイル(/tmpなど)への書き出しとコンパイル・実行を促すことで、リポジトリへの誤コミットを防ぎつつ迅速な検証を行う手法を紹介する。
影響分析・編集コメントを表示
影響分析
この記事は、LLMを活用した開発プロセスにおいて「コード生成」から「実行と検証」へのパラダイムシフトを促す重要な示唆を含んでいる。特に、エージェントに具体的なコマンドラインツールを通じて環境と対話させる手法は、実務レベルでのAI活用における信頼性向上に直結する。これは単なるコード生成を超え、自律的なデバッグ・検証プロセスを構築するための実践的なガイドラインとして、開発現場に広く影響を与える可能性がある。
編集コメント
Simon WillisonはAgentic Engineeringの第一人者であり、その実践的な知見は現場で即座に適用可能な価値が高い。自動テストの限界を認め、エージェントによる「擬似手動テスト」を導入する発想は、AI開発の成熟度を示す指標と言える。
*Agentic Engineering Patterns >*
コーディングエージェントの定義的な特徴は、自身が作成したコードを*実行できる*点です。これが、単に検証手段もなしにコードを吐き出すだけの LLM(大規模言語モデル)よりも、コーディングエージェントがはるかに有用である理由となります。
LLM によって生成されたコードが動作するかどうかは、そのコードを実行するまで決して仮定してはいけません。
コーディングエージェントには、自身が作成したコードが意図通りに機能していることを確認したり、機能するようになるまでさらに反復して改良したりする能力があります。
エージェントに ユニットテストの作成 を行わせることは、特にテストファースト型 TDD(テスト駆動開発)を活用することで、作成中のコードが適切に実行されていることを保証する強力な手段です。
しかし、それが唯一の有益なアプローチというわけではありません。
コードがテストを通過したからといって、意図通りに動作しているとは限りません。自動化されたテストに取り組んだ経験のある人なら誰でも、すべてのテストは合格しているにもかかわらず、コード自体には明らかな欠陥があるケースを目にしてきたはずです——起動時にサーバーをクラッシュさせたり、重要な UI 要素の表示に失敗したり、テストがカバーしきれなかった細部を見落としたりするといった問題です。
自動化されたテストは手動テストの代わりにはなりません。私はリリースに組み込む前に、自分の目で機能が動作していることを確認するのが好きです。
エージェントにコードの手動テストを行わせることもまた価値があり、自動化されたテストでは見逃されていた問題を頻繁に発見することができます。
エージェントによる手動テストのためのメカニズム
あるエージェントがコードを「手動」でテストする方法は、そのコードの内容によって異なります。
Python ライブラリの場合、有用なパターンとして python -c "... code ..." というものがあります。これは、他のモジュールをインポートするコードを含む Python コードの文字列(または複数行文字列)を、直接 Python インタープリタに渡すことができます。
コーディングエージェントはこのトリックにすべて慣れ親しんでおり、指示がなくても時折これを使用します。ただし、python -c を使用してテストするよう促すと、しばしば効果的です:
python -c を使って、その新しい関数のいくつかのエッジケースを試してみてください。
他の言語にも同様のメカニズムがあるかもしれませんが、ない場合でも、エージェントがデモファイルを作成し、その後コンパイルして実行するのは迅速な作業です。私は時折、後で誤ってリポジトリにコミットされるのを防ぐために、/tmp を使用することを推奨しています。
その関数のエッジケースを試すために /tmp でコードを書き、その後コンパイルして実行してください。
私のプロジェクトの多くは、JSON API を備えた Web アプリケーションを構築するものです。これらについては、エージェントに curl を使用してテストさせるよう指示しています:
開発サーバーを実行し、curl を使ってその新しい JSON API を探索してください。
エージェントに「探索」するように指示すると、多くの場合、新しい API のさまざまな側面を試すことになり、これにより広範囲を素早くカバーできます。
もしエージェントが手動テストを通じて動作しないものを見つけたら、私は彼らに赤/緑の TDD(テスト駆動開発 (Test-Driven Development))で修正するよう指示します。これにより、新しいケースが恒久的な自動テストによって確実にカバードされるようになります。
Web UI に対するブラウザ自動化の使用
プロジェクトにインタラクティブな Web UI が含まれている場合、手動テスト手順を確立しておくことはさらに価値が高まります。
歴史的にはコードからこれらの UI をテストすることは困難でしたが、過去 10 年間で実際の Web ブラウザを自動化するシステムにおいて目覚ましい進歩が見られました。アプリケーションに対して実際の Chrome や Firefox、Safari ブラウザを実行することで、現実的な環境においてあらゆる種類の興味深い問題を発見することができます。
コーディングエージェントはこれらのツールの使い方を非常によく知っています。
現在最も強力なものは Playwright です。これは Microsoft によって開発されたオープンソースライブラリです。Playwright は多様な人気プログラミング言語でのバインディングを備えたフル機能の API を提供し、あらゆる主要なブラウザエンジンを自動化できます。
エージェントに対して「Playwright でテストして」と指示するだけで十分な場合があります。エージェントは最も適切な言語バインディングを選択するか、Playwright のデフォルト CLI ツールを使用します。
コーディングエージェントは専用 CLI と非常に相性が良いです。Vercel による agent-browser は、コーディングエージェントが使用するために特別に設計された Playwright を包む包括的な CLI ラッパーです。
私のプロジェクト Rodney も同様の目的を果たしますが、こちらは Chrome DevTools Protocol(Chrome 開発者ツールプロトコル)を使用して Chrome のインスタンスを直接制御します。
Rodney を使用してものをテストするために私が使用する例のプロンプトは以下の通りです:
開発サーバーを起動し、その後 uvx rodney --help を使用して新しいホームページをテストし、スクリーンショットを確認してメニューが正しい場所にあるか確認してください
このプロンプトには3つのコツがあります:
- 「use uvx rodney --help」と言うことで、エージェントは uvx パッケージ管理ツールを介して
rodney --helpを実行します。これにより、Rodney は初回呼び出し時に自動的にインストールされます。 rodney --helpコマンドは、エージェントがツールの理解と使用に必要なすべての情報を得られるように特別に設計されています。こちらがそのヘルプテキストです that help text。- 「look at screenshots」と言うことで、エージェントに対して rodney のスクリーンショットコマンドを使用するよう示唆し、生成された画像ファイルに対して自身のビジョン機能を活用してページの視覚的な外観を評価できることを思い出させます。
これは、短いプロンプトに組み込まれた相当量のマニュアルテストです!
Rodney や同様のツールは、読み込まれたサイトでの JavaScript 実行からスクロール、クリック、入力、さらにはページのアクセシビリティツリー(accessibility tree)の読み取りに至るまで、幅広い機能を提供します。
他の形式の手動テストと同様に、ブラウザ自動化によって発見され修正された問題は、恒久的な自動テストにも追加できます。
過去に多くの開発者が、ブラウザの自動テストが「フラッキィ(flakiness:不安定さ)」で知られているという評判から、過度な自動テストを避けてきました。ページの HTML に対する最小限の変更でも、テストの連鎖的な失敗という厄介な事態を引き起こす可能性があるからです。
コーディングエージェントにこれらのテストを長期的に維持させることで、Web インターフェースの設計変更に対しても、それらを最新の状態に保つ際に伴う摩擦を大幅に軽減できます。
Showboat でノートを取らせる
エージェントに手動でコードを検証させることで追加の問題を発見できるほか、コードのドキュメント作成やテスト実施方法のデモンストレーションに役立つ成果物を作成するためにも利用可能です。
エージェントが「作業過程を見せる」ことへの挑戦に私は魅了されています。デモや文書化された実験を確認できることは、与えられた課題をエージェントが網羅的に解決したことを確認する非常に有用な手段です。
私は、アジェンティックな手動テストのフローを捉えたドキュメントを構築しやすくするために Showboat を開発しました。
私が頻繁に使用するプロンプトは以下の通りです:
uvx showboat --help を実行し、その後 notes/api-demo.md という名前の Showboat ドキュメントを作成して、新しい API のテストとドキュメント作成に使用してください。
前述の Rodney と同様に、showboat --help コマンドはエージェントに対して Showboat が何であるか、およびその使用方法を教えます。以下が そのヘルプテキスト全文 です。
Showboat の 3 つのコマンドは note, exec, image です。
note は Markdown 形式のノートを Showboat ドキュメントに追加します。exec はコマンドを記録し、その後そのコマンドを実行してその出力を記録します。image はドキュメントに画像を追加するもので、Rodney を使用して取得した Web アプリケーションのスクリーンショットなどに役立ちます。
exec コマンドはこれらの中で最も重要であり、実行されたコマンドとその結果の出力を記録するものです。これにより、エージェントが何を行い、どのような結果を得たかが明確になり、エージェントが「起こったと希望した内容」を文書に書き込むという不正行為を防ぐように設計されています。
私は、Showboat パターンが、エージェントセッション中に達成された作業を文書化するのに非常に効果的であることを発見しています。このパターンがより広範なツール群でも採用されるようになることを期待しています。
Tags: playwright, testing, agentic-engineering, ai, llms, coding-agents, ai-assisted-programming, rodney, showboat
原文を表示
*Agentic Engineering Patterns >*
The defining characteristic of a coding agent is that it can *execute the code* that it writes. This is what makes coding agents so much more useful than LLMs that simply spit out code without any way to verify it.
Never assume that code generated by an LLM works until that code has been executed.
Coding agents have the ability to confirm that the code they have produced works as intended, or iterate further on that code until it does.
Getting agents to write unit tests, especially using test-first TDD, is a powerful way to ensure they have exercised the code they are writing.
That's not the only worthwhile approach, though.
Just because code passes tests doesn't mean it works as intended. Anyone who's worked with automated tests will have seen cases where the tests all pass but the code itself fails in some obvious way - it might crash the server on startup, fail to display a crucial UI element, or miss some detail that the tests failed to cover.
Automated tests are no replacement for manual testing. I like to see a feature working with my own eye before I land it in a release.
I've found that getting agents to manually test code is valuable as well, frequently revealing issues that weren't spotted by the automated tests.
Mechanisms for agentic manual testing
How an agent should "manually" test a piece of code varies depending on what that code is.
For Python libraries a useful pattern is python -c "... code ...". You can pass a string (or multiline string) of Python code directly to the Python interpreter, including code that imports other modules.
The coding agents are all familiar with this trick and will sometimes use it without prompting. Reminding them to test using python -c can often be effective though:
Try that new function on some edge cases using python -c
Other languages may have similar mechanisms, and if they don't it's still quick for an agent to write out a demo file and then compile and run it. I sometimes encourage it to use /tmp purely to avoid those files being accidentally committed to the repository later on.
Write code in /tmp to try edge cases of that function and then compile and run it
Many of my projects involve building web applications with JSON APIs. For these I tell the agent to exercise them using curl:
Run a dev server and explore that new JSON API using curl
Telling an agent to "explore" often results in it trying out a bunch of different aspects of a new API, which can quickly cover a whole lot of ground.
If an agent finds something that doesn't work through their manual testing, I like to tell them to fix it with red/green TDD. This ensures the new case ends up covered by the permanent automated tests.
Using browser automation for web UIs
Having a manual testing procedure in place becomes even more valuable if a project involves an interactive web UI.
Historically these have been difficult to test from code, but the past decade has seen notable improvements in systems for automating real web browsers. Running a real Chrome or Firefox or Safari browser against an application can uncover all sorts of interesting problems in a realistic setting.
Coding agents know how to use these tools extremely well.
The most powerful of these today is Playwright, an open source library developed by Microsoft. Playwright offers a full-featured API with bindings in multiple popular programming languages and can automate any of the popular browser engines.
Simply telling your agent to "test that with Playwright" may be enough. The agent can then select the language binding that makes the most sense, or use Playwright's default CLI tool.
Coding agents work really well with dedicated CLIs. agent-browser by Vercel is a comprehensive CLI wrapper around Playwright specially designed for coding agents to use.
My own project Rodney serves a similar purpose, albeit using the Chrome DevTools Protocol to directly control an instance of Chrome.
Here's an example prompt I use to test things with Rodney:
Start a dev server and then use uvx rodney --help to test the new homepage, look at screenshots to confirm the menu is in the right place
There are three tricks in this prompt:
- Saying "use
uvx rodney --help" causes the agent to runrodney --helpvia the uvx package management tool, which automatically installs Rodney the first time it is called. - The
rodney --helpcommand is specifically designed to give agents everything they need to know to both understand and use the tool. Here's that help text. - Saying "look at screenshots" hints to the agent that it should use the
rodney screenshotcommand and remind it that it can use its own vision abilities against the resulting image files to evaluate the visual appearance of the page.
That's a whole lot of manual testing baked into a short prompt!
Rodney and tools like it offer a wide array of capabilities, from running JavaScript on the loaded site to scrolling, clicking, typing, and even reading the accessibility tree of the page.
As with other forms of manual tests, issues found and fixed via browser automation can then be added to permanent automated tests as well.
Many developers have avoided too many automated browser tests in the past due to their reputation for flakiness - the smallest tweak to the HTML of a page can result in frustrating waves of test breaks.
Having coding agents maintain those tests over time greatly reduces the friction involved in keeping them up-to-date in the face of design changes to the web interfaces.
Have them take notes with Showboat
Having agents manually test code can catch extra problems, but it can also be used to create artifacts that can help document the code and demonstrate how it has been tested.
I'm fascinated by the challenge of having agents *show their work*. Being able to see demos or documented experiments is a really useful way of confirming that the agent has comprehensively solved the challenge it was given.
I built Showboat to facilitate building documents that capture the agentic manual testing flow.
Here's a prompt I frequently use:
Run uvx showboat --help and then create a notes/api-demo.md showboat document and use it to test and document that new API.
As with Rodney above, the showboat --help command teaches the agent what Showboat is and how to use it. Here's that help text in full.
The three key Showboat commands are note, exec, and image.
note appends a Markdown note to the Showboat document. exec records a command, then runs that command and records its output. image adds an image to the document - useful for screenshots of web applications taken using Rodney.
The exec command is the most important of these, because it captures a command along with the resulting output. This shows you what the agent did and what the result was, and is designed to discourage the agent from cheating and writing what it *hoped* had happened into the document.
I've been finding the Showboat pattern to work really well for documenting the work that has been achieved during my agent sessions. I'm hoping to see similar patterns adopted across a wider set of tools.
Tags: playwright, testing, agentic-engineering, ai, llms, coding-agents, ai-assisted-programming, rodney, showboat
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み