Azure Ai Projects - Microsoft Foundry SDKs

Polar Sponsor
爱发电 赞助
.NET 9.0

使用 Azure AI 项目 Python SDK (azure-ai-projects) 构建 AI 应用。适用于处理 Foundry 项目客户端、使用 PromptAgentDefinition 创建版本化代理、运行评估、管理连接/部署/数据集/索引,或使用 OpenAI 兼容客户端。这是高级 Foundry SDK - 如需低级代理操作,请使用 azure-ai-agents-python 技能。

Azure AI Projects Python SDK(Foundry SDK). 在 Azure AI 创始人上使用 azure-ai- project S

功能概述

Azure AI Projects Python SDK(Foundry SDK). 在 Azure AI 创始人上使用 azure-ai- project S是一项面向实际任务的技能,主要用于客户操作概览;Acce 操作。

核心要点

  • 它将相关步骤、工具调用和结果整理方式集中到统一流程中,帮助使用者更快完成目标并减少重复操作。
  • 使用时应结合输入条件选择合适的执行方式,核对必要参数、依赖环境与输出内容,并按原始要求处理异常情况。
  • 该技能适合需要稳定复用相关能力的场景,可作为自动化工作流的一部分,也便于后续检查、调整和扩展。

使用与执行

从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;

结果检查与注意事项

若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。

Azure AI Projects Python SDK(Foundry SDK)

使用 azure-ai-projects SDK 在 Azure AI Foundry 上构建 AI 应用程序。

安装

pip install azure-ai-projects azure-identity

环境变量

AZURE_AI_PROJECT_ENDPOINT="https://.services.ai.azure.com/api/projects/"
AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-4o-mini"

身份验证

import os
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient

credential = DefaultAzureCredential()
client = AIProjectClient(
    endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
    credential=credential,
)

客户端操作概览

操作 访问路径 用途
client.agents .agents.* Agent 的增删改查、版本管理、会话线程(thread)、运行(run)
client.connections .connections.* 列出/获取项目连接(connection)
client.deployments .deployments.* 列出模型部署(model deployment)
client.datasets .datasets.* 数据集(dataset)管理
client.indexes .indexes.* 索引(index)管理
client.evaluations .evaluations.* 执行评估(evaluation)
client.red_teams .red_teams.* 红队(red team)操作

两种客户端使用方式

1. AIProjectClient(原生 Foundry 方式)

from azure.ai.projects import AIProjectClient

client = AIProjectClient(
    endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
    credential=DefaultAzureCredential(),
)

# 使用 Foundry 原生操作
agent = client.agents.create_agent(
    model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
    name="my-agent",
    instructions="You are helpful.",
)

2. 兼容 OpenAI 的客户端

# 从项目获取兼容 OpenAI 的客户端
openai_client = client.get_openai_client()

# 使用标准 OpenAI API
response = openai_client.chat.completions.create(
    model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
    messages=[{"role": "user", "content": "Hello!"}],
)

Agent 操作

创建 Agent(基础版)

agent = client.agents.create_agent(
    model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
    name="my-agent",
    instructions="You are a helpful assistant.",
)

创建带工具的 Agent

from azure.ai.agents import CodeInterpreterTool, FileSearchTool

agent = client.agents.create_agent(
    model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
    name="tool-agent",
    instructions="You can execute code and search files.",
    tools=[CodeInterpreterTool(), FileSearchTool()],
)

使用 PromptAgentDefinition 创建带版本的 Agent

from azure.ai.projects.models import PromptAgentDefinition

# 创建带版本的 Agent
agent_version = client.agents.create_version(
    agent_name="customer-support-agent",
    definition=PromptAgentDefinition(
        model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
        instructions="You are a customer support specialist.",
        tools=[],  # 根据需要添加工具
    ),
    version_label="v1.0",
)

详见 references/agents.md 中关于 Agent 的详细模式说明。

工具概览

