Microsoft Foundry Samples

repository·main·Indexed 18 days ago

https://github.com/microsoft-foundry/foundry-samples

A collection of official Microsoft Foundry documentation samples, including notebooks and code snippets for end-to-end scenarios and common developer tasks. It provides Bicep templates and configuration guides for deploying APIM connections, ModelGateway connections (supporting OpenAI, AzureAI, and OAuth2), and enabling AI Gateway for Azure AI Foundry projects.

Tokens
545.3K
Snippets
1.2K
Records
2K
Agent score
64%

What's inside foundry-samples

  1. Overview of the 'Bring Your Own' Responses Protocol Sample

    main

    This sample demonstrates a minimal 'hello world' hosted agent using the Bring Your Own (BYO) approach with the Responses protocol. It uses the azure-ai-agentserver-responses SDK to host a custom agent that calls a Foundry model via the Responses API and returns replies through a standard Responses protocol contract.

    Key Components

    • Model Integration: Uses the Foundry SDK (azure-ai-projects) to create an OpenAI-compatible Responses client. The handler extracts user input, calls the model, and returns a TextResponse. The SDK automatically manages the SSE (Server-Sent Events) lifecycle (response.createdresponse.in_progress → content events → response.completed).
    • Agent Hosting: Hosted via the Azure AI AgentServer Responses SDK, which provides a REST API endpoint compatible with the OpenAI Responses protocol.
    • Agent Deployment: Can be deployed to Microsoft Foundry using the Azure Developer CLI (azd).
  2. Overview of LangGraph Multi-turn Chat Agent

    main

    This sample implements a multi-turn conversational agent using LangGraph and Azure OpenAI, hosted via the invocations protocol.

    Key features include:

    • A LangGraph agent graph with conditional routing for tool calls.
    • Built-in tools: get_current_time and calculator.
    • Multi-turn conversations managed via agent_session_id using an in-memory session store.
    • SSE streaming output supported over the invocations protocol.
    • Authentication via DefaultAzureCredential for Azure OpenAI.
  3. Overview of Agent Framework Samples

    main

    The samples/python/hosted-agents/agent-framework/ directory provides implementations demonstrating how to use the Agent Framework to host agents with various capabilities. The samples are categorized by the API or protocol they demonstrate:

    • Responses API: Covers basic interactions, tool usage (local and Foundry Toolbox), workflows, file handling, skills, observability, RAG (Azure AI Search), memory (Azure AI Foundry Memory Store), and more.
    • Invocations API: Focuses on session state management using agent_session_id.
    • A2A protocol: Demonstrates Agent-to-Agent (A2A) delegation where a caller delegates tasks to an executor exposed via Foundry's incoming A2A feature.
  4. Overview of Standard Agent Setup with Private APIM and E2E Network Isolation

    main

    This IaC (Infrastructure as Code) solution deploys a network-secured Azure AI agent environment. It provides end-to-end network isolation using a Bring Your Own Virtual Network (BYO VNet) approach (custom VNet support with subnet delegation).

    Key features include:

    • Private Networking: All resources are behind private endpoints with no public internet access.
    • Private APIM Integration: Connects an existing Azure API Management (APIM) service behind a private endpoint within your VNet, allowing you to expose APIs while keeping traffic within the private network boundary.
    • RBAC & Managed Identity: Uses System Assigned Managed Identity for simplified identity management and Role-Based Access Control for security.
    • Resource Control: Allows for customer-managed Storage, Cosmos DB, and AI Search to ensure data residency and compliance.
  5. Overview of the Bring Your Own Toolbox sample

    main

    This sample demonstrates how to build a Bring Your Own hosted agent using the Responses protocol with Azure AI Foundry Toolbox MCP integration in Python.

    Key capabilities include:

    • Connecting to a Foundry toolbox at startup.
    • Discovering available tools via the Model Context Protocol (MCP).
    • Enabling an agentic tool-calling loop where the model invokes discovered tools during conversation.
    • Automatic conversation history management via the platform using previous_response_id.

    Technical stack:

  6. Overview of the Diagnostic Agent (Python, Invocations)

    main

    The diagnostic hosted-agent is built on the Invocations protocol. It is designed to diagnose network connectivity from within a Foundry runtime sandbox. It does not require an LLM, a Foundry project endpoint, or a model deployment.

    On each invocation, it runs DNS, TCP, TLS, and HTTP probes against hostnames provided by the caller and returns a structured JSON report. This is useful for verifying:

    • DNS resolution for private endpoints (e.g., <customer>.azurecr.io).
    • Connectivity and protocol behavior (e.g., whether an HTTPS request returns 401 Unauthorized or hangs).
    • Egress capabilities to public Azure endpoints (e.g., login.microsoftonline.com).

    Key Design Features:

    • Stdlib-only probes: Uses only socket, ssl, urllib, and http.client to ensure probes don't fail due to missing dependencies.
    • No secrets in response: Environment variables matching KEY, SECRET, PASSWORD, TOKEN, CONNECTION_STRING, or SAS are reported by length only.
    • Flexible Output: Returns a single JSON document by default, or supports Server-Sent Events (SSE) if "stream": true is set or Accept: text/event-stream is sent.
    • Uniform Schema: Every probe emits a ProbeResult containing probe, status, findings, metrics, and evidence.
  7. Overview of LangGraph Samples for Foundry

    main

    This collection of samples demonstrates how to use LangGraph in conjunction with langchain_azure_ai.agents.hosting to host agents on Microsoft Foundry. The samples are categorized by the API used to interact with the agent:

    Responses API

    Used for multi-turn conversations and complex workflows. Key samples include:

    • Chat: Minimal agent with local tools and multi-turn support via previous_response_id.
    • LangGraph Toolbox: Agent connected to a Foundry Toolbox (e.g., web_search, GitHub Copilot MCP).
    • Workflows: Custom StateGraph chaining specialized LLM nodes.
    • Files: Agent with local filesystem tools and code_interpreter for session-uploaded files.
    • Human-in-the-Loop: Uses langgraph.types.interrupt for manual review via mcp_approval_request.
    • Observability: Enables GenAI OpenTelemetry tracing via enable_auto_tracing() to Application Insights.

    Invocations API

    Focuses on session state management. The Chat sample demonstrates using agent_session_id (passed via URL parameter or x-agent-session-id header) backed by a LangGraph checkpointer.

    Agent-to-Agent (A2A)

    Demonstrates delegation between agents. For example, a concierge agent can delegate tasks to a math-expert using a RemoteA2A connection and an a2a_preview Toolbox.

  8. Overview of the GitHub Copilot Hosted Agent Sample

    main

    This sample demonstrates a conversational assistant built using the Bring Your Own approach on the Activity protocol in Python. It leverages the GitHub Copilot SDK to manage the model and tool-calling loop, while using azure-ai-agentserver-activity as the Foundry host to bridge to the M365 Agents SDK for Teams delivery.

    Key Capabilities

    • Streaming chat: Token-by-token replies in Teams with "working..." status updates.
    • To-do list: Interactive Adaptive Cards for managing tasks (Add/List/Complete) per conversation.
    • File handling: Direct reading of shared files (PDF, DOCX, etc.) and generation of downloadable files (including Office formats via runtime Python execution).
    • Vision: Image understanding via base64 blobs.
  9. Overview of Voice Live Hello World (C#)

    main

    This sample implements a minimal real-time voice agent using C#. It uses the Azure.AI.AgentServer.Invocations SDK (InvocationWebSocketHandler) to expose a /invocations_ws endpoint.

    Each browser WebSocket connection is bridged to an Azure Voice Live session. Azure Voice Live manages the entire STT (Speech-to-Text), LLM (Large Language Model), and TTS (Text-to-Speech) pipeline. The sample's primary responsibility is shuttling audio bytes and control events between the client and the Voice Live service.

  10. Overview of the Note-Taking Agent

    main

    The Note-Taking Agent is a Python-based implementation using the azure-ai-agentserver-invocations library and Azure OpenAI. It demonstrates how to build an agent that uses function calling to manage notes.

    Key Capabilities:

    • Natural Language Commands: Save notes (e.g., "save a note - buy groceries") and retrieve them (e.g., "show me my notes").
    • Per-session Isolation: Each agent_session_id maintains its own isolated JSONL note file.
    • Streaming: Supports real-time SSE streaming via the Invocations protocol.
    • Persistence: Uses the Session Files API to store notes at $HOME, making them accessible via the platform file API.
  11. Overview of the Scaling Capabilities Agent Sample

    main

    This sample demonstrates a personal-finance harness agent hosted via the Foundry Responses protocol v2 in C#. It extends a standard agent with four advanced 'scaling' capabilities:

    • Skills: File-based finance skills (valuation, risk-scoring) loaded on demand. Can optionally integrate centrally-managed Foundry skills via a Toolbox MCP endpoint (set FOUNDRY_TOOLBOX_MCP_SERVER_URL).
    • Shell: An approval-gated run_shell tool confined to the working/confirmations/ directory, used for file reorganization with a command deny-list.
    • CodeAct: A sandboxed Python interpreter running on Hyperlight. Note: This requires hardware virtualization enabled on the host. If virtualization is unavailable (e.g., in some hosted containers), only this specific tool will fail.
    • Background agents: The ability to fan out research tasks (like ticker research) to concurrent sub-agents and aggregate results.

    Data Persistence: In a hosted Foundry environment, working data (like portfolio.csv) and file memory live under $HOME. Files written by the agent are durable for the life of the session and accessible via the Session Files API.

  12. Overview of Foundry IQ Knowledge Base Agent

    main

    The Foundry IQ Knowledge Base Agent is an Agent Framework agent that answers questions using a Foundry IQ knowledge base (Azure AI Search agentic retrieval). It is hosted on Microsoft Foundry using the Responses protocol.

    Architecture

    1. Knowledge Base (Data Plane): Uses provision_kb.py to create an Azure AI Search index and a knowledge base. The knowledge base exposes an MCP endpoint ({search}/knowledgebases/{kb}/mcp) with a knowledge_base_retrieve tool. It uses an Azure OpenAI model for answer synthesis.
    2. Toolbox Connection: A RemoteTool connection (knowledge-base-mcp) uses Agentic Identity (managed identity, keyless) to authenticate to the knowledge base's MCP endpoint. A Foundry Toolbox (defined in toolbox.yaml) exposes this endpoint as an MCP tool.
    3. Agent: Uses FoundryChatClient and connects to the toolbox via FoundryToolbox. It discovers the knowledge_base_retrieve tool at runtime to ground answers in retrieved sources.