404 lines
25 KiB
Plaintext
404 lines
25 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b8c57858",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Azure AI ഏജന്റുകൾ മോഡൽ കോൺടെക്സ്റ്റ് പ്രോട്ടോക്കോൾ (MCP) പിന്തുണയോടെ - Python\n",
|
|
"\n",
|
|
"ഈ നോട്ട്ബുക്ക് Python-ൽ മോഡൽ കോൺടെക്സ്റ്റ് പ്രോട്ടോക്കോൾ (MCP) ടൂളുകളുമായി Azure AI ഏജന്റുകൾ എങ്ങനെ ഉപയോഗിക്കാമെന്ന് കാണിക്കുന്നു. കീലെസ് ഓതന്റിക്കേഷൻ ഉപയോഗിച്ച് മെച്ചപ്പെട്ട കഴിവുകൾക്കായി Microsoft Learn പോലുള്ള ബാഹ്യ MCP സർവറുകൾ പ്രയോജനപ്പെടുത്താൻ കഴിയുന്ന ബുദ്ധിമുട്ടുള്ള ഏജന്റ് എങ്ങനെ സൃഷ്ടിക്കാമെന്ന് ഇത് കാണിക്കുന്നു.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "2e6e4234",
|
|
"metadata": {},
|
|
"source": [
|
|
"## ആവശ്യമായ Python പാക്കേജുകൾ ഇൻസ്റ്റാൾ ചെയ്യുക\n",
|
|
"\n",
|
|
"ആദ്യം, ആവശ്യമായ Python പാക്കേജുകൾ ഇൻസ്റ്റാൾ ചെയ്യേണ്ടതാണ്:\n",
|
|
"- **azure-ai-projects**: കോർ Azure AI Projects SDK\n",
|
|
"- **azure-ai-agents**: ഏജന്റുകൾ സൃഷ്ടിക്കുകയും നിയന്ത്രിക്കുകയും ചെയ്യുന്നതിനുള്ള Azure AI Agents SDK\n",
|
|
"- **azure-identity**: DefaultAzureCredential ഉപയോഗിച്ച് കീലെസ് ഓതന്റിക്കേഷൻ നൽകുന്നു\n",
|
|
"- **mcp**: Python-ക്കായി മോഡൽ കോൺടെക്സ്റ്റ് പ്രോട്ടോക്കോൾ നടപ്പാക്കൽ\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "6a2e9a05",
|
|
"metadata": {},
|
|
"source": [
|
|
"## കീലെസ് ഓതന്റിക്കേഷൻ ഗുണങ്ങൾ\n",
|
|
"\n",
|
|
"ഈ നോട്ട്ബുക്ക് **കീലെസ് ഓതന്റിക്കേഷൻ** പ്രദർശിപ്പിക്കുന്നു, ഇത് നിരവധി ഗുണങ്ങൾ നൽകുന്നു:\n",
|
|
"- ✅ **മാനേജ് ചെയ്യേണ്ട API കീകൾ ഇല്ല** - Azure ഐഡന്റിറ്റി അടിസ്ഥാനമാക്കിയ ഓതന്റിക്കേഷൻ ഉപയോഗിക്കുന്നു\n",
|
|
"- ✅ **ഉയർന്ന സുരക്ഷ** - കോഡ് അല്ലെങ്കിൽ കോൺഫിഗറേഷൻ ഫയലുകളിൽ രഹസ്യങ്ങൾ സൂക്ഷിക്കാറില്ല\n",
|
|
"- ✅ **സ്വയം ക്രെഡൻഷ്യൽ റൊട്ടേഷൻ** - ക്രെഡൻഷ്യൽ ലൈഫ്സൈക്കിൾ മാനേജ്മെന്റ് Azure കൈകാര്യം ചെയ്യുന്നു\n",
|
|
"- ✅ **റോൾ അടിസ്ഥാന ആക്സസ് നിയന്ത്രണം** - സൂക്ഷ്മ അനുമതികൾക്കായി Azure RBAC ഉപയോഗിക്കുന്നു\n",
|
|
"- ✅ **ബഹുമുഖ പരിസ്ഥിതി പിന്തുണ** - വികസനവും പ്രൊഡക്ഷനും ഇടയിൽ സുതാര്യമായി പ്രവർത്തിക്കുന്നു\n",
|
|
"\n",
|
|
"`DefaultAzureCredential` സ്വയം ലഭ്യമായ മികച്ച ക്രെഡൻഷ്യൽ ഉറവിടം തിരഞ്ഞെടുക്കുന്നു:\n",
|
|
"1. **Managed Identity** (Azure-യിൽ പ്രവർത്തിക്കുമ്പോൾ)\n",
|
|
"2. **Azure CLI** ക്രെഡൻഷ്യലുകൾ (പ്രാദേശിക വികസന സമയത്ത്)\n",
|
|
"3. **Visual Studio** ക്രെഡൻഷ്യലുകൾ\n",
|
|
"4. **പരിസ്ഥിതി വേരിയബിളുകൾ** (കോണ്ഫിഗർ ചെയ്തിട്ടുണ്ടെങ്കിൽ)\n",
|
|
"5. **ഇന്ററാക്ടീവ് ബ്രൗസർ** ഓതന്റിക്കേഷൻ (ഫോൾബാക്കായി)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "43efa94d",
|
|
"metadata": {},
|
|
"source": [
|
|
"## കീലെസ് ഓതന്റിക്കേഷൻ സെറ്റപ്പ്\n",
|
|
"\n",
|
|
"**കീലെസ് ഓതന്റിക്കേഷനുള്ള മുൻകൂർ ആവശ്യങ്ങൾ:**\n",
|
|
"\n",
|
|
"### ലോക്കൽ ഡെവലപ്പ്മെന്റിനായി:\n",
|
|
"```bash\n",
|
|
"# Azure CLI ഇൻസ്റ്റാൾ ചെയ്ത് ലോഗിൻ ചെയ്യുക\n",
|
|
"az login\n",
|
|
"# നിങ്ങളുടെ തിരിച്ചറിയൽ സ്ഥിരീകരിക്കുക\n",
|
|
"az account show\n",
|
|
"```\n",
|
|
"\n",
|
|
"### അസ്യൂർ പരിസ്ഥിതികൾക്കായി:\n",
|
|
"- നിങ്ങളുടെ അസ്യൂർ റിസോഴ്സിൽ **സിസ്റ്റം-അസൈൻഡ് മാനേജ്ഡ് ഐഡന്റിറ്റി** സജീവമാക്കുക\n",
|
|
"- മാനേജ്ഡ് ഐഡന്റിറ്റിക്ക് അനുയോജ്യമായ **RBAC റോളുകൾ** നിയോഗിക്കുക:\n",
|
|
" - അസ്യൂർ ഓപ്പൺഎഐ ആക്സസിനായി `Cognitive Services OpenAI User`\n",
|
|
" - അസ്യൂർ എഐ പ്രോജക്റ്റുകൾ ആക്സസിനായി `AI Developer`\n",
|
|
"\n",
|
|
"### പരിസ്ഥിതി വേരിയബിളുകൾ (ഐച്ഛികം):\n",
|
|
"```python\n",
|
|
"# ഇവ DefaultAzureCredential ഉപയോഗിച്ച് സ്വയം കണ്ടെത്തപ്പെടുന്നു\n",
|
|
"# AZURE_CLIENT_ID=<നിങ്ങളുടെ-ക്ലയന്റ്-ഐഡി>\n",
|
|
"# AZURE_CLIENT_SECRET=<നിങ്ങളുടെ-ക്ലയന്റ്-സീക്രട്ട്>\n",
|
|
"# AZURE_TENANT_ID=<നിങ്ങളുടെ-ടെനന്റ്-ഐഡി>\n",
|
|
"```\n",
|
|
"\n",
|
|
"**എന്തെങ്കിലും API കീകൾ അല്ലെങ്കിൽ കണക്ഷൻ സ്ട്രിംഗുകൾ ആവശ്യമില്ല!** 🔐\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "2e21387d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"! pip install azure-ai-projects -U\n",
|
|
"! pip install azure-ai-agents==1.1.0b4 -U\n",
|
|
"! pip install azure-identity -U\n",
|
|
"! pip install mcp==1.11.0 -U"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b31c8873",
|
|
"metadata": {},
|
|
"source": [
|
|
"## ആവശ്യമായ ലൈബ്രറികൾ ഇറക്കുമതി ചെയ്യുക\n",
|
|
"\n",
|
|
"ആവശ്യമായ Python മോഡ്യൂളുകൾ ഇറക്കുമതി ചെയ്യുക:\n",
|
|
"- **os, time**: പരിസ്ഥിതി വ്യത്യാസങ്ങൾക്കും വൈകിപ്പിക്കലുകൾക്കും സ്റ്റാൻഡേർഡ് Python ലൈബ്രറികൾ\n",
|
|
"- **AIProjectClient**: Azure AI Projects-നുള്ള പ്രധാന ക്ലയന്റ്\n",
|
|
"- **DefaultAzureCredential**: Azure സേവനങ്ങൾക്ക് കീ ഇല്ലാത്ത പ്രാമാണീകരണം\n",
|
|
"- **MCP-സംബന്ധിച്ച ക്ലാസുകൾ**: MCP ടൂളുകൾ സൃഷ്ടിക്കുകയും മാനേജ് ചെയ്യുകയും അംഗീകാരങ്ങൾ കൈകാര്യം ചെയ്യുകയും ചെയ്യാൻ\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "43667b32",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os, time\n",
|
|
"from azure.ai.projects import AIProjectClient\n",
|
|
"from azure.identity import DefaultAzureCredential\n",
|
|
"from azure.ai.agents.models import McpTool, RequiredMcpToolCall, SubmitToolApprovalAction, ToolApproval\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "721355e5",
|
|
"metadata": {},
|
|
"source": [
|
|
"## MCP സെർവർ ക്രമീകരണങ്ങൾ ക്രമീകരിക്കുക\n",
|
|
"\n",
|
|
"ഫോൾബാക്ക് ഡിഫോൾട്ടുകളോടുകൂടിയ പരിസ്ഥിതി വ്യത്യാസങ്ങൾ ഉപയോഗിച്ച് MCP സെർവർ കോൺഫിഗറേഷൻ സജ്ജമാക്കുക:\n",
|
|
"- **MCP_SERVER_URL**: MCP സെർവറിന്റെ URL (ഡിഫോൾട്ട് Microsoft Learn API)\n",
|
|
"- **MCP_SERVER_LABEL**: MCP സെർവർ തിരിച്ചറിയാൻ ഒരു ലേബൽ (ഡിഫോൾട്ട് \"mslearn\")\n",
|
|
"\n",
|
|
"വിവിധ പരിസ്ഥിതികളിൽ സൗകര്യപ്രദമായ ക്രമീകരണത്തിന് ഈ സമീപനം അനുവദിക്കുന്നു.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "189f3d55",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"mcp_server_url = os.environ.get(\"MCP_SERVER_URL\", \"https://learn.microsoft.com/api/mcp\")\n",
|
|
"mcp_server_label = os.environ.get(\"MCP_SERVER_LABEL\", \"mslearn\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "20612d9a",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Azure AI പ്രോജക്ട് ക്ലയന്റ് സൃഷ്ടിക്കുക (കീലെസ് ഓതന്റിക്കേഷൻ)\n",
|
|
"\n",
|
|
"**കീലെസ് ഓതന്റിക്കേഷൻ** ഉപയോഗിച്ച് Azure AI പ്രോജക്ട് ക്ലയന്റ് ഇൻഷിയലൈസ് ചെയ്യുക:\n",
|
|
"- **endpoint**: Azure AI Foundry പ്രോജക്ട് എൻഡ്പോയിന്റ് URL\n",
|
|
"- **credential**: സുരക്ഷിതമായ, കീലെസ് ഓതന്റിക്കേഷനായി `DefaultAzureCredential()` ഉപയോഗിക്കുന്നു\n",
|
|
"- **API കീകൾ ആവശ്യമില്ല**: സ്വയം കണ്ടെത്തി ഏറ്റവും മികച്ച ക്രെഡൻഷ്യൽ ഉപയോഗിക്കുന്നു\n",
|
|
"\n",
|
|
"**ഓതന്റിക്കേഷൻ ഫ്ലോ:**\n",
|
|
"1. മാനേജ്ഡ് ഐഡന്റിറ്റി പരിശോധിക്കുന്നു (Azure പരിസരങ്ങളിൽ)\n",
|
|
"2. ലോക്കൽ ഡെവലപ്പ്മെന്റിനായി Azure CLI ക്രെഡൻഷ്യലിലേക്ക് തിരിച്ചുപോകുന്നു\n",
|
|
"3. ആവശ്യമായപ്പോൾ മറ്റ് ലഭ്യമായ ക്രെഡൻഷ്യൽ സ്രോതസ്സുകൾ ഉപയോഗിക്കുന്നു\n",
|
|
"\n",
|
|
"ഈ സമീപനം നിങ്ങളുടെ കോഡിൽ API കീകൾ അല്ലെങ്കിൽ കണക്ഷൻ സ്ട്രിംഗുകൾ കൈകാര്യം ചെയ്യേണ്ടതില്ല.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "36b1dbd8",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"project_client = AIProjectClient(\n",
|
|
" endpoint=\"Your Azure AI Foundry Endpoint\",\n",
|
|
" credential=DefaultAzureCredential(),\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "cdb6ab8c",
|
|
"metadata": {},
|
|
"source": [
|
|
"## MCP ടൂൾ നിർവചനം സൃഷ്ടിക്കുക\n",
|
|
"\n",
|
|
"Microsoft Learn MCP സെർവറുമായി ബന്ധിപ്പിക്കുന്ന MCP ടൂൾ സൃഷ്ടിക്കുക:\n",
|
|
"- **server_label**: MCP സെർവറിന്റെ തിരിച്ചറിയൽ\n",
|
|
"- **server_url**: MCP സെർവറിന്റെ URL എന്റ്പോയിന്റ്\n",
|
|
"- **allowed_tools**: ഉപയോഗിക്കാവുന്ന ടൂളുകൾ നിയന്ത്രിക്കാൻ ഐച്ഛികമായ പട്ടിക (ശൂന്യ പട്ടിക എല്ലാ ടൂളുകൾക്കും അനുമതി നൽകുന്നു)\n",
|
|
"\n",
|
|
"ഈ ടൂൾ ഏജന്റിന് Microsoft Learn ഡോക്യുമെന്റേഷൻ மற்றும் വിഭവങ്ങൾ ആക്സസ് ചെയ്യാൻ സാധ്യമാക്കും.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "51e7e136",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"mcp_tool = McpTool(\n",
|
|
" server_label=mcp_server_label,\n",
|
|
" server_url=mcp_server_url,\n",
|
|
" allowed_tools=[], # Optional: specify allowed tools\n",
|
|
")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "6e894b0b",
|
|
"metadata": {},
|
|
"source": [
|
|
"## ഏജന്റ് സൃഷ്ടിക്കുകയും സംഭാഷണം നടപ്പിലാക്കുകയും ചെയ്യുക (കീലെസ് വർക്ക്ഫ്ലോ)\n",
|
|
"\n",
|
|
"ഈ സമഗ്ര വിഭാഗം പൂർണ്ണമായ **കീലെസ് ഏജന്റ് വർക്ക്ഫ്ലോ** കാണിക്കുന്നു:\n",
|
|
"\n",
|
|
"1. **AI ഏജന്റ് സൃഷ്ടിക്കുക**: GPT-4.1 നാനോ മോഡലും MCP ടൂളുകളും ഉപയോഗിച്ച് ഏജന്റ് സജ്ജമാക്കുക \n",
|
|
"2. **ത്രീഡ് സൃഷ്ടിക്കുക**: ആശയവിനിമയത്തിനായി ഒരു സംഭാഷണ ത്രീഡ് സ്ഥാപിക്കുക \n",
|
|
"3. **സന്ദേശം അയയ്ക്കുക**: ഏജന്റിനോട് Azure OpenAI vs OpenAI വ്യത്യാസങ്ങളെക്കുറിച്ച് ചോദിക്കുക \n",
|
|
"4. **ടൂൾ അംഗീകാരങ്ങൾ കൈകാര്യം ചെയ്യുക**: ആവശ്യമായപ്പോൾ MCP ടൂൾ കോൾസ് സ്വയം അംഗീകരിക്കുക \n",
|
|
"5. **നടപ്പിലാക്കൽ നിരീക്ഷിക്കുക**: ഏജന്റിന്റെ പുരോഗതിയെ പിന്തുടരുകയും ആവശ്യമായ നടപടികൾ കൈകാര്യം ചെയ്യുകയും ചെയ്യുക \n",
|
|
"6. **ഫലങ്ങൾ പ്രദർശിപ്പിക്കുക**: സംഭാഷണവും ടൂൾ ഉപയോഗ വിശദാംശങ്ങളും കാണിക്കുക \n",
|
|
"\n",
|
|
"**കീലെസ് സവിശേഷതകൾ:** \n",
|
|
"- ✅ **ഹാർഡ്കോഡ് ചെയ്ത രഹസ്യങ്ങൾ ഇല്ല** - എല്ലാ പ്രാമാണീകരണവും Azure ഐഡന്റിറ്റി വഴി കൈകാര്യം ചെയ്യുന്നു \n",
|
|
"- ✅ **സ്വാഭാവികമായി സുരക്ഷിതം** - റോളിനിഷ്ഠ ആക്സസ് നിയന്ത്രണം ഉപയോഗിക്കുന്നു \n",
|
|
"- ✅ **സരളമായ വിന്യാസം** - ക്രെഡൻഷ്യൽ മാനേജ്മെന്റ് ആവശ്യമില്ല \n",
|
|
"- ✅ **ഓഡിറ്റ് സൗഹൃദം** - എല്ലാ ആക്സസും Azure ഐഡന്റിറ്റി വഴി ട്രാക്ക് ചെയ്യുന്നു \n",
|
|
"\n",
|
|
"ഏജന്റ് MCP ടൂളുകൾ ഉപയോഗിച്ച് Microsoft Learn വിഭവങ്ങളിലേക്ക് പൂർണ്ണ സുരക്ഷയോടും API കീ മാനേജ്മെന്റ് ഇല്ലാതെയും പ്രവേശനം നേടും.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "68c49af5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"with project_client:\n",
|
|
" agents_client = project_client.agents\n",
|
|
"\n",
|
|
" # Create a new agent with keyless authentication\n",
|
|
" # NOTE: To reuse existing agent, fetch it with get_agent(agent_id)\n",
|
|
" agent = agents_client.create_agent(\n",
|
|
" model=\"Your Azure OpenAI Model Deployment Name\",\n",
|
|
" name=\"my-mcp-agent\",\n",
|
|
" instructions=\"You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.\",\n",
|
|
" tools=mcp_tool.definitions,\n",
|
|
" )\n",
|
|
" print(f\"Created agent, ID: {agent.id}\")\n",
|
|
" print(f\"MCP Server: {mcp_tool.server_label} at {mcp_tool.server_url}\")\n",
|
|
"\n",
|
|
" # Create thread for communication\n",
|
|
" thread = agents_client.threads.create()\n",
|
|
" print(f\"Created thread, ID: {thread.id}\")\n",
|
|
"\n",
|
|
" # Create message to thread\n",
|
|
" message = agents_client.messages.create(\n",
|
|
" thread_id=thread.id,\n",
|
|
" role=\"user\",\n",
|
|
" content=\"What's difference between Azure OpenAI and OpenAI?\",\n",
|
|
" )\n",
|
|
" print(f\"Created message, ID: {message.id}\")\n",
|
|
"\n",
|
|
" # KEYLESS APPROACH: Handle tool approvals without hardcoded secrets\n",
|
|
" \n",
|
|
" # Option 1: Completely keyless (recommended for Azure identity-enabled MCP servers)\n",
|
|
" # run = agents_client.runs.create(thread_id=thread.id, agent_id=agent.id, tool_resources=mcp_tool.resources)\n",
|
|
" \n",
|
|
" # Option 2: With minimal headers (if MCP server requires specific headers)\n",
|
|
" # For demonstration purposes, using a placeholder header\n",
|
|
" mcp_tool.update_headers(\"SuperSecret\", \"123456\") # Replace with actual auth if needed\n",
|
|
" \n",
|
|
" # Set approval mode - uncomment next line to disable approval requirement completely\n",
|
|
" # mcp_tool.set_approval_mode(\"never\") # Fully automated, no approval needed\n",
|
|
" \n",
|
|
" run = agents_client.runs.create(thread_id=thread.id, agent_id=agent.id, tool_resources=mcp_tool.resources)\n",
|
|
" print(f\"Created run, ID: {run.id}\")\n",
|
|
"\n",
|
|
" while run.status in [\"queued\", \"in_progress\", \"requires_action\"]:\n",
|
|
" time.sleep(1)\n",
|
|
" run = agents_client.runs.get(thread_id=thread.id, run_id=run.id)\n",
|
|
"\n",
|
|
" if run.status == \"requires_action\" and isinstance(run.required_action, SubmitToolApprovalAction):\n",
|
|
" tool_calls = run.required_action.submit_tool_approval.tool_calls\n",
|
|
" if not tool_calls:\n",
|
|
" print(\"No tool calls provided - cancelling run\")\n",
|
|
" agents_client.runs.cancel(thread_id=thread.id, run_id=run.id)\n",
|
|
" break\n",
|
|
"\n",
|
|
" tool_approvals = []\n",
|
|
" for tool_call in tool_calls:\n",
|
|
" if isinstance(tool_call, RequiredMcpToolCall):\n",
|
|
" try:\n",
|
|
" print(f\"Approving tool call: {tool_call}\")\n",
|
|
" \n",
|
|
" # KEYLESS APPROVAL OPTIONS:\n",
|
|
" \n",
|
|
" # Option 1: No headers (fully keyless)\n",
|
|
" # tool_approvals.append(\n",
|
|
" # ToolApproval(\n",
|
|
" # tool_call_id=tool_call.id,\n",
|
|
" # approve=True,\n",
|
|
" # headers={} # No headers needed for keyless\n",
|
|
" # )\n",
|
|
" # )\n",
|
|
" \n",
|
|
" # Option 2: With headers (if MCP server requires them)\n",
|
|
" tool_approvals.append(\n",
|
|
" ToolApproval(\n",
|
|
" tool_call_id=tool_call.id,\n",
|
|
" approve=True,\n",
|
|
" headers=mcp_tool.headers, # Uses configured headers if needed\n",
|
|
" )\n",
|
|
" )\n",
|
|
" except Exception as e:\n",
|
|
" print(f\"Error approving tool_call {tool_call.id}: {e}\")\n",
|
|
"\n",
|
|
" print(f\"tool_approvals: {tool_approvals}\")\n",
|
|
" if tool_approvals:\n",
|
|
" agents_client.runs.submit_tool_outputs(\n",
|
|
" thread_id=thread.id, run_id=run.id, tool_approvals=tool_approvals\n",
|
|
" )\n",
|
|
"\n",
|
|
" print(f\"Current run status: {run.status}\")\n",
|
|
"\n",
|
|
" print(f\"Run completed with status: {run.status}\")\n",
|
|
" if run.status == \"failed\":\n",
|
|
" print(f\"Run failed: {run.last_error}\")\n",
|
|
"\n",
|
|
" # Display run steps and tool calls\n",
|
|
" run_steps = agents_client.run_steps.list(thread_id=thread.id, run_id=run.id)\n",
|
|
"\n",
|
|
" # Loop through each step\n",
|
|
" for step in run_steps:\n",
|
|
" print(f\"Step {step['id']} status: {step['status']}\")\n",
|
|
"\n",
|
|
" # Check if there are tool calls in the step details\n",
|
|
" step_details = step.get(\"step_details\", {})\n",
|
|
" tool_calls = step_details.get(\"tool_calls\", [])\n",
|
|
"\n",
|
|
" if tool_calls:\n",
|
|
" print(\" MCP Tool calls:\")\n",
|
|
" for call in tool_calls:\n",
|
|
" print(f\" Tool Call ID: {call.get('id')}\")\n",
|
|
" print(f\" Type: {call.get('type')}\")\n",
|
|
"\n",
|
|
" print() # add an extra newline between steps\n",
|
|
"\n",
|
|
" # Fetch and log all messages\n",
|
|
" messages = agents_client.messages.list(thread_id=thread.id)\n",
|
|
" print(\"\\nConversation:\")\n",
|
|
" print(\"-\" * 50)\n",
|
|
" for msg in messages:\n",
|
|
" if msg.text_messages:\n",
|
|
" last_text = msg.text_messages[-1]\n",
|
|
" print(f\"{msg.role.upper()}: {last_text.text.value}\")\n",
|
|
" print(\"-\" * 50)\n",
|
|
"\n",
|
|
" # Example of dynamic tool management (keyless)\n",
|
|
" print(f\"\\nDemonstrating keyless dynamic tool management:\")\n",
|
|
" print(f\"Current allowed tools: {mcp_tool.allowed_tools}\")\n",
|
|
" print(\"✅ All operations completed using keyless authentication!\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"---\n\n<!-- CO-OP TRANSLATOR DISCLAIMER START -->\n**അസൂയാ**: \nഈ രേഖ AI വിവർത്തന സേവനം [Co-op Translator](https://github.com/Azure/co-op-translator) ഉപയോഗിച്ച് വിവർത്തനം ചെയ്തതാണ്. നാം കൃത്യതയ്ക്ക് ശ്രമിച്ചിട്ടുണ്ടെങ്കിലും, സ്വയം പ്രവർത്തിക്കുന്ന വിവർത്തനങ്ങളിൽ പിശകുകൾ അല്ലെങ്കിൽ തെറ്റുകൾ ഉണ്ടാകാമെന്ന് ദയവായി ശ്രദ്ധിക്കുക. അതിന്റെ മാതൃഭാഷയിലുള്ള യഥാർത്ഥ രേഖ അധികാരപരമായ ഉറവിടമായി കണക്കാക്കപ്പെടണം. നിർണായക വിവരങ്ങൾക്ക്, പ്രൊഫഷണൽ മനുഷ്യ വിവർത്തനം ശുപാർശ ചെയ്യപ്പെടുന്നു. ഈ വിവർത്തനം ഉപയോഗിക്കുന്നതിൽ നിന്നുണ്ടാകുന്ന ഏതെങ്കിലും തെറ്റിദ്ധാരണകൾക്കോ തെറ്റായ വ്യാഖ്യാനങ്ങൾക്കോ ഞങ്ങൾ ഉത്തരവാദികളല്ല.\n<!-- CO-OP TRANSLATOR DISCLAIMER END -->\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "demo",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.15"
|
|
},
|
|
"coopTranslator": {
|
|
"original_hash": "39a035fea0d10767dfcb0662bd3528fa",
|
|
"translation_date": "2025-12-11T17:10:05+00:00",
|
|
"source_file": "05-AdvancedTopics/mcp-foundry-agent-integration/mcp_support_python.ipynb",
|
|
"language_code": "ml"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
} |