そんなプロンプトで大丈夫か?一番いいエージェントを頼む!
そんなプロンプトで大丈夫か?
大丈夫だ、問題ない
(前後のコンテキストで変わってしまったToDo)
Claude使っているとよくあることですね。でも、まだAIを乗り換える定めにはありません。
一番いい装備を使う
Agentsは独自コンテキストで動いているため、Claude本体でよく発生する前後のコンテキストによるプロンプトの変化が発生しません。また、指定されたプロンプトをテンプレートとして保持し、どのような命令に対しても一貫した品質で適用してくれます。
特定の作業を行う際、CLAUDE.mdに記載されたプロンプトの効果をコンテキストに関わらず一貫して維持したい場合は、Agentsを活用すべきです。
agentsの選択
/agents
で確認可能です。最初は標準で備わっているagentを試してみるとよいでしょう。
@code-refactorer path/to/fileのリファクタを頼む
agentの作成
既存agentにない特定のロールをagent化したい場合は、新しく作成します。慣れないうちはClaudeと一緒に作るのがおすすめです。多少拙いプロンプトを書いても、Claudeによって整理された形のプロンプトに仕上がります。
例えば以下の通り。
指定されたToDoにを細分化する手続きをユーザへ提案。
作成と変更の二択を提示し、変更であれば該当する機能に対しての具体的な変更詳細を、作成であれば具体的な内容を、壁打ちにて突き詰める。
具体的な内容が判明したら、単機能→結合→アクセス、の順に、それぞれテスト→テスト実施→ロジック実装→テスト実施→ロジック修正→テスト実施、を完了するまで行う。
解釈のばらつきを抑えるため、プロンプトをGoogle翻訳で英語にしてから入力してみました。
Propose to the user the procedure for breaking down the specified ToDo into smaller pieces.
Present the user with two options: create or modify, and for modify, brainstorm specific changes to the relevant function, or for create, the specific content.
Once the specific content is known, proceed in the order of single function → integration → access, following the steps below: test → test → logic implementation → test → logic modification → test until completed.
Claudeに入力すると以下のように変換されます。
Use this agent when you need to implement features or fix bugs using Test-Driven Development methodology. The agent will guide you through breaking down tasks, choosing between creation and modification approaches, and systematically implementing changes with a test-first approach. Perfect for ensuring code quality and maintaining test coverage while developing new functionality or refactoring existing code.\n\n\nContext: User wants to implement a new feature using TDD methodology\nuser: “I need to add a user authentication feature to the application”\nassistant: “I’ll use the TDD workflow manager to break this down into testable components and guide us through the implementation”\n\nSince the user needs to implement a new feature, use the Task tool to launch the tdd-workflow-manager agent to break down the task and guide through TDD implementation.\n\n\n\n\nContext: User has a ToDo item that needs to be implemented with proper testing\nuser: “ToDo: Implement data validation for the form submission endpoint”\nassistant: “Let me use the TDD workflow manager to break this ToDo down and implement it with proper test coverage”\n\nThe user has a ToDo that needs implementation, so use the tdd-workflow-manager to ensure it’s done following TDD principles.\n\n\n\n\nContext: User wants to refactor existing code with test-first approach\nuser: “I need to refactor the payment processing module to improve performance”\nassistant: “I’ll launch the TDD workflow manager to plan the refactoring with proper test coverage”\n\nRefactoring requires careful planning and testing, so use the tdd-workflow-manager to ensure safe modifications.
文章量が明らかに増えています。Claudeがテストドリブン開発の概念を理解し、TDDを前提としたプロンプトに洗練してくれました。
実際のプロセス
agentは与えられた課題に対して適切なToDoを組み立て、途中で別の問題が発見されても脱線せず、本来のタスクに集中して取り組みます。
ポイントは、別の問題が根本原因だった場合の対処法です。そのような場合は、escキーで一旦作業を中断し、その問題を指摘することで、agentが新たな解決タスクをToDoリストに組み込んでくれます。
あとがき
Claudeを使っていくと、MCPやhooks等の機能によって操作性が向上し快適さを実感できますが、次第にコンテキストによるプロンプトの変質という根本的な問題への対処に頭を悩ませるようになります。
使い込みを重ねてコンテキストによるプロンプト変質に悩むようになったら、agentを導入すべきタイミングです。CLAUDE.mdに「特定作業時に必ず守らせるべき事項」などの記述がすでにある場合は、それらの項目に基づいた独自agentの作成が効果的でしょう。
agentには多くの便利な機能がまだ眠っています。実際に使い込むことで新たな活用法を発見できるでしょう。まずは実際に試してみることから始めましょう。