次の方法で共有


新しいエージェント開発者エクスペリエンスに移行する

ヒント

Assistants API からエージェントへの移行を自動化するために、移行ツールを使用できます。

Foundry Agent Service は、ビルド、バージョン管理、操作、観察が容易なインテリジェントなエージェントを構築するためのアップグレードされた開発者エクスペリエンスを提供します。 新しいエージェント API では、最新化された SDK、新しいエンタープライズ レベルの機能が導入され、現在使用している ID、ガバナンス、および可観測性の機能が保持されます。

[前提条件]

  • Azure サブスクリプション。 無料で作成できます
  • Microsoft Foundry プロジェクト
  • 使用している言語用の Foundry Agent Service SDK と、認証用の対応する ID パッケージ。 言語のパッケージをインストールし、 az login でサインインするか、 DefaultAzureCredentialを使用します。
pip install "azure-ai-projects>=2.0.0"
  • 移行対象の既存エージェントまたはアシスタントのコード。

次のコードは、このガイド全体で使用されるクライアントを初期化します。

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

# Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
PROJECT_ENDPOINT = "your_project_endpoint"

project = AIProjectClient(
    endpoint=PROJECT_ENDPOINT,
    credential=DefaultAzureCredential(),
)
openai = project.get_openai_client()

エージェントの作成とバージョン管理には project を使用します。 会話や返信には、 openai (またはお使いの言語で同等のもの) を使用します。

主な利点

新しいエージェントには、次の利点があります。

開発者の生産性

  • その他のモデル。 エージェントで、または応答生成呼び出しとして直接、Foundry モデルを使用して応答を生成します。
  • その他の機能。 Web 検索、ファイル検索、コード インタープリター、MCP ツールの呼び出し、イメージの生成、および推論の概要。
  • 最新の API プリミティブ。 以前の Assistants API ではなく Responses API 上に構築されています。
  • バックグラウンド モード。 実行時間の長いツール (イメージ生成など) と永続ストリームのサポート (切断/再接続シナリオをサポート)
  • 将来性を備えています。 新機能とモデルのサポートは、新しいエージェントにのみ追加されます。
  • 新しいエージェントの種類。 プロンプト ベースのワークフロー ベースのエージェント、ワークフロー ベースのエージェント (プレビュー)、およびホストされるエージェント (プレビュー) を作成します。

エンタープライズ対応性

  • Single-tenant storage. 状態を格納し、データをセキュリティで保護するために独自のAzure Cosmos DBを使用するオプションを使用して、シングルテナント ストレージを使用します。
  • セキュリティの強化。 エージェント定義を実行または変更できるユーザーを制御します。
  • 職務の分離。 エージェントを 1 回定義し、さまざまな入力で実行します。
  • 展開可能なエージェント。 エージェントは、個々のエンドポイントとして公開できます。

API の最新化

  • 状態管理が改善されました。 スレッドとメッセージの代わりに会話を使用します。
  • ステートフル コンテキスト。 呼び出し間でコンテキストが自動的に保持されます。
  • Responses API のスーパーセット。 Responses API を基に構築され、さらに多くの機能を追加します。
  • 単一または複数エージェントのワークフロー。 複雑なワークフローのエージェントを簡単にチェーンできます。

主な変更点

次の表は、前のエージェント エクスペリエンスと現在のエージェント エクスペリエンスの間の主な API の変更をまとめたものです。

変更前 クリック後 詳細情報
スレッド数 会話 メッセージだけでなく、アイテムのストリームをサポートします。
Runs Responses 応答は入力項目を送信するか、会話オブジェクトを使用して出力項目を受信します。 ツール呼び出しループは明示的に管理されます。
アシスタント/エージェント エージェント (新規) Foundry モデルの既定では、ステートフル コンテキストを持つエンタープライズ対応のプロンプト、ワークフロー、およびホステッド エージェントのサポート。

エージェント ツールの可用性

次の表は、クラシック エージェントで使用できるエージェント ツールと、新しい Foundry Agent Service を比較したものです。 これを使用して、どのツールが直接引き継がれ、どのツールが変更され、新しいエクスペリエンス専用であるかを特定します。

