(上の画像をクリックすると、このレッスンのビデオをご覧いただけます)
このレッスンでは以下を学びます:
このレッスンを完了すると、以下ができるようになります:
まず、安全なエージェントアプリケーションを構築する方法を見ていきましょう。安全性とは、AIエージェントが設計通りに動作することを意味します。エージェントアプリケーションの開発者として、安全性を最大化するための方法とツールがあります。
大規模言語モデル(LLM)を使用してAIアプリケーションを構築したことがある場合、堅牢なシステムプロンプトやシステムメッセージを設計する重要性をご存じでしょう。これらのプロンプトは、LLMがユーザーやデータとどのようにやり取りするかの基本ルール、指示、ガイドラインを確立します。
AIエージェントの場合、システムプロンプトはさらに重要です。エージェントが設計されたタスクを完了するためには、非常に具体的な指示が必要です。
スケーラブルなシステムプロンプトを作成するために、アプリケーション内で1つ以上のエージェントを構築するためのシステムメッセージフレームワークを使用できます:
メタプロンプトは、LLMがエージェント用のシステムプロンプトを生成するために使用します。テンプレートとして設計することで、必要に応じて複数のエージェントを効率的に作成できます。
以下は、LLMに提供するメタシステムメッセージの例です:
You are an expert at creating AI agent assistants.
You will be provided a company name, role, responsibilities and other
information that you will use to provide a system prompt for.
To create the system prompt, be descriptive as possible and provide a structure that a system using an LLM can better understand the role and responsibilities of the AI assistant.
次に、AIエージェントを説明する基本プロンプトを作成します。エージェントの役割、完了するタスク、その他の責任を含めるべきです。
以下はその例です:
You are a travel agent for Contoso Travel that is great at booking flights for customers. To help customers you can perform the following tasks: lookup available flights, book flights, ask for preferences in seating and times for flights, cancel any previously booked flights and alert customers on any delays or cancellations of flights.
次に、メタシステムメッセージをシステムメッセージとして提供し、基本システムメッセージを組み合わせて最適化します。
これにより、AIエージェントを導くためにより適したシステムメッセージが生成されます:
**Company Name:** Contoso Travel
**Role:** Travel Agent Assistant
**Objective:**
You are an AI-powered travel agent assistant for Contoso Travel, specializing in booking flights and providing exceptional customer service. Your main goal is to assist customers in finding, booking, and managing their flights, all while ensuring that their preferences and needs are met efficiently.
**Key Responsibilities:**
1. **Flight Lookup:**
- Assist customers in searching for available flights based on their specified destination, dates, and any other relevant preferences.
- Provide a list of options, including flight times, airlines, layovers, and pricing.
2. **Flight Booking:**
- Facilitate the booking of flights for customers, ensuring that all details are correctly entered into the system.
- Confirm bookings and provide customers with their itinerary, including confirmation numbers and any other pertinent information.
3. **Customer Preference Inquiry:**
- Actively ask customers for their preferences regarding seating (e.g., aisle, window, extra legroom) and preferred times for flights (e.g., morning, afternoon, evening).
- Record these preferences for future reference and tailor suggestions accordingly.
4. **Flight Cancellation:**
- Assist customers in canceling previously booked flights if needed, following company policies and procedures.
- Notify customers of any necessary refunds or additional steps that may be required for cancellations.
5. **Flight Monitoring:**
- Monitor the status of booked flights and alert customers in real-time about any delays, cancellations, or changes to their flight schedule.
- Provide updates through preferred communication channels (e.g., email, SMS) as needed.
**Tone and Style:**
- Maintain a friendly, professional, and approachable demeanor in all interactions with customers.
- Ensure that all communication is clear, informative, and tailored to the customer's specific needs and inquiries.
**User Interaction Instructions:**
- Respond to customer queries promptly and accurately.
- Use a conversational style while ensuring professionalism.
- Prioritize customer satisfaction by being attentive, empathetic, and proactive in all assistance provided.
**Additional Notes:**
- Stay updated on any changes to airline policies, travel restrictions, and other relevant information that could impact flight bookings and customer experience.
- Use clear and concise language to explain options and processes, avoiding jargon where possible for better customer understanding.
This AI assistant is designed to streamline the flight booking process for customers of Contoso Travel, ensuring that all their travel needs are met efficiently and effectively.
このシステムメッセージフレームワークの価値は、複数のエージェント用のシステムメッセージを簡単にスケール作成できることと、時間をかけて改善できることです。最初から完全なユースケースに対応するシステムメッセージが得られることは稀です。基本システムメッセージを少しずつ調整し、システムを通じて実行することで、結果を比較・評価できます。
信頼できるAIエージェントを構築するには、リスクや脅威を理解し、それを軽減することが重要です。ここでは、AIエージェントに対するさまざまな脅威の一部と、それに対する計画・準備方法を見ていきます。
説明: 攻撃者がプロンプトや入力を操作して、AIエージェントの指示や目標を変更しようとします。
軽減策: AIエージェントが処理する前に、危険なプロンプトを検出するための検証チェックや入力フィルターを実行します。これらの攻撃は通常、エージェントとの頻繁なやり取りを必要とするため、会話のターン数を制限することも防止策の一つです。
説明: AIエージェントが機密データを保存するシステムやサービスにアクセスできる場合、攻撃者はエージェントとこれらのサービス間の通信を侵害する可能性があります。これには直接的な攻撃や、エージェントを通じてこれらのシステムに関する情報を得ようとする間接的な試みが含まれます。
軽減策: AIエージェントは必要最小限のアクセス権のみを持つべきです。エージェントとシステム間の通信は安全である必要があります。認証とアクセス制御を実装することも、この情報を保護する方法の一つです。
説明: AIエージェントはタスクを完了するためにさまざまなツールやサービスにアクセスできます。攻撃者はこの能力を利用して、AIエージェントを通じて大量のリクエストを送信し、システム障害や高コストを引き起こす可能性があります。
軽減策: AIエージェントがサービスに送信できるリクエスト数を制限するポリシーを実装します。会話のターン数やエージェントへのリクエスト数を制限することも、この種の攻撃を防ぐ方法です。
説明: この種の攻撃はAIエージェント自体を直接狙うのではなく、エージェントが使用するナレッジベースや他のサービスを狙います。これにより、エージェントがタスクを完了するために使用するデータや情報が汚染され、ユーザーに偏ったり意図しない応答を返す可能性があります。
軽減策: AIエージェントがワークフローで使用するデータを定期的に検証します。このデータへのアクセスを安全に保ち、信頼できる人物のみが変更できるようにすることで、この種の攻撃を防ぎます。
説明: AIエージェントはタスクを完了するためにさまざまなツールやサービスにアクセスします。攻撃者によるエラーが他のシステムの障害を引き起こし、エージェントが接続されているシステム全体に影響を及ぼす可能性があります。これにより、攻撃が広範囲に及び、トラブルシューティングが困難になります。
軽減策: AIエージェントが直接システムを攻撃されないように、Dockerコンテナ内でタスクを実行するなど、限定された環境で動作させる方法があります。また、特定のシステムがエラーを返した場合にフォールバックメカニズムやリトライロジックを作成することも、大規模なシステム障害を防ぐ方法です。
信頼できるAIエージェントシステムを構築するもう一つの効果的な方法は、ヒューマン・イン・ザ・ループを使用することです。これにより、ユーザーがエージェントにフィードバックを提供し、実行中のプロセスを承認または終了するフローを作成できます。ユーザーは、マルチエージェントシステム内のエージェントとして機能し、プロセスを監視します。
以下は、この概念を実装するためにAutoGenを使用したコードスニペットです:
# Create the agents.
model_client = OpenAIChatCompletionClient(model="gpt-4o-mini")
assistant = AssistantAgent("assistant", model_client=model_client)
user_proxy = UserProxyAgent("user_proxy", input_func=input) # Use input() to get user input from console.
# Create the termination condition which will end the conversation when the user says "APPROVE".
termination = TextMentionTermination("APPROVE")
# Create the team.
team = RoundRobinGroupChat([assistant, user_proxy], termination_condition=termination)
# Run the conversation and stream to the console.
stream = team.run_stream(task="Write a 4-line poem about the ocean.")
# Use asyncio.run(...) when running in a script.
await Console(stream)
信頼できるAIエージェントを構築するには、慎重な設計、堅牢なセキュリティ対策、継続的な改善が必要です。構造化されたメタプロンプトシステムを実装し、潜在的な脅威を理解し、軽減戦略を適用することで、安全で効果的なAIエージェントを作成できます。さらに、ヒューマン・イン・ザ・ループアプローチを取り入れることで、AIエージェントがユーザーのニーズに合致し、リスクを最小限に抑えることができます。AIが進化し続ける中で、セキュリティ、プライバシー、倫理的考慮に積極的に取り組む姿勢を維持することが、AI駆動システムにおける信頼性と信頼を育む鍵となります。
Azure AI Foundry Discordに参加して、他の学習者と交流したり、オフィスアワーに参加したり、AIエージェントに関する質問に答えてもらいましょう。
免責事項:
この文書は、AI翻訳サービス Co-op Translator を使用して翻訳されています。正確性を追求しておりますが、自動翻訳には誤りや不正確な部分が含まれる可能性があることをご承知ください。元の言語で記載された文書が正式な情報源とみなされるべきです。重要な情報については、専門の人間による翻訳を推奨します。この翻訳の使用に起因する誤解や誤解釈について、当方は一切の責任を負いません。