Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions 09-metacognition/code_samples/09-python-agent-framework.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"metadata": {},
"outputs": [],
"source": [
"! pip install agent-framework azure-ai-projects azure-identity -q"
"%pip install agent-framework azure-ai-projects azure-identity python-dotenv -q"
]
},
{
Expand All @@ -40,15 +40,32 @@
"outputs": [],
"source": [
"import logging\n",
"logging.getLogger(\"agent_framework.azure\").setLevel(logging.ERROR)\n",
"logging.getLogger(\"agent_framework.foundry\").setLevel(logging.ERROR)\n",
"\n",
"import os\n",
"import asyncio\n",
"import dotenv\n",
"from typing import Annotated\n",
"\n",
"from agent_framework import tool\n",
"from agent_framework.azure import AzureAIProjectAgentProvider\n",
"from azure.identity import AzureCliCredential"
"from agent_framework.foundry import FoundryChatClient\n",
"from azure.identity import DefaultAzureCredential\n",
"\n",
"dotenv.load_dotenv()\n",
"\n",
"endpoint = os.getenv(\"AZURE_AI_PROJECT_ENDPOINT\")\n",
"deployment_name = os.getenv(\"AZURE_AI_MODEL_DEPLOYMENT_NAME\")\n",
"\n",
"missing = [k for k, v in {\n",
" \"AZURE_AI_PROJECT_ENDPOINT\": endpoint,\n",
" \"AZURE_AI_MODEL_DEPLOYMENT_NAME\": deployment_name\n",
"}.items() if not v]\n",
"\n",
"if missing:\n",
" raise ValueError(\n",
" f\"Missing required environment variables: {', '.join(missing)}. \"\n",
" \"Please set them as environment variables (e.g., in your .env file or shell environment).\"\n",
" )"
]
},
{
Expand All @@ -58,8 +75,12 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"provider = AzureAIProjectAgentProvider(credential=AzureCliCredential())"
"# Create the Azure AI Foundry client\n",
"client = FoundryChatClient(\n",
" project_endpoint=endpoint,\n",
" model=deployment_name,\n",
" credential=DefaultAzureCredential()\n",
")"
]
},
{
Expand Down Expand Up @@ -150,7 +171,7 @@
"metadata": {},
"outputs": [],
"source": [
"agent = await provider.create_agent(\n",
"agent = client.as_agent(\n",
" tools=[get_flight_times, get_flight_times_backup],\n",
" name=\"FlightBookingAgent\",\n",
" instructions=\"\"\"You are a flight booking agent with self-reflection capabilities.\n",
Expand Down Expand Up @@ -198,7 +219,7 @@
"metadata": {},
"outputs": [],
"source": [
"evaluation_agent = await provider.create_agent(\n",
"evaluation_agent = client.as_agent(\n",
" tools=[get_flight_times, get_flight_times_backup],\n",
" name=\"ResponseEvaluator\",\n",
" instructions=\"\"\"You are a quality evaluator for travel agent responses.\n",
Expand Down Expand Up @@ -253,7 +274,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
"version": "3.12.13"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"metadata": {},
"outputs": [],
"source": [
"! pip install agent-framework azure-ai-projects azure-identity -q"
"%pip install agent-framework azure-ai-projects azure-identity python-dotenv -q"
]
},
{
Expand All @@ -40,15 +40,32 @@
"outputs": [],
"source": [
"import logging\n",
"logging.getLogger(\"agent_framework.azure\").setLevel(logging.ERROR)\n",
"logging.getLogger(\"agent_framework.foundry\").setLevel(logging.ERROR)\n",
"\n",
"import os\n",
"import asyncio\n",
"import dotenv\n",
"from typing import Annotated\n",
"\n",
"from agent_framework import tool\n",
"from agent_framework.azure import AzureAIProjectAgentProvider\n",
"from azure.identity import AzureCliCredential"
"from agent_framework.foundry import FoundryChatClient\n",
"from azure.identity import DefaultAzureCredential\n",
"\n",
"dotenv.load_dotenv()\n",
"\n",
"endpoint = os.getenv(\"AZURE_AI_PROJECT_ENDPOINT\")\n",
"deployment_name = os.getenv(\"AZURE_AI_MODEL_DEPLOYMENT_NAME\")\n",
"\n",
"missing = [k for k, v in {\n",
" \"AZURE_AI_PROJECT_ENDPOINT\": endpoint,\n",
" \"AZURE_AI_MODEL_DEPLOYMENT_NAME\": deployment_name\n",
"}.items() if not v]\n",
"\n",
"if missing:\n",
" raise ValueError(\n",
" f\"Missing required environment variables: {', '.join(missing)}. \"\n",
" \"Please set them as environment variables (e.g., in your .env file or shell environment).\"\n",
" )"
]
},
{
Expand All @@ -58,8 +75,12 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"provider = AzureAIProjectAgentProvider(credential=AzureCliCredential())"
"# Create the Azure AI Foundry client\n",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following standard industry practice and Microsoft's own convention in this repository, code comments and error messages are intentionally kept in English even in translated notebooks. Translating runtime messages and code comments would be inconsistent with the rest of the codebase.

"client = FoundryChatClient(\n",
" project_endpoint=endpoint,\n",
" model=deployment_name,\n",
" credential=DefaultAzureCredential()\n",
")"
]
},
{
Expand Down Expand Up @@ -150,7 +171,7 @@
"metadata": {},
"outputs": [],
"source": [
"agent = await provider.create_agent(\n",
"agent = client.as_agent(\n",
" tools=[get_flight_times, get_flight_times_backup],\n",
" name=\"FlightBookingAgent\",\n",
" instructions=\"\"\"You are a flight booking agent with self-reflection capabilities.\n",
Expand Down Expand Up @@ -198,7 +219,7 @@
"metadata": {},
"outputs": [],
"source": [
"evaluation_agent = await provider.create_agent(\n",
"evaluation_agent = client.as_agent(\n",
" tools=[get_flight_times, get_flight_times_backup],\n",
" name=\"ResponseEvaluator\",\n",
" instructions=\"\"\"You are a quality evaluator for travel agent responses.\n",
Expand Down Expand Up @@ -240,7 +261,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n\n<!-- CO-OP TRANSLATOR DISCLAIMER START -->\n**Aviso Legal**:\nEste documento ha sido traducido utilizando el servicio de traducción automática [Co-op Translator](https://github.com/Azure/co-op-translator). Aunque nos esforzamos por la precisión, tenga en cuenta que las traducciones automáticas pueden contener errores o inexactitudes. El documento original en su idioma nativo debe considerarse la fuente autorizada. Para información crítica, se recomienda la traducción profesional realizada por humanos. No nos hacemos responsables por malentendidos o interpretaciones erróneas que puedan derivarse del uso de esta traducción.\n<!-- CO-OP TRANSLATOR DISCLAIMER END -->\n"
"---\n",
"\n",
"<!-- CO-OP TRANSLATOR DISCLAIMER START -->\n",
"**Aviso Legal**:\n",
"Este documento ha sido traducido utilizando el servicio de traducción automática [Co-op Translator](https://github.com/Azure/co-op-translator). Aunque nos esforzamos por la precisión, tenga en cuenta que las traducciones automáticas pueden contener errores o inexactitudes. El documento original en su idioma nativo debe considerarse la fuente autorizada. Para información crítica, se recomienda la traducción profesional realizada por humanos. No nos hacemos responsables por malentendidos o interpretaciones erróneas que puedan derivarse del uso de esta traducción.\n",
"<!-- CO-OP TRANSLATOR DISCLAIMER END -->\n"
]
}
],
Expand All @@ -260,9 +286,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
"version": "3.12.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Loading