工具 类名 适用场景
代码解释器 CodeInterpreterTool 执行 Python 代码、生成文件
文件搜索 FileSearchTool 对已上传文档执行 RAG
Bing 接地 BingGroundingTool 网页搜索(需配置 connection)
Azure AI Search AzureAISearchTool 搜索您创建的索引
函数调用 FunctionTool 调用您的 Python 函数
OpenAPI OpenApiTool 调用 REST API
MCP McpTool 对接 Model Context Protocol 服务器
内存搜索 MemorySearchTool 搜索 Agent 的内存存储(memory store)
SharePoint SharepointGroundingTool 搜索 SharePoint 内容

所有工具的使用模式详见 references/tools.md。

会话线程(Thread)与消息流

# 1. 创建 thread
thread = client.agents.threads.create()

# 2. 添加消息
client.agents.messages.create(
    thread_id=thread.id,
    role="user",
    content="What's the weather like?",
)

# 3. 创建并处理 run
run = client.agents.runs.create_and_process(
    thread_id=thread.id,
    agent_id=agent.id,
)

# 4. 获取响应
if run.status == "completed":
    messages = client.agents.messages.list(thread_id=thread.id)
    for msg in messages:
        if msg.role == "assistant":
            print(msg.content[0].text.value)

连接(Connections)

# 列出所有 connection
connections = client.connections.list()
for conn in connections:
    print(f"{conn.name}: {conn.connection_type}")

# 获取指定 connection
connection = client.connections.get(connection_name="my-search-connection")

连接相关使用模式详见 references/connections.md。

部署(Deployments)

# 列出可用的模型部署
deployments = client.deployments.list()
for deployment in deployments:
    print(f"{deployment.name}: {deployment.model}")

部署相关使用模式详见 references/deployments.md。

数据集(Datasets)与索引(Indexes)

# 列出数据集
datasets = client.datasets.list()

# 列出索引
indexes = client.indexes.list()

数据操作相关说明详见 references/datasets-indexes.md。

评估(Evaluation)

# 使用 OpenAI 客户端执行评估
openai_client = client.get_openai_client()

# 使用内置评估器创建评估任务
eval_run = openai_client.evals.runs.create(
    eval_id="my-eval",
    name="quality-check",
    data_source={
        "type": "custom",
        "item_references": [{"item_id": "test-1"}],
    },
    testing_criteria=[
        {"type": "fluency"},
        {"type": "task_adherence"},
    ],
)

评估相关使用模式详见 references/evaluation.md。

异步客户端(Async Client)

from azure.ai.projects.aio import AIProjectClient

async with AIProjectClient(
    endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
    credential=DefaultAzureCredential(),
) as client:
    agent = await client.agents.create_agent(...)
    # ... 异步操作

异步使用模式详见 references/async-patterns.md。

内存存储(Memory Stores)

# 为 Agent 创建内存存储
memory_store = client.agents.create_memory_store(
    name="conversation-memory",
)

# 将其附加至 Agent,实现持久化记忆能力
agent = client.agents.create_agent(
    model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
    name="memory-agent",
    tools=[MemorySearchTool()],
    tool_resources={"memory": {"store_ids": [memory_store.id]}},
)

最佳实践

  1. 使用上下文管理器 管理异步客户端:async with AIProjectClient(...) as client:
  2. 及时清理 Agent:任务完成后调用 client.agents.delete_agent(agent.id)
  3. 对简单运行使用 create_and_process,对实时用户体验(UX)则优先采用 流式响应(streaming)
  4. 生产环境部署应使用带版本的 Agent
  5. 推荐使用 connection 集成外部服务(如 AI Search、Bing 等)

SDK 对比

功能 azure-ai-projects azure-ai-agents
抽象层级 高层级(面向 Foundry) 低层级(面向 Agents)
客户端类型 AIProjectClient AgentsClient
版本支持 create_version() 不支持
连接(Connections) 支持 不支持
部署(Deployments) 支持 不支持
数据集 / 索引 支持 不支持
评估(Evaluation) 通过 OpenAI 客户端支持 不支持
适用场景 需完整集成 Azure AI Foundry 的应用 独立的 Agent 应用