ツール Foundry (クラシック) Foundry (新規)
エージェント間通信 (A2A) いいえ はい (パブリック プレビュー)
Azure AI Search はい (GA) はい (GA)
Azure Functions はい (GA) いいえ
ブラウザーの自動化 はい (パブリック プレビュー) はい (パブリック プレビュー)
コード インタープリター はい (GA) はい (GA)
コンピューターの使用 はい (パブリック プレビュー) はい (パブリック プレビュー)
接続されたエージェント はい (パブリック プレビュー) いいえ (推奨事項: ワークフローと A2A ツール)
詳細な調査 はい (パブリック プレビュー) いいえ (推奨事項: Web 検索ツールを使用したディープ リサーチ モデル)
ファブリックデータエージェント はい (パブリック プレビュー) はい (パブリック プレビュー)
ファイル検索 はい (GA) はい (GA)
Function はい (GA) はい (GA)
Bing検索による基礎固め はい (GA) はい (GA)
Bingカスタム検索を利用した基盤作り はい (パブリック プレビュー) はい (パブリック プレビュー)
画像生成 いいえ はい (パブリック プレビュー)
MCP はい (パブリック プレビュー) はい (GA)
OpenAPI はい (GA) はい (GA)
SharePointグラウンド設定 はい (パブリック プレビュー) はい (パブリック プレビュー)
Web Search いいえ はい (パブリック プレビュー)

Important

新しい API では、会話と応答 API は OpenAI クライアント (または同等の言語) を使用します。 Pythonで、project.get_openai_client() を呼び出します。 C# では、 projectClient.OpenAI.GetProjectResponsesClientForAgent()を使用します。 JavaScript で、 projectClient.getOpenAIClient()を呼び出します。 Javaでは、AgentsClientBuilder を使用して、ResponsesClientをビルドします。 エージェントの作成とバージョン管理は 、プロジェクト クライアントに残ります。 各セクションの例では、使用するクライアントを示します。

スレッドを会話に移行する

スレッドはサーバー側にメッセージを格納しました。 会話には、メッセージ、ツール呼び出し、ツール出力、その他のデータなどのアイテムを格納できます。

リクエスト

次の例では、スレッドの作成 (前) と会話の作成 (現在) を比較します。 現在のアプローチでは、 project.get_openai_client()から取得した OpenAI クライアントを使用します。

前 - スレッド

thread = client.agents.threads.create( 
     messages=[{"role": "user", "content": "Tell me a one line funny story about unicorns"}], 
     metadata={"agent": "my-awesome-agent"}, 
) 

現在の会話

conversation = openai.conversations.create(
    items=[
        {
            "type": "message",
            "role": "user",
            "content": "Tell me a one line funny "
                       "story about unicorns",
        }
    ],
    metadata={"agent": "my-awesome-agent"},
)

Responses

JSON 応答は、スレッド オブジェクトと会話オブジェクトの構造上の違いを示しています。

前 - スレッド

{ 
  "id": "thread_1234abcd",  
  "object": "thread",  
  "created_at": 1762217858,  
  "metadata": {"agent": "my-awesome-agent"},  
  "tool_resources": {} 
} 

現在の会話

{ 
  "id":"conv_1234abcd", 
  "created_at":1762217961, 
  "metadata":{"agent":"my-awesome-agent"}, 
  "object":"conversation" 
} 

既存の会話にアイテムを追加する

会話を作成したら、 conversations.items.create() を使用して後続のメッセージを追加します。 このパターンは、スレッドへのメッセージの追加を client.agents.messages.create()に置き換えます。

前 - スレッドにメッセージを追加する

message = client.agents.messages.create(
    thread_id=thread.id,
    role="user",
    content="Follow-up question about the same topic",
)

現在 - 会話にアイテムを追加する

openai.conversations.items.create(
    conversation_id=conversation.id,
    items=[
        {
            "type": "message",
            "role": "user",
            "content": "Follow-up question "
                       "about the same topic",
        }
    ],
)

実行を応答に移行する

実行は、スレッドに対して実行される非同期プロセスでした。 応答の方が簡単です。実行する入力項目のセットを提供し、出力項目の一覧を取得します。 応答は単独で使用することも、コンテキストを格納するための会話オブジェクトと共に使用することもできます。 応答 API は OpenAI クライアントを使用します。

リクエスト

次の例では、エージェント ロジックを呼び出す方法を比較します。 以前のアプローチでは、非同期実行にポーリングを利用しました。 現在のアプローチでは、OpenAI クライアントで responses.create() が呼び出されます。

以前 - 実行

