[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-43dd0425-7389-4999-8fd0-0cb0e7211f15":3,"$fabdnLxPFGe7typjbKgDy9NlXdPihbZQo4rAqV9Tqo_U":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"43dd0425-7389-4999-8fd0-0cb0e7211f15","agent-framework-azure-ai-py","在Azure AI Foundry上使用Microsoft Agent Framework Python SDK构建持久代理。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: agent-framework-azure-ai-py\ndescription: \"Build persistent agents on Azure AI Foundry using the Microsoft Agent Framework Python SDK.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Agent Framework Azure Hosted Agents\n\nBuild persistent agents on Azure AI Foundry using the Microsoft Agent Framework Python SDK.\n\n## Architecture\n\n```\nUser Query → AzureAIAgentsProvider → Azure AI Agent Service (Persistent)\n                    ↓\n              Agent.run() \u002F Agent.run_stream()\n                    ↓\n              Tools: Functions | Hosted (Code\u002FSearch\u002FWeb) | MCP\n                    ↓\n              AgentThread (conversation persistence)\n```\n\n## Installation\n\n```bash\n# Full framework (recommended)\npip install agent-framework --pre\n\n# Or Azure-specific package only\npip install agent-framework-azure-ai --pre\n```\n\n## Environment Variables\n\n```bash\nexport AZURE_AI_PROJECT_ENDPOINT=\"https:\u002F\u002F\u003Cproject>.services.ai.azure.com\u002Fapi\u002Fprojects\u002F\u003Cproject-id>\"\nexport AZURE_AI_MODEL_DEPLOYMENT_NAME=\"gpt-4o-mini\"\nexport BING_CONNECTION_ID=\"your-bing-connection-id\"  # For web search\n```\n\n## Authentication\n\n```python\nfrom azure.identity.aio import AzureCliCredential, DefaultAzureCredential\n\n# Development\ncredential = AzureCliCredential()\n\n# Production\ncredential = DefaultAzureCredential()\n```\n\n## Core Workflow\n\n### Basic Agent\n\n```python\nimport asyncio\nfrom agent_framework.azure import AzureAIAgentsProvider\nfrom azure.identity.aio import AzureCliCredential\n\nasync def main():\n    async with (\n        AzureCliCredential() as credential,\n        AzureAIAgentsProvider(credential=credential) as provider,\n    ):\n        agent = await provider.create_agent(\n            name=\"MyAgent\",\n            instructions=\"You are a helpful assistant.\",\n        )\n        \n        result = await agent.run(\"Hello!\")\n        print(result.text)\n\nasyncio.run(main())\n```\n\n### Agent with Function Tools\n\n```python\nfrom typing import Annotated\nfrom pydantic import Field\nfrom agent_framework.azure import AzureAIAgentsProvider\nfrom azure.identity.aio import AzureCliCredential\n\ndef get_weather(\n    location: Annotated[str, Field(description=\"City name to get weather for\")],\n) -> str:\n    \"\"\"Get the current weather for a location.\"\"\"\n    return f\"Weather in {location}: 72°F, sunny\"\n\ndef get_current_time() -> str:\n    \"\"\"Get the current UTC time.\"\"\"\n    from datetime import datetime, timezone\n    return datetime.now(timezone.utc).strftime(\"%Y-%m-%d %H:%M:%S UTC\")\n\nasync def main():\n    async with (\n        AzureCliCredential() as credential,\n        AzureAIAgentsProvider(credential=credential) as provider,\n    ):\n        agent = await provider.create_agent(\n            name=\"WeatherAgent\",\n            instructions=\"You help with weather and time queries.\",\n            tools=[get_weather, get_current_time],  # Pass functions directly\n        )\n        \n        result = await agent.run(\"What's the weather in Seattle?\")\n        print(result.text)\n```\n\n### Agent with Hosted Tools\n\n```python\nfrom agent_framework import (\n    HostedCodeInterpreterTool,\n    HostedFileSearchTool,\n    HostedWebSearchTool,\n)\nfrom agent_framework.azure import AzureAIAgentsProvider\nfrom azure.identity.aio import AzureCliCredential\n\nasync def main():\n    async with (\n        AzureCliCredential() as credential,\n        AzureAIAgentsProvider(credential=credential) as provider,\n    ):\n        agent = await provider.create_agent(\n            name=\"MultiToolAgent\",\n            instructions=\"You can execute code, search files, and search the web.\",\n            tools=[\n                HostedCodeInterpreterTool(),\n                HostedWebSearchTool(name=\"Bing\"),\n            ],\n        )\n        \n        result = await agent.run(\"Calculate the factorial of 20 in Python\")\n        print(result.text)\n```\n\n### Streaming Responses\n\n```python\nasync def main():\n    async with (\n        AzureCliCredential() as credential,\n        AzureAIAgentsProvider(credential=credential) as provider,\n    ):\n        agent = await provider.create_agent(\n            name=\"StreamingAgent\",\n            instructions=\"You are a helpful assistant.\",\n        )\n        \n        print(\"Agent: \", end=\"\", flush=True)\n        async for chunk in agent.run_stream(\"Tell me a short story\"):\n            if chunk.text:\n                print(chunk.text, end=\"\", flush=True)\n        print()\n```\n\n### Conversation Threads\n\n```python\nfrom agent_framework.azure import AzureAIAgentsProvider\nfrom azure.identity.aio import AzureCliCredential\n\nasync def main():\n    async with (\n        AzureCliCredential() as credential,\n        AzureAIAgentsProvider(credential=credential) as provider,\n    ):\n        agent = await provider.create_agent(\n            name=\"ChatAgent\",\n            instructions=\"You are a helpful assistant.\",\n            tools=[get_weather],\n        )\n        \n        # Create thread for conversation persistence\n        thread = agent.get_new_thread()\n        \n        # First turn\n        result1 = await agent.run(\"What's the weather in Seattle?\", thread=thread)\n        print(f\"Agent: {result1.text}\")\n        \n        # Second turn - context is maintained\n        result2 = await agent.run(\"What about Portland?\", thread=thread)\n        print(f\"Agent: {result2.text}\")\n        \n        # Save thread ID for later resumption\n        print(f\"Conversation ID: {thread.conversation_id}\")\n```\n\n### Structured Outputs\n\n```python\nfrom pydantic import BaseModel, ConfigDict\nfrom agent_framework.azure import AzureAIAgentsProvider\nfrom azure.identity.aio import AzureCliCredential\n\nclass WeatherResponse(BaseModel):\n    model_config = ConfigDict(extra=\"forbid\")\n    \n    location: str\n    temperature: float\n    unit: str\n    conditions: str\n\nasync def main():\n    async with (\n        AzureCliCredential() as credential,\n        AzureAIAgentsProvider(credential=credential) as provider,\n    ):\n        agent = await provider.create_agent(\n            name=\"StructuredAgent\",\n            instructions=\"Provide weather information in structured format.\",\n            response_format=WeatherResponse,\n        )\n        \n        result = await agent.run(\"Weather in Seattle?\")\n        weather = WeatherResponse.model_validate_json(result.text)\n        print(f\"{weather.location}: {weather.temperature}°{weather.unit}\")\n```\n\n## Provider Methods\n\n| Method | Description |\n|--------|-------------|\n| `create_agent()` | Create new agent on Azure AI service |\n| `get_agent(agent_id)` | Retrieve existing agent by ID |\n| `as_agent(sdk_agent)` | Wrap SDK Agent object (no HTTP call) |\n\n## Hosted Tools Quick Reference\n\n| Tool | Import | Purpose |\n|------|--------|---------|\n| `HostedCodeInterpreterTool` | `from agent_framework import HostedCodeInterpreterTool` | Execute Python code |\n| `HostedFileSearchTool` | `from agent_framework import HostedFileSearchTool` | Search vector stores |\n| `HostedWebSearchTool` | `from agent_framework import HostedWebSearchTool` | Bing web search |\n| `HostedMCPTool` | `from agent_framework import HostedMCPTool` | Service-managed MCP |\n| `MCPStreamableHTTPTool` | `from agent_framework import MCPStreamableHTTPTool` | Client-managed MCP |\n\n## Complete Example\n\n```python\nimport asyncio\nfrom typing import Annotated\nfrom pydantic import BaseModel, Field\nfrom agent_framework import (\n    HostedCodeInterpreterTool,\n    HostedWebSearchTool,\n    MCPStreamableHTTPTool,\n)\nfrom agent_framework.azure import AzureAIAgentsProvider\nfrom azure.identity.aio import AzureCliCredential\n\n\ndef get_weather(\n    location: Annotated[str, Field(description=\"City name\")],\n) -> str:\n    \"\"\"Get weather for a location.\"\"\"\n    return f\"Weather in {location}: 72°F, sunny\"\n\n\nclass AnalysisResult(BaseModel):\n    summary: str\n    key_findings: list[str]\n    confidence: float\n\n\nasync def main():\n    async with (\n        AzureCliCredential() as credential,\n        MCPStreamableHTTPTool(\n            name=\"Docs MCP\",\n            url=\"https:\u002F\u002Flearn.microsoft.com\u002Fapi\u002Fmcp\",\n        ) as mcp_tool,\n        AzureAIAgentsProvider(credential=credential) as provider,\n    ):\n        agent = await provider.create_agent(\n            name=\"ResearchAssistant\",\n            instructions=\"You are a research assistant with multiple capabilities.\",\n            tools=[\n                get_weather,\n                HostedCodeInterpreterTool(),\n                HostedWebSearchTool(name=\"Bing\"),\n                mcp_tool,\n            ],\n        )\n        \n        thread = agent.get_new_thread()\n        \n        # Non-streaming\n        result = await agent.run(\n            \"Search for Python best practices and summarize\",\n            thread=thread,\n        )\n        print(f\"Response: {result.text}\")\n        \n        # Streaming\n        print(\"\\nStreaming: \", end=\"\")\n        async for chunk in agent.run_stream(\"Continue with examples\", thread=thread):\n            if chunk.text:\n                print(chunk.text, end=\"\", flush=True)\n        print()\n        \n        # Structured output\n        result = await agent.run(\n            \"Analyze findings\",\n            thread=thread,\n            response_format=AnalysisResult,\n        )\n        analysis = AnalysisResult.model_validate_json(result.text)\n        print(f\"\\nConfidence: {analysis.confidence}\")\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n## Conventions\n\n- Always use async context managers: `async with provider:`\n- Pass functions directly to `tools=` parameter (auto-converted to AIFunction)\n- Use `Annotated[type, Field(description=...)]` for function parameters\n- Use `get_new_thread()` for multi-turn conversations\n- Prefer `HostedMCPTool` for service-managed MCP, `MCPStreamableHTTPTool` for client-managed\n\n## Reference Files\n\n- references\u002Ftools.md: Detailed hosted tool patterns\n- references\u002Fmcp.md: MCP integration (hosted + local)\n- references\u002Fthreads.md: Thread and conversation management\n- references\u002Fadvanced.md: OpenAPI, citations, structured outputs\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,184,2034,"2026-05-16 13:01:13",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"15c464ce-4162-46e7-be2b-7df78588a6a0","1.0.0","agent-framework-azure-ai-py.zip",2907,"uploads\u002Fskills\u002F43dd0425-7389-4999-8fd0-0cb0e7211f15\u002Fagent-framework-azure-ai-py.zip","4923cf3e4c39cb721f1b9fec494af2ad9b69111ea2eef5bce45df2e69560127d","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":10343}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]