azure-ai-agent-deploy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAzure AI Agent Deploy
Azure AI Agent 部署
Overview
概述
This skill guides the deployment of simple prompt-based Azure AI agents to Azure AI Foundry using YAML definitions. It automates the complex process of Azure authentication, project selection, model deployment, and agent creation while providing clear guidance for users unfamiliar with Azure constraints.
📦 Self-Contained: This skill includes all required Python scripts, bash scripts, and the agents module in the directory. No external repository dependencies are needed.
scripts/本Skill可指导用户通过YAML定义将基于提示词的简单Azure AI Agent部署至Azure AI Foundry。它能自动处理Azure身份验证、项目选择、模型部署和Agent创建等复杂流程,同时为不熟悉Azure限制的用户提供清晰指引。
📦 独立封装: 本Skill包含所有必需的Python脚本、bash脚本以及目录下的agents模块,无需依赖外部代码库。
scripts/Dependencies
依赖项
Core Python packages required:
azure-ai-projects==2.0.0b3
azure-ai-agents==1.1.0
azure-identity==1.25.1
azure-core==1.38.0
openai==2.16.0
PyYAML==6.0.3Full requirements: See for complete pinned dependencies.
scripts/requirements.txtSystem requirements:
- Python 3.10+
- Azure CLI () - must be installed and logged in
az
所需核心Python包:
azure-ai-projects==2.0.0b3
azure-ai-agents==1.1.0
azure-identity==1.25.1
azure-core==1.38.0
openai==2.16.0
PyYAML==6.0.3完整依赖列表: 完整的固定版本依赖项请查看。
scripts/requirements.txt系统要求:
- Python 3.10+
- Azure CLI () - 必须已安装并完成登录
az
Pre-Flight Check (IMPORTANT)
预检查(重要)
Before running any deployment commands, verify the environment is ready:
bash
undefined在运行任何部署命令前,请验证环境是否就绪:
bash
undefined1. Check Python dependencies are installed
1. 检查Python依赖是否已安装
python -c "from azure.ai.projects import AIProjectClient; from azure.identity import DefaultAzureCredential; import yaml; print('✅ Dependencies OK')" 2>/dev/null || echo "❌ Missing dependencies - run: pip install -r requirements.txt"
python -c "from azure.ai.projects import AIProjectClient; from azure.identity import DefaultAzureCredential; import yaml; print('✅ Dependencies OK')" 2>/dev/null || echo "❌ Missing dependencies - run: pip install -r requirements.txt"
2. Check Azure CLI is installed and logged in
2. 检查Azure CLI是否已安装并完成登录
az account show >/dev/null 2>&1 && echo "✅ Azure CLI OK" || echo "❌ Azure CLI not ready - run: az login"
**If dependencies are missing**, install them:
```bash
pip install -r requirements.txtaz account show >/dev/null 2>&1 && echo "✅ Azure CLI OK" || echo "❌ Azure CLI not ready - run: az login"
**若缺少依赖项,请执行以下命令安装:**
```bash
pip install -r requirements.txtOR install core packages directly:
或直接安装核心包:
pip install azure-ai-projects==2.0.0b3 azure-identity PyYAML openai
undefinedpip install azure-ai-projects==2.0.0b3 azure-identity PyYAML openai
undefinedQuick Start
快速开始
Setup: Copy the directory from this skill to your working directory.
scripts/The complete workflow involves 3 steps:
- Create agent YAML - Define agent with name, description, and instructions
- Deploy - Run to deploy to Azure (handles all Azure complexity)
create-agent.py - Test - Run for interactive testing
test-agent.py
Typical user flow:
bash
undefined设置: 将本Skill中的目录复制到你的工作目录。
scripts/完整工作流包含3个步骤:
- 创建Agent YAML - 定义Agent的名称、描述和指令
- 部署 - 运行将Agent部署至Azure(自动处理所有Azure相关复杂操作)
create-agent.py - 测试 - 运行进行交互式测试
test-agent.py
典型用户流程:
bash
undefinedSetup (one time)
一次性设置
cp -r scripts/* ./
cp -r scripts/* ./
Install dependencies (REQUIRED before deployment)
安装依赖项(部署前必须完成)
pip install -r requirements.txt
pip install -r requirements.txt
Verify Azure login
验证Azure登录状态
az login
az login
1. Create or use example: agents/examples/my-agent.yaml
1. 创建或使用示例文件:agents/examples/my-agent.yaml
python create-agent.py agents/examples/helpful-assistant.yaml --filter myproject
python create-agent.py agents/examples/helpful-assistant.yaml --filter myproject
2. Script handles: Azure auth, project selection, model deployment, agent creation
2. 脚本将处理:Azure身份验证、项目选择、模型部署、Agent创建
Creates: agents/examples/helpful-assistant.agent.txt with connection details
生成:agents/examples/helpful-assistant.agent.txt,包含连接信息
3. Test interactively
3. 交互式测试
python test-agent.py agents/examples/helpful-assistant.agent.txt
undefinedpython test-agent.py agents/examples/helpful-assistant.agent.txt
undefinedAgent YAML Format
Agent YAML格式
Agents use YAML frontmatter + instructions format:
yaml
---
name: agent-name
description: Brief description of what the agent does
model: gpt-4o-mini # Optional hint - if not found, will prompt/deploy
---
System instructions for the agent go here.
These become the agent's system prompt.
Example instructions:
You are a helpful assistant that specializes in...Required fields:
- - Agent identifier (lowercase, hyphens allowed)
name - - What the agent does (one sentence)
description
Optional fields:
- - Model hint (e.g.,
model,gpt-4o) - triggers auto-deployment if not foundgpt-4o-mini
Use the template in for new agents. See for complete examples.
assets/template-agent.yamlreferences/yaml-examples.mdAgent采用YAML前置元数据+指令的格式:
yaml
---
name: agent-name
description: Brief description of what the agent does
model: gpt-4o-mini # 可选提示 - 若未找到模型,将提示/部署模型
---
此处为Agent的系统指令。
这些内容将成为Agent的系统提示词。
示例指令:
你是一位专业的助手,擅长...必填字段:
- - Agent标识符(小写,允许使用连字符)
name - - Agent的功能描述(一句话)
description
可选字段:
- - 模型提示(例如
model,gpt-4o)- 若未找到模型,将触发自动部署gpt-4o-mini
创建新Agent时可使用模板。完整示例请查看。
assets/template-agent.yamlreferences/yaml-examples.mdDeployment Workflow
部署工作流
Prerequisites Check
先决条件检查
The script automatically checks:
create-agent.py- Azure CLI installed - Provides install commands if missing
- Azure login - Prompts for device code login if needed
- RBAC roles - Verifies user has Azure AI User/Contributor/Owner role
If role check fails, script provides admin command to fix:
bash
az role assignment create --role "Azure AI User" --assignee "user@example.com" --scope /subscriptions/{sub-id}create-agent.py- Azure CLI是否已安装 - 若未安装,将提供安装命令
- Azure登录状态 - 若未登录,将提示进行设备代码登录
- RBAC角色 - 验证用户是否拥有Azure AI User/Contributor/Owner角色
若角色检查失败,脚本将提供管理员修复命令:
bash
az role assignment create --role "Azure AI User" --assignee "user@example.com" --scope /subscriptions/{sub-id}Interactive Deployment Steps
交互式部署步骤
The script guides through each step:
1. Project Selection
- Lists Azure AI Foundry projects (with optional for large subscriptions)
--filter - Auto-selects if only one match
- Shows:
resource-name/project-name location
2. Model Deployment Selection
- Lists current deployments in selected project
- If model hint provided in YAML:
- Checks for exact match on deployment/model name
- Checks quota availability in project region
- Offers to deploy model automatically if not found
- If no model hint: shows all deployments for manual selection
- Can select existing deployment (letter A-Z) or deploy new model (number)
3. Model Deployment (if needed)
- Launches interactively
deploy-azure-model.sh - Handles:
- Model availability in region
- Quota checking (GlobalStandard/Standard SKUs)
- Capacity configuration (default 10K TPM)
- Deployment name conflicts
4. Agent Creation
- Creates prompt-based agent with AgentKind.PROMPT
- Handles name conflicts - prompts for new name if exists
- Verifies creation with follow-up GET request
5. Output
- Saves file with connection details and sample code
.agent.txt - Prints test command:
python test-agent.py <agent-name> <endpoint>
脚本将引导用户完成每个步骤:
1. 项目选择
- 列出Azure AI Foundry项目(针对大型订阅,可使用参数筛选)
--filter - 若仅匹配一个项目,将自动选择
- 显示内容:
resource-name/project-name location
2. 模型部署选择
- 列出所选项目中的当前部署
- 若YAML中提供了模型提示:
- 检查是否存在与部署/模型名称完全匹配的项
- 检查项目所在区域的配额可用性
- 若未找到模型,将提供自动部署选项
- 若未提供模型提示:显示所有部署供手动选择
- 可选择现有部署(字母A-Z)或部署新模型(数字选项)
3. 模型部署(如需)
- 交互式启动
deploy-azure-model.sh - 处理以下内容:
- 模型在目标区域的可用性
- 配额检查(GlobalStandard/Standard SKU)
- 容量配置(默认10K TPM)
- 部署名称冲突
4. Agent创建
- 创建基于提示词的Agent,类型为AgentKind.PROMPT
- 处理名称冲突 - 若名称已存在,将提示输入新名称
- 通过后续GET请求验证创建结果
5. 输出
- 保存文件,包含连接信息和示例代码
.agent.txt - 打印测试命令:
python test-agent.py <agent-name> <endpoint>
Command Reference
命令参考
bash
undefinedbash
undefinedBasic deployment
基础部署
python create-agent.py agents/examples/code-reviewer.yaml
python create-agent.py agents/examples/code-reviewer.yaml
Filter projects (useful for large subscriptions)
筛选项目(适用于大型订阅)
python create-agent.py agents/examples/math-tutor.yaml --filter maeda
python create-agent.py agents/examples/math-tutor.yaml --filter maeda
Deploy and test immediately
部署后立即测试
python create-agent.py agents/examples/helpful-assistant.yaml --test
undefinedpython create-agent.py agents/examples/helpful-assistant.yaml --test
undefinedTesting Agents
Agent测试
Interactive Testing
交互式测试
bash
undefinedbash
undefinedUsing .agent.txt file (recommended)
使用.agent.txt文件(推荐)
python test-agent.py agents/examples/my-agent.agent.txt
python test-agent.py agents/examples/my-agent.agent.txt
Direct specification
直接指定参数
python test-agent.py agent-name https://resource.services.ai.azure.com/api/projects/project-name
**Test session features:**
- Interactive chat loop
- Type 'exit' or 'quit' to end
- Ctrl+C to interrupt
- Prints Python code sample after conversationpython test-agent.py agent-name https://resource.services.ai.azure.com/api/projects/project-name
**测试会话功能:**
- 交互式聊天循环
- 输入'exit'或'quit'结束会话
- 按Ctrl+C中断
- 会话结束后打印Python代码示例Programmatic Usage
程序化调用
The file includes sample code:
.agent.txtpython
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
client = AIProjectClient(
endpoint="https://resource.services.ai.azure.com/api/projects/project",
credential=DefaultAzureCredential(),
)
openai_client = client.get_openai_client()
response = openai_client.responses.create(
input=[{"role": "user", "content": "Your message"}],
extra_body={"agent": {"name": "agent-name", "type": "agent_reference"}},
)
print(response.output_text).agent.txtpython
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
client = AIProjectClient(
endpoint="https://resource.services.ai.azure.com/api/projects/project",
credential=DefaultAzureCredential(),
)
openai_client = client.get_openai_client()
response = openai_client.responses.create(
input=[{"role": "user", "content": "Your message"}],
extra_body={"agent": {"name": "agent-name", "type": "agent_reference"}},
)
print(response.output_text)Setup Azure Infrastructure (Optional)
搭建Azure基础设施(可选)
If user needs to create Azure AI Foundry infrastructure from scratch:
bash
./setup-azure-ai.sh myproject swedencentralCreates:
- Resource group:
rg-myproject - AI Services resource: (with project management enabled)
myproject-resource - AI Foundry project:
myproject-project
Returns endpoint and API key for use.
若用户需要从零开始创建Azure AI Foundry基础设施:
bash
./setup-azure-ai.sh myproject swedencentral将创建以下资源:
- 资源组:
rg-myproject - AI服务资源:(已启用项目管理)
myproject-resource - AI Foundry项目:
myproject-project
返回可用于后续操作的端点和API密钥。
Model Deployment (Standalone)
模型部署(独立使用)
To deploy models without creating agents:
bash
undefined若无需创建Agent,仅需部署模型:
bash
undefinedInteractive deployment
交互式部署
./deploy-azure-model.sh
./deploy-azure-model.sh
With filters
带筛选参数部署
./deploy-azure-model.sh myresource gpt-4o
Features:
- Lists available models by region
- Checks quota (GlobalStandard/Standard)
- Configurable capacity (TPM)
- Can select existing deployments./deploy-azure-model.sh myresource gpt-4o
功能特性:
- 按区域列出可用模型
- 检查配额(GlobalStandard/Standard)
- 可配置容量(TPM)
- 可选择现有部署Important Constraints
重要限制
Agent Type
Agent类型
This skill only covers simple prompt-based agents (AgentKind.PROMPT). No tools like Code Interpreter, File Search, or custom functions. For tool-enabled agents, see .
.agents/skills/hosted-agents-v2-py/本Skill仅支持基于提示词的简单Agent(AgentKind.PROMPT)。不支持代码解释器、文件搜索或自定义函数等工具。如需使用支持工具的Agent,请查看。
.agents/skills/hosted-agents-v2-py/Model Requirements
模型要求
- Only OpenAI models (gpt-4o, gpt-4o-mini, gpt-4, gpt-35-turbo, etc.)
- Standard or GlobalStandard SKU (not Provisioned)
- Model must be available in project region
- Quota must be available (checked automatically)
- 仅支持OpenAI模型(gpt-4o、gpt-4o-mini、gpt-4、gpt-35-turbo等)
- 仅支持Standard或GlobalStandard SKU(不支持Provisioned)
- 模型必须在项目所在区域可用
- 必须有可用配额(将自动检查)
Azure Requirements
Azure要求
- Azure CLI must be installed
- User must be logged in via
az login - User needs Azure AI User role minimum (or Contributor/Owner)
- Uses (never API keys)
DefaultAzureCredential()
- 必须安装Azure CLI
- 用户必须通过完成登录
az login - 用户至少需要拥有Azure AI User角色(或Contributor/Owner角色)
- 使用(绝不使用API密钥)
DefaultAzureCredential()
Beta SDK Notice
Beta SDK说明
Uses (beta) - APIs may change. The API is specific to SDK 2.0.0b3+.
azure-ai-projects==2.0.0b3AgentDefinition使用的为Beta版本 - API可能会发生变化。 API仅适用于SDK 2.0.0b3及以上版本。
azure-ai-projects==2.0.0b3AgentDefinitionCommon Issues
常见问题
See for detailed solutions to:
references/troubleshooting.md- Authentication failures (tenant mismatches)
- RBAC permission errors
- Quota exhaustion
- Model availability by region
- Name conflicts
- SDK version issues
有关以下问题的详细解决方案,请查看:
references/troubleshooting.md- 身份验证失败(租户不匹配)
- RBAC权限错误
- 配额耗尽
- 模型区域可用性
- 名称冲突
- SDK版本问题
Bundled Scripts
内置脚本
This skill includes all required scripts and dependencies:
本Skill包含所有必需的脚本和依赖项:
Main Scripts
主脚本
- scripts/create-agent.py - Main deployment CLI (610 lines)
- scripts/test-agent.py - Interactive testing tool (179 lines)
- scripts/deploy-azure-model.sh - Model deployment (336 lines)
- scripts/setup-azure-ai.sh - Infrastructure setup (140 lines)
- scripts/create-agent.py - 主部署CLI(610行)
- scripts/test-agent.py - 交互式测试工具(179行)
- scripts/deploy-azure-model.sh - 模型部署脚本(336行)
- scripts/setup-azure-ai.sh - 基础设施搭建脚本(140行)
Python Module
Python模块
- scripts/agents/ - Core Python module with:
- - Module initialization
__init__.py - - YAML frontmatter parser
yaml_parser.py - - Agent creation via SDK
agent_builder.py - - Resource discovery
azure_discovery.py
- scripts/agents/ - 核心Python模块,包含:
- - 模块初始化文件
__init__.py - - YAML前置元数据解析器
yaml_parser.py - - 通过SDK创建Agent
agent_builder.py - - 资源发现
azure_discovery.py
Example Agents
示例Agent
- scripts/agents/examples/ - Agent YAML templates:
- - General purpose
helpful-assistant.yaml - - Code review
code-reviewer.yaml - - Tutoring
math-tutor.yaml - - Data analysis
data-analyst.yaml - - Fun pirate example
pirate-captain.yaml
- scripts/agents/examples/ - Agent YAML模板:
- - 通用助手
helpful-assistant.yaml - - 代码评审
code-reviewer.yaml - - 数学辅导
math-tutor.yaml - - 数据分析
data-analyst.yaml - - 趣味海盗示例
pirate-captain.yaml
Configuration
配置文件
- scripts/requirements.txt - Python dependencies
Usage: Copy the directory to your working directory to deploy agents.
scripts/- scripts/requirements.txt - Python依赖项列表
使用方法: 将目录复制到工作目录即可部署Agent。
scripts/Resources
资源
Setup Documentation
设置文档
- README.md - Complete setup guide with installation and configuration steps
- README.md - 包含安装和配置步骤的完整设置指南
References
参考文档
- troubleshooting.md - Solutions to common Azure/deployment errors
- yaml-examples.md - Complete agent YAML examples for various use cases
- troubleshooting.md - Azure/部署相关常见错误的解决方案
- yaml-examples.md - 适用于不同场景的完整Agent YAML示例
Assets
资源文件
- template-agent.yaml - Clean template for creating new agents
- template-agent.yaml - 用于创建新Agent的空白模板