定制模板 !!! tip "完成本模块后,您将能够" [ ] 探索默认的 AI Agent 功能 [ ] 使用自己的索引添加 AI 搜索 [ ] 激活并分析追踪指标 [ ] 执行评估运行 [ ] 执行红队扫描 [ ] 实验 5:制定定制计划 5.1 AI Agent 功能 !!! success "我们在实验 01 中已完成" 文件搜索:OpenAI 内置的文件搜索功能,用于知识检索 引用:响应中的自动来源归属 可定制指令:修改代理行为和个性 工具集成:可扩展的工具系统,用于自定义功能 5.2 知识检索选项 !!!
!!! tip "完成本模块后,您将能够"
- [ ] 探索默认的 AI Agent 功能 - [ ] 使用自己的索引添加 AI 搜索 - [ ] 激活并分析追踪指标 - [ ] 执行评估运行 - [ ] 执行红队扫描 - [ ] **实验 5:制定定制计划**
!!! success "我们在实验 01 中已完成"
!!! task "完成此任务需要进行更改并重新部署"
```bash title="" # 设置环境变量 azd env set USE_AZURE_AI_SEARCH_SERVICE true azd env set AZURE_AI_EMBED_MODEL_NAME "text-embedding-3-large" azd env set AZURE_AI_EMBED_DEPLOYMENT_NAME "embeddings-large" azd env set AZURE_AI_EMBED_DEPLOYMENT_CAPACITY 75 azd env set AZURE_AI_SEARCH_INDEX_NAME "retail-products" # 上传数据并创建我的索引 ```
OpenAI 文件搜索(默认):
Azure AI 搜索(可选):
USE_AZURE_AI_SEARCH_SERVICE=true!!! task "完成此任务需要进行更改并重新部署"
```bash title="" azd env set ENABLE_AZURE_MONITOR_TRACING true azd deploy ```
追踪:
日志记录:
本地评估:
持续监控:
CI/CD 集成:
AI 红队:
认证:
!!! quote "完成本实验后,您应该已经"
- [ ] 定义了场景需求
- [ ] 定制了环境变量(配置)
- [ ] 定制了代理指令(任务)
- [ ] 部署了定制模板(应用)
- [ ] 完成了部署后的任务(手动)
- [ ] 运行了测试评估
此示例展示了如何为企业零售场景定制模板,使用两个专用代理和多个模型部署。
gpt-4.1:主要聊天模型o3:用于复杂查询的推理模型gpt-4.1-nano:用于简单交互的轻量模型text-embedding-3-large:用于搜索的高质量嵌入模型创建设置脚本 (setup-retail.sh)
#!/bin/bash # Set environment name azd env set AZURE_ENV_NAME "retail-ai-agents" # Configure region (choose based on model availability) azd env set AZURE_LOCATION "eastus2" # Enable all optional services azd env set USE_APPLICATION_INSIGHTS true azd env set USE_AZURE_AI_SEARCH_SERVICE true azd env set ENABLE_AZURE_MONITOR_TRACING true # Configure primary chat model (gpt-4o as closest available to gpt-4.1) azd env set AZURE_AI_AGENT_MODEL_NAME "gpt-4o" azd env set AZURE_AI_AGENT_MODEL_FORMAT "OpenAI" azd env set AZURE_AI_AGENT_DEPLOYMENT_NAME "chat-primary" azd env set AZURE_AI_AGENT_DEPLOYMENT_CAPACITY 150 # Configure embedding model for enhanced search azd env set AZURE_AI_EMBED_MODEL_NAME "text-embedding-3-large" azd env set AZURE_AI_EMBED_DEPLOYMENT_NAME "embeddings-large" azd env set AZURE_AI_EMBED_DEPLOYMENT_CAPACITY 75 # Set agent name (will create first agent) azd env set AZURE_AI_AGENT_NAME "shopper-agent" # Configure search index azd env set AZURE_AI_SEARCH_INDEX_NAME "retail-products" echo "Environment configured for retail deployment" echo "Recommended quota: 300,000+ TPM across all models"
创建 custom-agents/shopper-agent-instructions.md:
# Shopper Agent Instructions You are a helpful shopping assistant for an enterprise retail company. Your role is to: 1. **Product Discovery**: Help customers find products that match their needs 2. **Comparison**: Provide detailed product comparisons with pros/cons 3. **Recommendations**: Suggest complementary products and alternatives 4. **Inventory**: Check product availability and delivery options ## Guidelines: - Always provide citations from the product catalog - Be conversational and helpful - Ask clarifying questions to understand customer needs - Mention relevant promotions when appropriate - Escalate complex warranty or return questions to human agents ## Knowledge Base: You have access to our complete product catalog including specifications, pricing, reviews, and inventory levels.
创建 custom-agents/loyalty-agent-instructions.md:
# Loyalty Agent Instructions You are a customer loyalty specialist focused on maximizing customer satisfaction and retention. Your responsibilities include: 1. **Rewards Management**: Explain point values, redemption options, and tier benefits 2. **Promotions**: Identify applicable discounts and special offers 3. **Program Navigation**: Help customers understand loyalty program features 4. **Account Support**: Assist with account-related questions and updates ## Guidelines: - Prioritize customer satisfaction and retention - Explain complex program rules in simple terms - Proactively identify opportunities for customers to save money - Celebrate customer milestones and achievements - Connect customers with shopper agent for product questions ## Knowledge Base: You have access to loyalty program rules, current promotions, customer tier information, and reward catalogs.
创建 deploy-retail.sh:
#!/bin/bash set -e echo " Starting Enterprise Retail AI Agents deployment..." # Validate prerequisites echo " Validating prerequisites..." if ! command -v azd &> /dev/null; then echo "❌ Azure Developer CLI (azd) is required" exit 1 fi if ! az account show &> /dev/null; then echo "❌ Please login to Azure CLI: az login" exit 1 fi # Set up environment echo " Configuring deployment environment..." chmod +x setup-retail.sh ./setup-retail.sh # Check quota in selected region echo " Checking quota availability..." LOCATION=$(azd env get-values | grep AZURE_LOCATION | cut -d'=' -f2 | tr -d '"') echo "Deploying to region: $LOCATION" echo "⚠️ Please verify you have 300,000+ TPM quota for:" echo " - gpt-4o: 150,000 TPM" echo " - text-embedding-3-large: 75,000 TPM" echo " - Additional models: 75,000+ TPM" read -p "Continue with deployment? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Deployment cancelled" exit 1 fi # Deploy infrastructure and application echo "️ Deploying Azure infrastructure..." azd up # Capture deployment outputs echo " Capturing deployment information..." azd show > deployment-info.txt # Get the web app URL APP_URL=$(azd show --output json | jq -r '.services.api_and_frontend.project.target.url // empty') if [ ! -z "$APP_URL" ]; then echo "✅ Deployment completed successfully!" echo " Web Application: $APP_URL" echo " Azure Portal: Run 'azd show' for resource group link" echo " AI Foundry Portal: https://ai.azure.com" else echo "⚠️ Deployment completed but unable to retrieve URL" echo "Run 'azd show' for deployment details" fi echo " Next steps:" echo "1. Create second agent (Loyalty Agent) in AI Foundry portal" echo "2. Upload product catalog to search index" echo "3. Configure custom agent instructions" echo "4. Test both agents with sample queries"
创建 configure-retail-agents.sh:
#!/bin/bash echo " Configuring retail agents..." # Get deployment information PROJECT_ENDPOINT=$(azd env get-values | grep AZURE_EXISTING_AIPROJECT_ENDPOINT | cut -d'=' -f2 | tr -d '"') AGENT_ID=$(azd env get-values | grep AZURE_EXISTING_AGENT_ID | cut -d'=' -f2 | tr -d '"') echo "Project Endpoint: $PROJECT_ENDPOINT" echo "Primary Agent ID: $AGENT_ID" # Instructions for manual configuration echo " Agent Configuration: 1. **Update Shopper Agent Instructions:** - Go to AI Foundry portal: https://ai.azure.com - Navigate to your project - Select Agents tab - Edit the existing agent - Update instructions with content from custom-agents/shopper-agent-instructions.md 2. **Create Loyalty Agent:** - In Agents tab, click 'Create Agent' - Name: 'loyalty-agent' - Model: Use same deployment as shopper agent - Instructions: Use content from custom-agents/loyalty-agent-instructions.md - Enable file search tool - Save and note the Agent ID 3. **Upload Knowledge Base:** - Prepare product catalog files (JSON/CSV format) - Upload to both agents' file search - Or configure Azure AI Search index 4. **Test Configuration:** - Test shopper agent with product queries - Test loyalty agent with rewards questions - Verify citations and search functionality Monitoring Setup: - Tracing: Available in AI Foundry > Tracing tab - Logs: Azure Portal > Container Apps > Monitoring > Log Stream - Evaluation: Run python evals/evaluate.py Security Validation: - Run red teaming: python airedteaming/ai_redteaming.py - Review security recommendations - Configure authentication if needed "
创建 test-retail-deployment.sh:
#!/bin/bash echo " Testing retail deployment..." # Verify environment variables are set echo " Checking environment configuration..." azd env get-values | grep -E "(AZURE_AI_|USE_|ENABLE_)" # Test web application availability APP_URL=$(azd show --output json | jq -r '.services.api_and_frontend.project.target.url // empty') if [ ! -z "$APP_URL" ]; then echo " Testing web application at: $APP_URL" HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$APP_URL") if [ "$HTTP_STATUS" = "200" ]; then echo "✅ Web application is responding" else echo "❌ Web application returned status: $HTTP_STATUS" fi else echo "❌ Could not retrieve web application URL" fi # Run evaluation if configured if [ -f "evals/evaluate.py" ]; then echo " Running agent evaluation..." cd evals python -m pip install -r ../src/requirements.txt python -m pip install azure-ai-evaluation python evaluate.py cd .. fi echo " Deployment validation complete! Next steps: 1. Access the web application and test basic functionality 2. Create the second agent (Loyalty Agent) in AI Foundry portal 3. Upload your product catalog and loyalty program data 4. Configure agent instructions for your specific use case 5. Run comprehensive testing with your retail scenarios "
按照此实施指南操作后,您将拥有:
已部署的基础设施:
初始代理:
准备定制:
生产就绪:
此示例展示了如何扩展和定制 AZD 模板以适应特定企业场景,同时保持安全性、监控和可扩展性的最佳实践。