AI エージェントのプロンプトを作成する
優れたプロンプトは明確で構造化されており、AI エージェントがタスクを確実かつ一貫して実行するために必要なすべての情報を提供します。エージェントの推論、ツールの選択、出力の書式設定をガイドすることで、人間の意図を機械の動作に変換します。
プロンプトの基本
役割定義の明確化
プロンプトでは、エージェントの役割またはペルソナを明確に定義する必要があります。これにより、エージェントは正しい口調、ドメインの専門知識、推論のスタイルを使用できます。
例:
You are an AI assistant specialized in customer billing and payments.
Without a role, the agent tends to give general, inconsistent answers.
Clear objective or goal
The agent should have a well-defined objective so it can recognize when the task is completed successfully. Define the purpose or expected outcome of the interaction.
Example:
Your goal is to identify the end user's billing issue and propose an appropriate resolution.
これにより、エージェントの推論が導かれ、応答が意図したタスクに沿った状態に保たれます。
コンテキストと入力
エージェントが情報に基づいた意思決定を行うために必要な背景情報をすべて提供します。プレースホルダーを使用して、動的コンテンツをマークします。
形式: {{variable_name}}です。
例:
Context: end_user_message, account_metadata, billing_history.
Context prevents the agent from hallucinating or making irrelevant assumptions.
Step-by-step instructions
Tell the agent how to think and act by breaking down the reasoning or workflow into logical steps.
Example:
Step-by-step prompts improve reasoning accuracy and consistency.
Tool usage policy
If the agent has access to tools, specify when and how those tools should be used. Include restrictions or preconditions.
Example:
Use billing.lookup before issuing any refund. Only call billing.create_refund if confidence > 0.85.
これにより、誤ったアクションや不正なアクションが防止され、予想される動作が保証されます。
トーンと制約
エージェントが通信する方法と、エージェントが尊重しなければならない境界を定義します。これにより、安全性、コンプライアンス、一貫した声のトーンが保証されます。
例:
Use a professional, concise tone. Do not disclose internal tool data. If unsure, ask for clarification.
Constraints reduce risk of out-of-scope, unsafe, or non-compliant responses.
Example outputs
Providing sample outputs helps the agent understand the expected output format. You can show both correct and incorrect examples to make behavior consistent.
Agents learn implicitly from examples, even within a single prompt.
Predictable behavior and fallbacks
Design prompts such that the agent behaves predictably, even in ambiguous situations.
Best practices:
- Include confidence thresholds
- Define what to do when data is missing or unclear
- Describe how to escalate or ask for clarification
Continuous improvement
Good prompts require continuous improvement. Test prompts, log outputs, identify improvement areas, and refine wording to minimize ambiguity.
Output format and schema
Define the exact output structure, ideally as a JSON schema or clearly formatted template. This enables automatic parsing and integration with other systems.
Example:
Add this information in the Agent details > Instructions field or Agent structured output field when configuring the agent.
General guidelines
- Avoid contradictions and repetitiveness.
- Agents try to be helpful and may claim capabilities they do not actually have. Use prompts to explicitly define and limit what the agent can do.
- If the instructions are not clear to you, they will not be clear to the agent.
- Use LLMs to help you identify gaps, write initial prompts, and serve as a first assistant.
Complete example: Finance Tracker agent
The following example shows a complete agent prompt with all best practices applied: