このレッスンでは、本コースのコードサンプルの実行方法を説明します。
リポジトリをクローンする前に、セットアップのサポートやコースに関する質問、他の学習者との交流のためにAI Agents For Beginners Discord チャンネルに参加してください。
開始するには、GitHub リポジトリをクローンまたはフォークしてください。これにより、コードを実行、テスト、調整できる自分専用のコース教材のバージョンが作成されます!
This can be done by clicking the link to リポジトリをフォークする
You should now have your own forked version of this course in the following link:

リポジトリ全体は、履歴やすべてのファイルを完全にダウンロードすると大きくなることがあります(約3 GB)。ワークショップに参加するだけ、またはいくつかのレッスンフォルダだけが必要な場合、浅いクローン(またはスパースクローン)は履歴を切り詰めたり、blob をスキップすることでその大部分のダウンロードを回避します。
Replace <your-username> in the below commands with your fork URL (or the upstream URL if you prefer).
To clone only the latest commit history (small download):
git clone --depth 1 https://github.com/<your-username>/ai-agents-for-beginners.git
To clone a specific branch:
git clone --depth 1 --branch <branch-name> https://github.com/<your-username>/ai-agents-for-beginners.git
This uses partial clone and sparse-checkout (requires Git 2.25+ and recommended modern Git with partial clone support):
git clone --depth 1 --filter=blob:none --sparse https://github.com/<your-username>/ai-agents-for-beginners.git
Traverse into the repo folder:
cd ai-agents-for-beginners
Then specify which folders you want (example below shows two folders):
git sparse-checkout set 00-course-setup 01-intro-to-ai-agents
After cloning and verifying the files, if you only need files and want to free space (no git history), please delete the repository metadata (💀irreversible — you will lose all Git functionality: no commits, pulls, pushes, or history access).
# zsh または bash
rm -rf .git
# パワーシェル Remove-Item -Recurse -Force .git
Create a new Codespace for this repo via the GitHub の UI.
In the terminal of the newly created codespace, run one of the shallow/sparse clone commands above to bring only the lesson folders you need into the Codespace workspace.
Optional: after cloning inside Codespaces, remove .git to reclaim extra space (see removal commands above).
Note: If you prefer to open the repo directly in Codespaces (without an extra clone), be aware Codespaces will construct the devcontainer environment and may still provision more than you need. Cloning a shallow copy inside a fresh Codespace gives you more control over disk usage.
This course offers a series of Jupyter Notebooks that you can run with to get hands-on experience building AI Agents.
The code samples use Microsoft Agent Framework (MAF) with the AzureAIProjectAgentProvider, which connects to Azure AI Agent Service V2 (the Responses API) through Microsoft Foundry.
All Python notebooks are labelled *-python-agent-framework.ipynb.
Python 3.12+
注意: Python 3.12 をインストールしていない場合は、インストールしてください。次に、requirements.txt に記載された正しいバージョンがインストールされるように python3.12 を使って仮想環境を作成してください。
例
Create Python venv directory:
python -m venv venv
Then activate venv environment for:
# zsh/bash
source venv/bin/activate
# Command Prompt for Windows venv\Scripts\activate
.NET 10+: For the sample codes using .NET, ensure you install .NET 10 SDK or later. Then, check your installed .NET SDK version:
dotnet --list-sdks
Azure CLI — 認証に必要です。インストールは aka.ms/installazurecli から行ってください。
Azure Subscription — Microsoft Foundry と Azure AI Agent Service へのアクセスに必要です。
Microsoft Foundry Project — デプロイされたモデル(例: gpt-4o)を持つプロジェクト。以下の Step 1 を参照してください。
We have included a requirements.txt file in the root of this repository that contains all the required Python packages to run the code samples.
You can install them by running the following command in your terminal at the root of the repository:
pip install -r requirements.txt
We recommend creating a Python virtual environment to avoid any conflicts and issues.
Make sure that you are using the right version of Python in VSCode.
ノートブックを実行するには、デプロイされたモデルを持つ Azure AI Foundry のハブとプロジェクトが必要です。
gpt-4o)をデプロイします。Microsoft Foundry ポータルのプロジェクトから:

gpt-4o)を確認します。All notebooks use AzureCliCredential for authentication — no API keys to manage. This requires you to be signed in via the Azure CLI.
Azure CLI をインストール していない場合はインストールしてください: aka.ms/installazurecli
サインイン は以下を実行します:
az login
Or if you're in a remote/Codespace environment without a browser:
az login --use-device-code
サブスクリプションを選択(プロンプトが表示された場合)— Foundry プロジェクトを含むサブスクリプションを選択してください。
サインインされていることを確認:
az account show
なぜ
az loginなのか? ノートブックはazure-identityパッケージのAzureCliCredentialを使用して認証します。つまり、Azure CLI セッションが認証情報を提供するため、.envファイルに API キーやシークレットを置く必要がありません。これは セキュリティ上のベストプラクティス です。
Copy the example file:
# zsh と bash
cp .env.example .env
# PowerShell(パワーシェル) Copy-Item .env.example .env
Open .env and fill in these two values:
AZURE_AI_PROJECT_ENDPOINT=https://<your-project>.services.ai.azure.com/api/projects/<your-project-id> AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4o
| 変数 | 参照先 |
|---|---|
AZURE_AI_PROJECT_ENDPOINT | Foundry ポータル → あなたのプロジェクト → Overview ページ |
AZURE_AI_MODEL_DEPLOYMENT_NAME | Foundry ポータル → Models + Endpoints → デプロイしたモデルの名前 |
ほとんどのレッスンはこれで完了です!ノートブックは az login セッションを通じて自動的に認証されます。
pip install -r requirements.txt
仮想環境内でこれを実行することをお勧めします。
Lesson 5 uses Azure AI Search for retrieval-augmented generation. If you plan to run that lesson, add these variables to your .env file:
| 変数 | 参照先 |
|---|---|
AZURE_SEARCH_SERVICE_ENDPOINT | Azure ポータル → あなたの Azure AI Search リソース → Overview → URL |
AZURE_SEARCH_API_KEY | Azure ポータル → あなたの Azure AI Search リソース → Settings → Keys → プライマリ管理キー |
一部のノートブック(レッスン6と8)は Azure AI Foundry の代わりに GitHub Models を使用します。これらのサンプルを実行する場合は、以下の変数を .env ファイルに追加してください:
| 変数 | 参照先 |
|---|---|
GITHUB_TOKEN | GitHub → Settings → Developer settings → Personal access tokens |
GITHUB_ENDPOINT | 使用する: https://models.inference.ai.azure.com (default value) |
GITHUB_MODEL_ID | 使用するモデル名(例: gpt-4o-mini) |
レッスン8 の条件付きワークフローノートブックは、Azure AI Foundry 経由で Bing grounding を使用します。このサンプルを実行する場合は、次の変数を .env ファイルに追加してください:
| 変数 | 参照先 |
|---|---|
BING_CONNECTION_ID | Azure AI Foundry ポータル → あなたのプロジェクト → Management → Connected resources → あなたの Bing 接続 → 接続 ID をコピー |
macOS を使用していて次のようなエラーが発生した場合:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain
これは、macOS 上の Python でシステムの SSL 証明書が自動的に信頼されない既知の問題です。以下の解決策を順に試してください:
オプション 1: Python の Install Certificates スクリプトを実行する(推奨)
# インストールされている Python バージョン(例: 3.12 または 3.13)に合わせて 3.XX を置き換えてください:
/Applications/Python\ 3.XX/Install\ Certificates.command
オプション 2: ノートブックで connection_verify=False を使用する(GitHub Models ノートブックのみ)
Lesson 6 のノートブック(06-building-trustworthy-agents/code_samples/06-system-message-framework.ipynb)には、コメントアウトされた回避策が既に含まれています。クライアントを作成するときに connection_verify=False のコメントを外してください:
client = ChatCompletionsClient(
endpoint=endpoint,
credential=AzureKeyCredential(token),
connection_verify=False, # 証明書エラーが発生した場合は、SSL検証を無効にしてください
)
⚠️ 警告: SSL 検証を無効にする(
connection_verify=False)と、証明書検証をスキップするためセキュリティが低下します。これは開発環境での一時的な回避策としてのみ使用し、本番では絶対に使用しないでください。
オプション 3: truststore をインストールして使用する
pip install truststore
次に、ネットワーク呼び出しを行う前にノートブックやスクリプトの先頭に以下を追加します:
import truststore
truststore.inject_into_ssl()
If you have any issues running this setup, hop into our Azure AI コミュニティ Discord or Issue を作成する.
You are now ready to run the code for this course. Happy learning more about the world of AI Agents!
免責事項: この文書は AI 翻訳サービス「Co-op Translator」(https://github.com/Azure/co-op-translator)を使用して翻訳されました。正確性には努めておりますが、自動翻訳には誤りや不正確な表現が含まれる可能性があります。原文(原言語で作成された文書)が正式な情報源とみなされます。重要な内容については、専門の翻訳者による人間翻訳を推奨します。本翻訳の利用により生じたいかなる誤解や解釈の相違についても責任を負いかねます。