(点击上方图片观看本课程视频)
本课程将涵盖
完成本课程后,您将了解如何
我们首先来看看如何构建安全的智能体应用程序。安全意味着AI智能体按设计运行。作为智能体应用程序的构建者,我们有方法和工具来最大程度地提高安全性。
如果您曾使用大型语言模型(LLM)构建过AI应用程序,您会知道设计健壮的系统提示或系统消息的重要性。这些提示建立了LLM将如何与用户和数据交互的元规则、指令和指南。
对于AI智能体而言,系统提示更为重要,因为AI智能体需要高度具体的指令才能完成我们为其设计的任务。
为了创建可扩展的系统提示,我们可以使用一个系统消息框架来构建应用程序中的一个或多个智能体。
元提示将由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智能体将使用的知识库和其他服务。这可能涉及破坏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智能体需要精心的设计、 robust 的安全措施和持续的迭代。通过实施结构化的元提示系统、理解潜在威胁并应用缓解策略,开发人员可以创建既安全又有效的AI智能体。此外,引入人机协同方法可确保AI智能体与用户需求保持一致,同时最大程度地降低风险。随着AI的不断发展,在安全性、隐私和伦理考虑方面保持积极主动的态度将是培养AI驱动系统信任和可靠性的关键。
加入 Azure AI Foundry Discord,与其他学习者交流,参加办公时间,并获得您的 AI Agent 问题解答。