thread_id = "thread_abcd1234" 
assistant_id = "asst_efgh5678" 
run = project_client.agents.runs.create( 
  thread_id=thread_id,  
  agent_id=assistant_id, 
  additional_instructions="Please address the user as Jane Doe. The user has a premium account" 
) 
while run.status in ("queued", "in_progress"): 
  time.sleep(1) 
  run = project_client.agents.runs.get(thread_id=thread_id, run_id=run.id) 

現在の応答

conversation_id = "conv_11112222AAAABBBB"

response = openai.responses.create(
    input="Hi, Agent! Draw a graph for a line "
          "with a slope of 4 and "
          "y-intercept of 9.",
    conversation=conversation_id,
    extra_body={
        "agent_reference": {
            "name": "my-agent",
            "type": "agent_reference",
        }
    },
)

Responses

以前 - 実行

{
  "id": "run_xyz",
  "object": "thread.run",
  "created_at": 1762218810,
  "assistant_id": "asst_efgh5678",
  "thread_id": "thread_abcd1234",
  "status": "completed",
  "started_at": 1762218810,
  "expires_at": null,
  "cancelled_at": null,
  "failed_at": null,
  "completed_at": 1762218812,
  "required_action": null,
  "last_error": null,
  "model": "gpt-4.1",
  "instructions": "You politely help with math questions. Use the Code Interpreter tool when asked to visualize numbers. Please address the user as Jane Doe. The user has a premium account",
  "tools": [
    {
      "type": "code_interpreter"
    }
  ],
  "tool_resources": {},
  "metadata": {},
  "temperature": 1.0,
  "top_p": 1.0,
  "max_completion_tokens": null,
  "max_prompt_tokens": null,
  "truncation_strategy": {
    "type": "auto",
    "last_messages": null
  },
  "incomplete_details": null,
  "usage": {
    "prompt_tokens": 1216,
    "completion_tokens": 76,
    "total_tokens": 1292,
    "prompt_token_details": {
      "cached_tokens": 0
    }
  },
  "response_format": "auto",
  "tool_choice": "auto",
  "parallel_tool_calls": true
}

現在の応答

