agent framework azure ai py

AI Community

Skill notes

Authentication & Lifecycle

🔑 Two rules apply to every code sample below: 1. Prefer DefaultAzureCredential. It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation. - Local dev: DefaultAzureCredential works as-is. - Production: set AZURE_TOKEN_CREDENTIALS=prod (or AZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.

Provider Methods

Method · Description create_agent() · Create new agent on Azure AI service get_agent(agent_id) · Retrieve existing agent by ID as_agent(sdk_agent) · Wrap SDK Agent object (no HTTP call)

Hosted Tools Quick Reference

Tool · Import · Purpose HostedCodeInterpreterTool · from agent_framework import HostedCodeInterpreterTool · Execute Python code HostedFileSearchTool · from agent_framework import HostedFileSearchTool · Search vector stores HostedWebSearchTool · from agent_framework import HostedWebSearchTool · Bing web search HostedMCPTool · from agent_framework import HostedMCPTool · Service-managed MCP

Conventions

Always use async context managers: async with provider: Pass functions directly to tools= parameter (auto-converted to AIFunction) Use Annotated[type, Field(description=...)] for function parameters Use get_new_thread() for multi-turn conversations Prefer HostedMCPTool for service-managed MCP, MCPStreamableHTTPTool for client-managed

Best Practices

This SDK is async-first — use async def handlers and async with throughout. Always use context managers for clients and async credentials. Wrap every client in with Client(...) as client: (sync) or async with Client(...) as client: (async). For async DefaultAzureCredential from azure.identity.aio, also use async with credential: so tokens and transports are cleaned up.

Fluxly profile Runtime and permissions are inferred by Fluxly static checks, not author declarations or runtime test results.
Domain
AI
Author-declared agents
No explicit declaration found; this is not inferred or tested compatibility
Static check
94 / 100 · heuristic scan, not runtime safety proof
Runtime evidence
Not run; no isolated runtime test evidence is currently recorded
Author / version / license
@microsoft · MIT
Token usage
Lean
Setup complexity
Guided setup
External API key
Not required
Operating systems
Unspecified (assume cross-platform)
Runtime requirements
Python
Detected file/system behavior
  • Read-only
  • Write / modify
  • Shell exec
  • Env read
Network behavior
Local-only
Install commands
None (reference only)

Heads up: Tool permissions are not declared; actual access depends on the runtime.

Output preview agent-framework-azure-ai-py.preview
# Structured Outputs

from pydantic import BaseModel, ConfigDict
from agent_framework.azure import AzureAIAgentsProvider
from azure.identity.aio import AzureCliCredential

class WeatherResponse(BaseModel):
    model_config = ConfigDict(extra="forbid")
    
    location: str
    temperature: float
    unit: str
    conditions: str

async def main():
    async with (
        AzureCliCredential() as credential,
        AzureAIAgentsProvider(credential=credential) as provider,
    ):
        agent = await provider.create_agent(
            name="StructuredAgent",
            instructions="Provide weather information in structured format.",
            response_format=WeatherResponse,
        )
        
        result = await agent.run("Weather in Seattle?")
        weather = WeatherResponse.model_validate_json(result.text)
        print(f"{weather.location}: {weather.temperature}°{weather.unit}")

Discussion

Powered by GitHub Discussions. Sign in with GitHub to comment, react, or subscribe.