AI Agentでタスク駆動開発をしている話
各種AI Agentがいろいろありますが、どのAgentを使うにしても下記のようなルールファイルを作っています。
# Principles of Conduct
The rules below are mandatory—every agent must follow them without exception.
### Repository Context
This is k-kinzal/testcontainers-php, a PHP implementation of the Testcontainers framework. It enables container management for testing purposes with minimal dependencies and supports PHP versions 5.6-8.3 (including EOL versions).
### Task Lifecycle
Whenever the user issues an instruction, you must follow the workflow below without skipping, merging, or re-ordering any step.
1. **Create a task file**
* Avoid duplicates: Before creating a file, double-check that no existing task covers the same objective.
* Location: `.task/`
* Naming convention: `YYYY-MM-DD-NNN.md`
* `YYYY-MM-DD` = current date
* `NNN` = three-digit serial number for that day, starting at `001`
* Example: `.task/2025-06-01-001.md`
2. **Populate the file with this template**
# <Concise Task Title>
Date: YYYY-MM-DD
Status: Open | In-Progress | Closed
## Request
A one-sentence summary of what is being asked.
## Objective
A clear statement of what “done” looks like.
## Action Plan
<!-- The Action Plan can be left empty when you first create the task;
add checklist items here as you define the steps. -->
- [ ]
## Execution Log
### YYYY-MM-DD HH:MM:SS
Notes, commands run, findings, links, etc.
3. **Before starting any step**
1. Run the system command `date` and copy the timestamp (24-hour, ISO 8601 format).
2. **Requirement check — MANDATORY:**
* Confirm that all assumptions and expectations for *this specific step* are clear.
* If anything is unclear, record the question in **Execution Log** and resolve it before moving on.
* Log the timestamped confirmation (or clarification) right after it is made.
4. **Execute exactly one step** from the *Action Plan*.
* **One step = one execution.** Do **not** batch multiple checklist items in a single run.
5. **Update the task file**
* Add a new entry under **Execution Log** headed by the timestamp you just recorded.
* Describe what you did and what you discovered.
* If the step is finished, tick its checkbox in the *Action Plan*.
* **If you discover that any requirement or assumption has changed or was wrong:**
1. Update *Objective* and/or *Action Plan* immediately.
2. Document the change in **Execution Log** with a timestamp **before starting the next step**.
6. **Repeat Steps 3–5** until every step in the *Action Plan* is complete.
7. **Completion and review**
* When all steps are finished, request confirmation from the requester.
* After they approve, set **Status** to `Closed`.
---
### Extra Rule
If you uncover additional work outside the current task’s scope (e.g., a bug or a follow-up improvement), spin up a brand-new task file using the same procedure above.
Task Lifecycle自体はファイルでやるんじゃなくて専用のMCPとUI作るべきだと思っているのですが、そこまでやれてないので妥協の産物なところがあります。
基本的な思想
基本骨子としてはこの手のルールにあまりごちゃごちゃ書きたくないというのがあります。
現状ではコンテキストは貴重なものであり、本当に必要最小限の情報を提示する形にしないとノイズになり逆にタスクの実行精度を下げると思っています。
また、タスク自体は多種多様なタスクを指示するので、あまり特定タスク用の情報をルールに含めたくないです。
もし、そういった情報があるならナレッジとして保持して必要に応じてこれを読めとした方がタスク精度が高くできそうです。
狙っている効果
1. 長い愚直な作業をやりきる
AIさんに洗い出しタスクを依頼すると大体中途半端なところで投げ出します。
これはコンテキストから外れるとか、コンテキストの谷に入って関心から外れるとかだと思っています。
そういったさいに次のステップを実行してねと愚直にやってもらうためにプランを永続的に保持できるようにしています。
2. コンテキストを破棄しても継続できる
AIさんのコンテキストが変な感じになったり、継続できない状態(Copilot Agent Modeだとコンテキストが溢れてエラーになるとか)になったとき、別のAI Agentに切り替えたいときなどでコンテキストを残せるようにしています。
タスクを続きからやったり、注意事項があればログを参照できるようにですね。
つまり申し送りとして必要な情報を永続化することで、再実行の容易性を残せるようにしています。
3. 記録の改竄
ここの記録を改竄することで、意図しない方向に進んださいに起動修正しやすいです。
特に計画の変更や、意図しないログの削除、知識付与のための捏造した記録の追加などなど、タスク精度の向上のために仕込み安いのは気に入っています。
4. 将来への布石
こういった情報を貯めることで、AI Agent動作に必要な何かを作るための布石にできるのでは?という思想のもと記録を行なっています。
どう使うかとかイメージできてないので何かの役にたてばいいなぐらいの温度感です。
実際にやってみて
絶妙なところだなぁという感じです。
ログに時間を残させているのですが、コマンド実行をしないと取れないので若干冗長です。
またファイル名がちょっと失敗していてNNNで番号指定してますが、これのせいでたまに001を上書きしてきます。
これは秒まで含めたファイル名にした方が良さそうです。
このあたりはMCP化したりすれば解消できると思うので時間見つけて作らなきゃ。
理想像の話
個人的にAI Agentに全部丸投げ〜というよりは、適時コミュニケーションを取りながら成果物の品質向上を目指していきたいです。
そう考えると基本は突っ走ってもらっていいのですが、要所要所では確認させてほしいというのでタスクやチケットみたいなので対話したい感じがあります。(もちろん内容を詰めるときはチャットとかで同期にやる方がいいけど)
さらに言えば、特定の作業がうまくできない場合にそれをサブタスクとして切り出して、別のAIに担当させるとかできるとマルチエージェントみたいな感じで得意なものは得意な人にやらせるみたいなことができていいですよね。
そのサブタスクもAIに限らず人に依頼するみたいなのでも良いと思います。
と、考えるとリアルタイムな通知を持ったタスク管理ツールで、人間はUIで、AIはMCPでやりとりしたり、そこ駆動で動けるようになるといいのかなぁみたいな妄想してます。
というので今のやり方は完全に妥協の産物ですね。たぶん似たようなのは誰か作ってそうだけど、微妙に欲しいものと違いそうなのでどこかのタイミングで作りたい。
Discussion