azure-ai-projects-ts について
Azure AI Foundry プロジェクトを扱う TypeScript SDK スキルで、エージェントやプロジェクトリソースを管理する開発者向けです。エージェントの作成・実行に加え、接続、デプロイ、データセット、インデックス、評価を扱います。
主な機能
- 01エージェントの作成とバージョン管理
- 02ツール付きエージェントの実行
- 03プロジェクト接続の管理
- 04モデルデプロイの一覧表示
- 05データセットのアップロードとインデックス管理
- 06評価指標とメモリの管理
活用シーン
- 01プロジェクトエージェントの定義と実行
- 02接続リソースとデプロイの確認
- 03プロジェクトのワークフロー用データセットのアップロード
- 04検索インデックスと評価の設定
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ sickn33/ agentic-awesome-skills --skill azure-ai-projects-tsインストール後、Claude Code で/azure-ai-projects-tsを入力して読み込まれたか確認します。
詳細
Azure AI Projects SDK for TypeScript
エージェント、接続、デプロイ、評価機能を備えた Azure AI Foundry プロジェクト向けの高レベル SDK です。
インストール
npm install @azure/ai-projects @azure/identity
トレーシングを行う場合:
npm install @azure/monitor-opentelemetry @opentelemetry/api
環境変数
AZURE_AI_PROJECT_ENDPOINT=https://<resource>.services.ai.azure.com/api/projects/<project>
MODEL_DEPLOYMENT_NAME=gpt-4o
認証
import { AIProjectClient } from "@azure/ai-projects";
import { DefaultAzureCredential } from "@azure/identity";
const client = new AIProjectClient(
process.env.AZURE_AI_PROJECT_ENDPOINT!,
new DefaultAzureCredential()
);
SDK の生成と影響
これらの独立したコード片では、バージョンによって異なるプロジェクト/エージェント API が使用されています。実際のパッケージ/API の世代を固定し、使用前に利用可能な操作グループを確認してください。エージェントの実行、データセットのアップロード、ツールの使用前に、テナント/プロジェクトと予算を確認してください。コードインタープリター/MCP はコードを実行したり、非公開データを漏えいさせたりする可能性があります。getWithCredentials はシークレットを返すため、通常の検出操作としては使用しないでください。クリーンアップの対象は、このタスクで作成し、所有しているリソースのみにしてください。
操作グループ
| グループ | 目的 |
|---|---|
client.agents | AI エージェントの作成と管理 |
client.connections | 接続済みの Azure リソースの一覧表示 |
client.deployments | モデルのデプロイの一覧表示 |
client.datasets | データセットのアップロードと管理 |
client.indexes | 検索インデックスの作成と管理 |
client.evaluators | 評価指標の管理 |
client.memoryStores | エージェントのメモリーの管理 |
OpenAI クライアントの取得
const openAIClient = await client.getOpenAIClient();
// Use for responses
const response = await openAIClient.responses.create({
model: "gpt-4o",
input: "What is the capital of France?"
});
// Use for conversations
const conversation = await openAIClient.conversations.create({
items: [{ type: "message", role: "user", content: "Hello!" }]
});
エージェント
エージェントの作成
const agent = await client.agents.createVersion("my-agent", {
kind: "prompt",
model: "gpt-4o",
instructions: "You are a helpful assistant."
});
ツールを使用するエージェント
// Code Interpreter
const agent = await client.agents.createVersion("code-agent", {
kind: "prompt",
model: "gpt-4o",
instructions: "You can execute code.",
tools: [{ type: "code_interpreter", container: { type: "auto" } }]
});
// File Search
const agent = await client.agents.createVersion("search-agent", {
kind: "prompt",
model: "gpt-4o",
tools: [{ type: "file_search", vector_store_ids: [vectorStoreId] }]
});
// Web Search
const agent = await client.agents.createVersion("web-agent", {
kind: "prompt",
model: "gpt-4o",
tools: [{
type: "web_search_preview",
user_location: { type: "approximate", country: "US", city: "Seattle" }
}]
});
// Azure AI Search
const agent = await client.agents.createVersion("aisearch-agent", {
kind: "prompt",
model: "gpt-4o",
tools: [{
type: "azure_ai_search",
azure_ai_search: {
indexes: [{
project_connection_id: connectionId,
index_name: "my-index",
query_type: "simple"
}]
}
}]
});
// Function Tool
const agent = await client.agents.createVersion("func-agent", {
kind: "prompt",
model: "gpt-4o",
tools: [{
type: "function",
function: {
name: "get_weather",
description: "Get weather for a location",
strict: true,
parameters: {
type: "object",
properties: { location: { type: "string" } },
required: ["location"]
}
}
}]
});
// MCP Tool
const agent = await client.agents.createVersion("mcp-agent", {
kind: "prompt",
model: "gpt-4o",
tools: [{
type: "mcp",
server_label: "my-mcp",
server_url: "https://mcp-server.example.com",
require_approval: "always"
}]
});
エージェントの実行
const openAIClient = await client.getOpenAIClient();
// Create conversation
const conversation = await openAIClient.conversations.create({
items: [{ type: "message", role: "user", content: "Hello!" }]
});
// Generate response using agent
const response = await openAIClient.responses.create(
{ conversation: conversation.id },
{ body: { agent: { name: agent.name, type: "agent_reference" } } }
);
// Cleanup
await openAIClient.conversations.delete(conversation.id);
await client.agents.deleteVersion(agent.name, agent.version);
接続
// List all connections
for await (const conn of client.connections.list()) {
console.log(conn.name, conn.type);
}
// Get connection by name
const conn = await client.connections.get("my-connection");
// Get connection with credentials
const connWithCreds = await client.connections.getWithCredentials("my-connection");
// Get default connection by type
const defaultAzureOpenAI = await client.connections.getDefault("AzureOpenAI", true);
デプロイ
// List all deployments
for await (const deployment of client.deployments.list()) {
if (deployment.type === "ModelDeployment") {
console.log(deployment.name, deployment.modelName);
}
}
// Filter by publisher
for await (const d of client.deployments.list({ modelPublisher: "OpenAI" })) {
console.log(d.name);
}
// Get specific deployment
const deployment = await client.deployments.get("gpt-4o");
データセット
// Upload single file
const dataset = await client.datasets.uploadFile(
"my-dataset",
"1.0",
"./data/training.jsonl"
);
// Upload folder
const dataset = await client.datasets.uploadFolder(
"my-dataset",
"2.0",
"./data/documents/"
);
// Get dataset
const ds = await client.datasets.get("my-dataset", "1.0");
// List versions
for await (const version of client.datasets.listVersions("my-dataset")) {
console.log(version);
}
// Delete
await client.datasets.delete("my-dataset", "1.0");
インデックス
import { AzureAISearchIndex } from "@azure/ai-projects";
const indexConfig: AzureAISearchIndex = {
name: "my-index",
type: "AzureSearch",
version: "1",
indexName: "my-index",
connectionName: "search-connection"
};
// Create index
const index = await client.indexes.createOrUpdate("my-index", "1", indexConfig);
// List indexes
for await (const idx of client.indexes.list()) {
console.log(idx.name);
}
// Delete
await client.indexes.delete("my-index", "1");
主な型
import {
AIProjectClient,
AIProjectClientOptionalParams,
Connection,
ModelDeployment,
DatasetVersionUnion,
AzureAISearchIndex
} from "@azure/ai-projects";
ベストプラクティス
- getOpenAIClient() を使用する - 応答、会話、ファイル、ベクトルストアにはこれを使用します
- エージェントをバージョン管理する - 再現可能なエージェント定義には
createVersionを使用します - リソースをクリーンアップする - 完了したらエージェントと会話を削除します
- 接続を使用する - プロジェクト接続から資格情報を取得し、ハードコードしないでください
- デプロイをフィルタリングする - 特定のモデルを見つけるには
modelPublisherフィルターを使用します
使用する場合
このスキルは、概要に記載されているワークフローまたはアクションを実行する場合に適用できます。
制限事項
- このスキルは、タスクが上記の説明の範囲に明確に該当する場合にのみ使用してください。
- 出力を、環境固有の検証、テスト、または専門家によるレビューの代替として扱わないでください。
- 必要な入力、権限、安全上の境界、または成功基準が不足している場合は、作業を中断して確認を求めてください。
コメント
Markdown 対応