参考文档文件

  • references/agents.md:使用 PromptAgentDefinition 的 Agent 操作示例
  • references/tools.md:全部 Agent 工具及其使用示例
  • references/evaluation.md:评估操作及内置评估器说明
  • references/connections.md:连接(connection)操作说明
  • references/deployments.md:模型部署枚举说明
  • references/datasets-indexes.md:数据集与索引操作说明
  • references/async-patterns.md:异步客户端使用说明

相关专题

更多
vsd文件打开方法
vsd文件打开方法

vsd文件打开方法有使用Microsoft Visio软件、使用Microsoft Visio查看器、转换为其他格式等。想了解更多vsd文件相关内容,可以阅读本专题下面的文章。

2023.10.30

1042

5

Aionclaw智能助手介绍
Aionclaw智能助手介绍

本专题汇总了AionClaw(AI龙虾助手)的功能介绍与在线使用入口。AionClaw是杭州趣猿人工智能有限公司推出的桌面级AI智能体,能直接在电脑上读写文件、运行脚本、操作浏览器,自动交付Word、PPT、Excel等成品。

2026.09.20

0

13

AionClaw AI智能体与电脑自动化任务执行功能使用教程
AionClaw AI智能体与电脑自动化任务执行功能使用教程

AionClaw专题整理AI智能体与电脑自动化相关功能使用教程,涵盖安装部署、AI任务执行、Skills技能、文件处理、浏览器控制、电脑操作、持久记忆、聊天工具连接以及办公、编程和内容创作等功能,帮助用户快速掌握AionClaw的实际使用方法。

2026.09.20

0

15

AI视频生成软件推荐
AI视频生成软件推荐

本专题汇总了当前主流的AI视频生成软件推荐与排行榜单,涵盖seko、AniShort、剧云、Lovart、LiblibAI及立刻mv等热门工具。同时整理了各软件在文生视频、图生视频、时长限制、画质表现及免费额度等方面的差异对比,助您快速选对适合创作需求的AI视频生成工具。

2026.09.16

0

9

ai生成视频的工具免费版合集
ai生成视频的工具免费版合集

本专题汇总了当前免费AI生成视频工具的排行榜与推荐清单,涵盖seko、讯飞智作、AniShort及剧云、Lovart等多模型集成平台。同时整理了各工具的免费额度、输出时长、水印政策及适用场景差异,助您快速选择合适工具开启AI视频创作。

2026.09.16

0

10

Pandas时间序列分析与可视化报表
Pandas时间序列分析与可视化报表

本专题整理Pandas日期转换、时间索引、重采样、滚动窗口、时区处理、plot绘图、Styler表格样式和报表输出方法。

2026.09.16

0

23

Pandas数据筛选索引与清洗处理
Pandas数据筛选索引与清洗处理

本专题整理Pandas中的loc、iloc、条件筛选、query查询、缺失值处理、重复值删除、类型转换和字符串列清洗方法。

2026.09.16

0

25

Pandas数据读取导入与文件导出处理
Pandas数据读取导入与文件导出处理

本专题整理Pandas读取CSV、Excel、JSON、SQL、Parquet等文件的方法,以及to_csv、to_excel、to_sql和to_parquet等常用数据导出流程。

2026.09.16

0

27

GDB怎么设置断点
GDB怎么设置断点

本专题介绍GDB按照函数名、源代码行号和文件位置设置断点的方法,详细说明run、continue、next、step等命令的配合使用,帮助定位程序崩溃、逻辑异常及代码未按预期执行的问题。

2026.09.11

0

28

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Microsoft Copilot官方手册
Microsoft Copilot官方手册

共0课时 | 0人学习

C# 教程
C# 教程

共94课时 | 21.6万人学习

ASP教程
ASP教程

共36课时 | 48.7万人学习