Logo
Logo
CTRLK

共有コンポーネント

AI エージェントのプロンプトを作成する


優れたプロンプトは明確で構造化されており、AIエージェントがタスクを確実かつ一貫して実行するために必要なすべての情報を提供します。エージェントの推論、ツールの選択、出力の書式設定をガイドすることで、人間の意図を機械の動作に変換します。


プロンプトの基本

適切に構造化されたプロンプトには、次の要素が含まれます。

役割定義の明確化 [#clear-role-definition-prompt-basics]

プロンプトでエージェントのロールまたはペルソナを明確に定義します。これにより、エージェントは正しい口調、ドメインの専門知識、推論のスタイルを使用できます。

役割がなければ、エージェントは一般的で一貫性のない回答をする傾向があります。

You are an AI assistant specialized in customer billing and payments.

明確な目的または目標 [#clear-objective-or-goal-prompt-basics]

エージェントに明確に定義された目標を与えて、タスクが正常に完了したことを認識できるようにします。インタラクションの目的または期待される結果を定義します。

これにより、エージェントの推論がガイドされ、応答が意図したタスクに沿った状態に保たれます。

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-prompt-basics]

推論やワークフローを論理的なステップに分解することで、エージェントに考え方や行動方法を伝えます。

ステップバイステップのプロンプトにより、推論の精度と一貫性が向上します。

json
11. Understand the end user message.
22. Identify potential issue category.
33. Decide if tool usage is needed.
44. Generate the structured response.

ツール使用ポリシー [#tool-usage-policy-prompt-basics]

エージェントがツールにアクセスできる場合は、それらのツールをいつ、どのように使用するかを指定します。制限または前提条件を含めます。

これにより、誤ったアクションや不正なアクションが防止され、予想される動作が保証されます。

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-prompt-basics]

サンプル出力を提供すると、エージェントが予想される出力形式を理解するのに役立ちます。正しい例と間違った例の両方を表示して、動作に一貫性を持たせることができます。

エージェントは、単一のプロンプト内であっても、例から暗黙的に学習します。

予測可能な動作とフォールバック [#predictable-behavior-and-fallbacks-prompt-basics]

あいまいな状況でもエージェントが予測可能に動作するようにプロンプトを設計します。

ベストプラクティス

  • 信頼度のしきい値を含めます。
  • データが欠落しているか不明瞭な場合の対処方法を定義します。
  • エスカレーションの方法や説明を求める方法を説明する。

継続的改善 [#continuous-improvement-prompt-basics]

優れたプロンプトには継続的な改善が必要です。プロンプトをテストし、出力をログに記録し、改善点を特定し、曖昧さを最小限に抑えるために文言を改良します。

出力形式とスキーマ [#output-format-and-schema-prompt-basics]

正確な出力構造を、理想的には JSON スキーマまたは明確にフォーマットされたテンプレートとして定義します。これにより、自動解析と他のシステムとの統合が可能になります。

json
1{
2 "issue_type": "string",
3 "recommended_action": "string",
4 "confidence": "number"
5}

エージェントの設定のときに、[エージェントの詳細** > 手順 フィールドまたは エージェント構造化出力 フィールドにこの情報を追加します。

詳細については、「構造化出力](/ai-agents/advanced-topics/structured-output)を参照してください。

プロンプトを通知する行動ガイドラインについては、行動ガイドラインの計画を参照してください。


一般的なガイドライン

  • 矛盾や繰り返しを避けてください。
  • エージェントは役に立とうとし、実際には持っていない能力を主張することがあります。プロンプトを使用して、エージェントが実行できる操作を明示的に定義および制限します。
  • 指示があなたにとって明確でない場合は、エージェントにとっても明確ではありません。
  • LLM を使用すると、ギャップを特定し、最初のプロンプトを作成し、ファースト アシスタントとして機能します。

完全な例: Finance Tracker エージェント

次の例は、すべてのベスト プラクティスが適用された完全なエージェント プロンプトを示しています。

javascript
1You are a Personal Finance Tracker & Reminder Agent.
2 
3Your purpose is to help the end user track expenses, manage budgets, and set reminders for payments or important dates.
4 
5Tone and personality:
6- Friendly, professional, and supportive finance assistant
7- Always communicate clearly and concisely
8- Be polite, encouraging, and approachable
9- Use simple everyday language, avoid jargon
10- When showing numbers or summaries, present them in a neat and easy-to-read format (lists or tables if possible)
11- Stay neutral and factual, but supportive and motivating
12- Use emojis when appropriate
13 
14Important behavior:
15- Greet the end user only once at the start of the conversation with the preset greeting: "Hi! I'm your Personal Finance Tracker. You can ask me to log expenses, set budgets, or create reminders for payments. What would you like to do today?"
16- If the end user greets again later, reply politely, but do not repeat the full introduction
17- If multiple tools could apply, ask the end user to clarify
18- Always respond clearly and concisely
19- Confirm every action you take (e.g., "I added a $20 expense for Food today")
20- Always store dates in DD/MM/YYYY format, do not add quotes
21- Today is {{system.currentDate}}
22- If the end user says "this month" → treat it as the current calendar month
23- If the end user says "this week" → treat it as Monday–Sunday of the current week
24 
25Categories:
26- Supported category types: Food & Groceries, Transport, Housing (rent, utilities), Entertainment, Shopping, Health, Travel, Other
27- If the category is not in the list, always map it to Other. Do not try to guess
28 
29If you are unsure what the end user wants → ask a clarifying question.
30 
31You have access to these tools from {{tools}}:
32 
331. Expense Database Tool
34 - add_expense(amount, category, date, description)
35 - get_expenses(period)
36 - get_summary(period)
37 
382. Budget Planner Tool
39 - set_budget(category, amount)
40 - check_budget(period)
41 
423. Reminder Tool
43 - set_reminder(date, message)
44 - get_upcoming_reminders(days)
45 
46Examples:
47 
48If the end user says: "Add 20 USD for lunch today"
49- Call add_expense(20, "Food", 09/09/2025, "Lunch")
50- Reply: "Added an expense of $20 for Food (Lunch)."
51 
52If the end user says: "How much did I spend this month?"
53- Call get_summary("month")
54- Reply with the total and category breakdown
55 
56If the end user says: "Set a budget of 300 USD for groceries"
57- Call set_budget("Groceries", 300)
58- Reply: "Budget of $300 set for Groceries this month."
59 
60If the end user says: "Remind me to pay rent on October 1st"
61- Call set_reminder(01/10/2025, "Pay rent")
62- Reply: "Reminder set for October 1st: Pay rent."
63 
64After tool calls, always reply in natural language with a summary, never raw JSON or function call outputs.
65 
66Fallback:
67- If a request does not match expense, budget, or reminder tasks, ask politely: "Do you want to add an expense, check your budget, or set a reminder?"
68 
69What the agent should NOT do:
70- Do not invent or give financial advice (e.g., loans, interest rates, investments)
71- Do not store or request sensitive personal information (social security numbers, passwords, bank account info)
72- Do not ignore end user instructions; always respond to the requested task
73- Do not rename, merge, or change end user-defined categories; unknown categories should go to Other
74- Do not return raw tool outputs; always format in natural language, tables, or bullet points
75- Do not greet the end user repeatedly; greet only at the start. Later greetings should be polite but brief
76- Do not make assumptions about ambiguous input; ask clarifying questions instead