{
  "id": "resp_3483e9c8dda4f165006909550333588190afc76a645a0e877a",
  "created_at": 1762219267.0,
  "error": null,
  "incomplete_details": null,
  "instructions": null,
  "metadata": {
    "x-ms-telemetry-agent-kind": "",
    "x-ms-telemetry-user-agent": "OpenAI/Python 2.4.0",
    "x-ms-telemetry-response-start-time": "2025-11-04T01:21:06.5346780+00:00"
  },
  "model": "gpt-4.1",
  "object": "response",
  "output": [
    {
      "id": "msg_3483e9c8dda4f1650069095503abf881909917865574cddf2c",
      "content": [
        {
          "annotations": [],
          "text": "Of course! Here's a simple plot for the line with a rate of change of 4 and a y-intercept of 9.\\n\\nThe equation of the line is:\\n\\n\\\\[ y = 4x + 9 \\\\]\\n\\nLet's draw a graph for it:\\n\\n---\\n\\n```plaintext\\n  |\\n20|                     *\\n  |                  *\\n  |               *\\n  |            *\\n10|         *\\n  |      *\\n  |   *\\n  |*\\n  +---------------------------\\n   -2 -1  0  1  2  3\\n```\\n\\n**Key points:**\\n- The y-intercept is **9**, so at \\\\(x = 0\\\\), \\\\(y = 9\\\\) (point: (0,9))\\n- For each step right (increase in x), y goes up 4 units (rate of change \\\\(m = 4\\\\))\\n  - For \\\\(x = 1\\\\): \\\\(y = 4(1) + 9 = 13\\\\) (point: (1,13))\\n  - For \\\\(x = -1\\\\): \\\\(y = 4(-1) + 9 = 5\\\\) (point: (-1,5))\\n\\nIf you'd like a precise graph or want to visualize it interactively, let me know!",

          "type": "output_text",
          "logprobs": []
        }
      ],
      "role": "assistant",
      "status": "completed",
      "type": "message"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "tools": [],
  "top_p": 1.0,
  "background": false,
  "conversation": {
    "id": "conv_3483e9c8dda4f16500GwcAgtdWlSmbMPzYLjWvDjiSe6LSFcC6"
  },
  "max_output_tokens": null,
  "max_tool_calls": null,
  "previous_response_id": null,
  "prompt": null,
  "prompt_cache_key": null,
  "reasoning": {
    "effort": null,
    "generate_summary": null,
    "summary": null
  },
  "safety_identifier": null,
  "service_tier": "default",
  "status": "completed",
  "text": {
    "format": {
      "type": "text"
    },
    "verbosity": "medium"
  },
  "top_logprobs": 0,
  "truncation": "disabled",
  "usage": {
    "input_tokens": 45,
    "input_tokens_details": {
      "cached_tokens": 0
    },
    "output_tokens": 264,
    "output_tokens_details": {
      "reasoning_tokens": 0
    },
    "total_tokens": 309
  },
  "user": null,
  "content_filters": null,
  "store": true
}

クラシック エージェントを新しいエージェントに移行する

以前のバージョンの SDK の client.agents.create_agent() メソッドを使用する場合は、 client.agents.create_version()に移行します。 この新しいメソッドでは、明示的な kindmodel、および instructions フィールドを含む構造化エージェント定義が導入されています。

リクエスト

前の

agent = client.agents.create_agent( 
    model="gpt-4.1", 
    name="my-agent",  # Name of the agent 
    instructions="You politely help with math questions. Use the Code Interpreter tool when asked to visualize numbers.",  # Instructions for the agent 
    tools=code_interpreter.definitions,  # Attach the tool 
) 

現在

from azure.ai.projects.models import (
    CodeInterpreterTool,
    PromptAgentDefinition,
)

agent = project.agents.create_version(
    agent_name="my-agent",
    definition=PromptAgentDefinition(
        model="gpt-4.1",
        instructions=(
            "You politely help with math "
            "questions. Use the Code "
            "Interpreter tool when asked to "
            "visualize numbers."
        ),
        tools=[CodeInterpreterTool()],
    ),
)

Responses

次の JSON の例では、前のエージェント作成メソッドと現在のエージェント作成メソッドによって返される応答オブジェクトを比較します。

前の

{ 
  'id': 'asst_AVKrdr2KJthDnZiJ51nca1jy', 
  'object': 'assistant', 
  'created_at': 1762218496, 
  'name': 'my-agent', 
  'description': None, 
  'model': 'gpt-4.1', 
  'instructions': 'You politely help with math questions. Use the Code Interpreter tool when asked to visualize numbers.', 
  'tools': [ 
    { 
      'type': 'code_interpreter' 
    } 
  ], 
  'top_p': 1.0, 
  'temperature': 1.0, 
  'tool_resources': { 
    'code_interpreter': { 
      'file_ids': [      
      ] 
    } 
  }, 
  'metadata': { 
  }, 
  'response_format': 'auto' 
} 

現在

{
  "metadata": {},
  "object": "agent.version",
  "id": "code-agent:1",
  "name": "code-agent",
  "version": "1",
  "description": "Agent with code interpreter",
  "created_at": 1772045947,
  "definition": {
    "kind": "prompt",
    "model": "gpt-4.1",
    "instructions": "You politely help with math questions. Use the Code Interpreter tool when asked to visualize numbers.",
    "tools": [
      {
        "type": "code_interpreter"
      }
    ]
  }
}

アシスタントを新しいエージェントに移行する

コードで OpenAI Assistants API (client.beta.assistants.create()) を使用する場合は、 client.agents.create_version()を使用して Foundry Agent Service に移行します。 次の例は、構造の違いを示しています。

前へ - アシスタントたち

assistant = client.beta.assistants.create( 
    model="gpt-4.1", 
    name="my-assistant", 
    instructions="You politely help with math questions. Use the Code Interpreter tool when asked to visualize numbers.",  # Instructions for the agent 
    tools=[{"type": "code_interpreter"}], 
) 

現在のエージェント - 新しいエージェント

from azure.ai.projects.models import (
    CodeInterpreterTool,
    PromptAgentDefinition,
)

agent = project.agents.create_version(
    agent_name="my-agent",
    definition=PromptAgentDefinition(
        model="gpt-4.1",
        instructions=(
            "You politely help with math "
            "questions. Use the Code "
            "Interpreter tool when asked to "
            "visualize numbers."
        ),
        tools=[CodeInterpreterTool()],
    ),
)

移行ツールを実行する

migration ツールは、エージェントとアシスタントの移行の自動化に役立つGitHubで使用できます。 このツールは、エージェント定義、スレッド作成、メッセージ作成、実行作成などのコードコンストラクトを移行します。 過去の実行、スレッド、メッセージなどの状態データは移行されません。 移行後、新しいコードを実行すると、新しい状態データが更新された形式で作成されます。

次の例は、前後の完全な比較を示しています。 現在のコードでは、エージェントの作成に project と会話と応答の openai の両方が使用されていることに注意してください。

前の

agent = project_client.agents.create_agent( 
    model="gpt-4.1", 
    name="my-agent", 
    instructions="You politely help with math questions. Use the Code Interpreter tool when asked to visualize numbers.",  # Instructions for the agent 
    tools=[{"type": "code_interpreter"}] 
) 
thread = project_client.agents.threads.create() 
message = project_client.agents.messages.create( 
    thread_id=thread.id, 
    role="user",  # Role of the message sender 
    content="Hi, Agent! Draw a graph for a line with a rate of change of 4 and y-intercept of 9.",  # Message content 
) 
run = project_client.agents.runs.create_and_process( 
    thread_id=thread.id, 
    agent_id=agent.id, 
    additional_instructions="Please address the user as Jane Doe. The user has a premium account", 
) 
messages = project_client.agents.messages.list(thread_id=thread.id) 
for message in messages: 
    print(f"Role: {message.role}, Content: {message.content}") 

現在

from azure.ai.projects.models import (
    CodeInterpreterTool,
    PromptAgentDefinition,
)

# Create the agent
agent = project.agents.create_version(
    agent_name="my-agent",
    definition=PromptAgentDefinition(
        model="gpt-4.1",
        instructions=(
            "You politely help with math "
            "questions. Use the Code "
            "Interpreter tool when asked "
            "to visualize numbers."
        ),
        tools=[CodeInterpreterTool()],
    ),
)

# Create a conversation with initial message
conversation = openai.conversations.create(
    items=[
        {
            "type": "message",
            "role": "user",
            "content": (
                "Hi, Agent! Draw a graph "
                "for a line with a rate "
                "of change of 4 and "
                "y-intercept of 9."
            ),
        }
    ],
)

# Send a response with the agent
response = openai.responses.create(
    conversation=conversation.id,
    extra_body={
        "agent_reference": {
            "name": agent.name,
            "type": "agent_reference",
        }
    },
    input=(
        "Please address the user as "
        "Jane Doe. The user has a "
        "premium account"
    ),
)

移行を検証する

コードを移行したら、すべてが正しく動作することを確認します。

  1. 更新されたコードを実行 し、エラーなしで実行されることを確認します。
  2. create_version()フィールドとidフィールドを持つオブジェクトを返していることを確認して、エージェントの作成を確認します。
  3. 会話を 作成し、応答を送信し、出力項目が返されることを確認して、会話をテストします。
  4. 同じ会話に複数の応答を送信し、エージェントが以前のメッセージを記憶していることを確認して、コンテキストの保持を確認します。

一般的な問題のトラブルシューティング

症状 原因 解決策
Python: AttributeError: 'AIProjectClient' has no attribute 'conversations' OpenAI クライアントではなく、プロジェクト クライアントで conversations.create() を呼び出しました。 project.get_openai_client()を使用して OpenAI クライアントを取得し、openai.conversations.create()を呼び出します。
C#: Azure.AI.Projects.OpenAI 名前空間が見つかりません Azure.AI.Projects.OpenAI NuGet パッケージがありません。 Azure.AI.Projects.OpenAIAzure.AI.Projects と共にインストールします。 両方のパッケージが必要です。
JavaScript: getOpenAIClient is not a function 以前のバージョンの @azure/ai-projectsを使用しています。 @azure/ai-projects@2.0.0-beta.5以降に更新する: npm install @azure/ai-projects@2.0.0-beta.5
Java: AgentsClientBuilder 解決できません azure-ai-agents Maven の依存関係が見つからないか、古くなっています。 com.azure:azure-ai-agents:2.0.0-beta.2の依存関係にpom.xmlを追加します。
create_agent() は削除されます 以前のバージョンの SDK では、v2.0.0 で削除された create_agent()が使用されていました。 create_version() (Python/JS) または CreateAgentVersionAsync() (C#) または createAgentVersion() (Java) に置き換え、PromptAgentDefinition オブジェクトを渡します。
古いスレッド データは使用できません 移行ツールでは、状態データ (過去の実行、スレッド、またはメッセージ) は移行されません。 移行後に新しい会話を開始します。 履歴データは、非推奨になるまで前の API を介してアクセスできます。
responses.create() モデル エラーが発生する モデル名が正しくないか、リージョンで使用できない可能性があります。 Foundry プロジェクトのモデル名を確認し、 モデル リージョンの可用性を確認します