AI エージェントのプロンプトを作成する
優れたプロンプトは明確で構造化されており、AIエージェントがタスクを確実かつ一貫して実行するために必要なすべての情報を提供します。エージェントの推論、ツールの選択、出力の書式設定をガイドすることで、人間の意図を機械の動作に変換します。
プロンプトの基本
適切に構造化されたプロンプトには、次の要素が含まれます。
役割定義の明確化 [#clear-role-definition-prompt-basics]
プロンプトでエージェントのロールまたはペルソナを明確に定義します。これにより、エージェントは正しい口調、ドメインの専門知識、推論のスタイルを使用できます。
役割がなければ、エージェントは一般的で一貫性のない回答をする傾向があります。
例
You are an AI assistant specialized in customer billing and payments.
Clear objective or goal [#clear-objective-or-goal-prompt-basics]
Give the agent a well-defined objective so it can recognize when the task is completed successfully. Define the purpose or expected outcome of the interaction.
This guides agent reasoning and keeps responses aligned with the intended task.
Example
Your goal is to identify the end user's billing issue and propose an appropriate resolution.
コンテキストと入力 [#context-and-inputs-prompt-basics]
エージェントが情報に基づいた意思決定を行うために必要なすべての 背景情報 を提供します。プレースホルダーを使用して、動的コンテンツをマークします。
コンテキストは、エージェントが幻覚を見たり、無関係な仮定をしたりするのを防ぎます。
フォーマット: {{variable_name}}。
例
Context: end_user_message, account_metadata, billing_history.
Step-by-step instructions [#step-by-step-instructions-prompt-basics]
Tell the agent how to think and act by breaking down the reasoning or workflow into logical steps.
Step-by-step prompts improve reasoning accuracy and consistency.
Example
Tool usage policy [#tool-usage-policy-prompt-basics]
If the agent has access to tools, specify when and how to use those tools. Include restrictions or preconditions.
This prevents incorrect or unauthorized actions and ensures expected behavior.
Example
Use billing.lookup before issuing any refund. Only call billing.create_refund if confidence > 0.85.
トーンと制約 [#tone-and-constraints-prompt-basics]
エージェントのコミュニケーション方法と、エージェントが尊重する必要がある境界を定義します。これにより、安全性、コンプライアンス、一貫した声のトーンが保証されます。
制約により、範囲外、安全でない、または非準拠の応答のリスクが軽減されます。
例
Use a professional, concise tone. Do not disclose internal tool data. If unsure, ask for clarification.
Example outputs [#example-outputs-prompt-basics]
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 [#predictable-behavior-and-fallbacks-prompt-basics]
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 [#continuous-improvement-prompt-basics]
Good prompts require continuous improvement. Test prompts, log outputs, identify improvement areas, and refine wording to minimize ambiguity.
Output format and schema [#output-format-and-schema-prompt-basics]
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.
For more information, see Structured output.
For behavioral guidelines that inform your prompts, see Plan behavioral guidelines.
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 are not 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: