From 875e0038bd987ff0b3d3b63da13bdee9431b7bb7 Mon Sep 17 00:00:00 2001 From: Shayne Boyer Date: Sun, 25 Jan 2026 12:49:18 -0500 Subject: [PATCH] Improve skill format, auto-install deps, and auto-login SKILL.md: - Updated to match GitHub Copilot plugins format (workiq template) - Added explicit trigger phrases in description - Added CRITICAL usage table with Foundry-specific triggers - Added MCP tool reference and common use cases query_foundry_agent.py: - Auto-install missing Python dependencies on first run - Fallback to ensurepip if pip not available - Auto-invoke 'az login' if user not authenticated - Improved error handling with clear messages README.md: - Simplified to minimal setup (copy files + configure endpoint) - Removed manual dependency install step (now automatic) - Removed manual auth step (now automatic) --- .github/skills/foundry-agent/SKILL.md | 155 +++++++++++------- .../foundry-agent/query_foundry_agent.py | 55 ++++++- README.md | 152 +++-------------- 3 files changed, 168 insertions(+), 194 deletions(-) diff --git a/.github/skills/foundry-agent/SKILL.md b/.github/skills/foundry-agent/SKILL.md index ecebf10..27f950c 100644 --- a/.github/skills/foundry-agent/SKILL.md +++ b/.github/skills/foundry-agent/SKILL.md @@ -1,81 +1,114 @@ --- name: foundry-agent -description: > - Enables GitHub Copilot to send user prompts to a Microsoft Foundry Agent for advanced Q&A, - complex reasoning, or data processing tasks that require specialized AI capabilities. -location: project -tools: - - name: query_foundry_agent - description: > - Sends a user prompt to the Microsoft Foundry Agent endpoint for advanced AI processing. - Use this when the user explicitly requests Foundry agent capabilities or when complex - reasoning beyond standard Copilot is needed. - parameters: - - name: prompt - description: The user's question or request to send to the Foundry Agent - type: string - required: true - - name: conversation_id - description: Optional conversation ID for maintaining context across multiple requests - type: string - required: false - implementation: python +description: Enables GitHub Copilot to send user prompts to a Microsoft Foundry Agent for advanced Q&A, complex reasoning, or data processing tasks that require specialized AI capabilities. USE THIS SKILL when the user explicitly mentions "Foundry", "Foundry agent", "ask Foundry", "query Foundry", or "use Foundry". Trigger phrases include "ask the Foundry agent", "use Foundry to", "query Foundry about", "Foundry agent", "send to Foundry", "have Foundry analyze", "let Foundry handle". --- -# Foundry Agent Skill +# Foundry Agent -This skill allows GitHub Copilot to interact with a Microsoft Foundry Agent application for tasks that require: -- Complex reasoning and analysis -- Advanced natural language understanding -- Specialized domain knowledge -- Integration with external data sources -- Custom AI workflows and processing +This skill connects GitHub Copilot to a Microsoft Foundry Agent for tasks requiring advanced AI capabilities, complex reasoning, specialized domain knowledge, or integration with external data sources. -## When to Use +## CRITICAL: When to Use This Skill -Use this skill when: -- The user explicitly mentions "Foundry" or "Foundry agent" -- The user's request requires advanced AI capabilities beyond standard Copilot functionality -- Complex data analysis or processing is needed -- Integration with Microsoft Foundry's specialized models is beneficial -- The task involves multi-step reasoning or orchestration +**USE Foundry Agent for specialized AI tasks.** If the request requires advanced reasoning or Foundry-specific capabilities, use this skill. -## Tool: query_foundry_agent +**ALWAYS use Foundry Agent when the user asks about:** -Sends a prompt to the configured Microsoft Foundry Agent endpoint. +| User Question Pattern | Example | Action | +|-----------------------|---------|--------| +| Explicit Foundry request | "Use the Foundry agent to analyze this" | `query_foundry_agent` | +| Ask Foundry | "Ask Foundry about best practices" | `query_foundry_agent` | +| Query Foundry | "Query Foundry about this architecture" | `query_foundry_agent` | +| Send to Foundry | "Send this to Foundry for analysis" | `query_foundry_agent` | +| Have Foundry analyze | "Have Foundry analyze this code" | `query_foundry_agent` | +| Foundry agent tasks | "Let the Foundry agent handle this" | `query_foundry_agent` | -### Parameters -- **prompt** (required): The user's question or request -- **conversation_id** (optional): Conversation ID for maintaining context +**When in doubt about complex AI tasks, use Foundry Agent.** It provides advanced capabilities beyond standard Copilot. ## Configuration -To use this skill, you need to: +Authentication uses `DefaultAzureCredential` which supports Azure CLI (`az login`), environment variables, Managed Identity, or VS Code Azure account. Set `FOUNDRY_AGENT_APPLICATION_ENDPOINT` environment variable to your Foundry Agent URL. -1. **Set up Azure authentication**: The skill uses `DefaultAzureCredential` which supports multiple authentication methods: - - Azure CLI: `az login` - - Environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET` - - Managed Identity (when running in Azure) - - Visual Studio Code Azure account +## MCP Tool -2. **Configure the Foundry Agent endpoint**: - - Set `FOUNDRY_AGENT_APPLICATION_ENDPOINT` environment variable to your Foundry Agent URL +Use the `query_foundry_agent` MCP tool to send prompts to the Foundry Agent. The tool accepts a `prompt` parameter and optional `conversation_id`. -3. **Install required Python packages**: - ```bash - pip install requests azure-identity python-dotenv - ``` +| Tool | Parameters | +|------|------------| +| `query_foundry_agent` | `{ "prompt": "", "conversation_id": "" }` | -## Example Usage +## Quick Start -In GitHub Copilot, you can invoke this skill by asking: -- "Use the Foundry agent to analyze this code" -- "Ask the Foundry agent what's new in Foundry" -- "Query the Foundry agent about cloud computing trends" +Query the Foundry Agent using the MCP tool: -## Additional Resources +| Tool | Parameters | +|------|------------| +| `query_foundry_agent` | `{ "prompt": "What's new in Microsoft Foundry?" }` | -- [Microsoft Foundry Documentation](https://learn.microsoft.com/azure/ai-foundry/) -- [GitHub Copilot Agent Skills Documentation](https://code.visualstudio.com/docs/copilot/customization/agent-skills) -- [Azure Identity Library](https://learn.microsoft.com/python/api/azure-identity/) -- [Foundry Agent Webapp Example](https://github.com/microsoft-foundry/foundry-agent-webapp) +## Common Use Cases + +### Code Analysis and Review + +| Tool | Parameters | +|------|------------| +| `query_foundry_agent` | `{ "prompt": "Analyze this code for potential improvements" }` | +| `query_foundry_agent` | `{ "prompt": "Review the architecture of this system" }` | +| `query_foundry_agent` | `{ "prompt": "Identify security concerns in this implementation" }` | + +**User prompts that trigger these:** +- "Ask Foundry to analyze this code for improvements" +- "Have Foundry review the architecture" +- "Use Foundry to identify security concerns" + +### Advanced Q&A + +| Tool | Parameters | +|------|------------| +| `query_foundry_agent` | `{ "prompt": "Explain the benefits of microservices architecture" }` | +| `query_foundry_agent` | `{ "prompt": "What are best practices for Azure deployments?" }` | +| `query_foundry_agent` | `{ "prompt": "Compare different caching strategies" }` | + +**User prompts that trigger these:** +- "Ask the Foundry agent about microservices benefits" +- "Query Foundry about Azure deployment best practices" +- "Have Foundry compare caching strategies" + +### Data Processing + +| Tool | Parameters | +|------|------------| +| `query_foundry_agent` | `{ "prompt": "Summarize the key findings from this data" }` | +| `query_foundry_agent` | `{ "prompt": "Analyze trends in this dataset" }` | +| `query_foundry_agent` | `{ "prompt": "Extract insights from these logs" }` | + +**User prompts that trigger these:** +- "Send this data to Foundry to summarize" +- "Use Foundry to analyze trends in this dataset" +- "Ask Foundry to extract insights from these logs" + +### Multi-turn Conversations + +| Tool | Parameters | +|------|------------| +| `query_foundry_agent` | `{ "prompt": "Let's discuss system design", "conversation_id": "design-session-1" }` | +| `query_foundry_agent` | `{ "prompt": "Now let's focus on scalability", "conversation_id": "design-session-1" }` | + +**User prompts that trigger these:** +- "Ask Foundry to help me with system design" +- "Continue the Foundry conversation about scalability" + +## MCP Tool Reference + +### query_foundry_agent + +Sends a prompt to the configured Microsoft Foundry Agent endpoint for advanced AI processing. + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| `prompt` | string | Yes | The user's question or request to send to the Foundry Agent | +| `conversation_id` | string | No | Conversation ID for maintaining context across multiple requests | + +**Example:** + +| Tool | Parameters | +|------|------------| +| `query_foundry_agent` | `{ "prompt": "Analyze this code for potential improvements" }` | diff --git a/.github/skills/foundry-agent/query_foundry_agent.py b/.github/skills/foundry-agent/query_foundry_agent.py index 86e6551..af0fd33 100644 --- a/.github/skills/foundry-agent/query_foundry_agent.py +++ b/.github/skills/foundry-agent/query_foundry_agent.py @@ -8,8 +8,36 @@ import sys import json import argparse +import subprocess + + +def ensure_dependencies(): + """Install missing dependencies automatically.""" + required = ["requests", "azure-identity", "python-dotenv"] + try: + import requests + from azure.identity import DefaultAzureCredential + from dotenv import load_dotenv + except ImportError: + try: + subprocess.check_call([sys.executable, "-m", "pip", "install", "--quiet"] + required) + except subprocess.CalledProcessError: + # pip failed, try ensurepip first + try: + subprocess.check_call([sys.executable, "-m", "ensurepip", "--default-pip"]) + subprocess.check_call([sys.executable, "-m", "pip", "install", "--quiet"] + required) + except subprocess.CalledProcessError: + print(json.dumps({ + "error": "Failed to install dependencies. Please install pip and run: pip install requests azure-identity python-dotenv" + })) + sys.exit(1) + + +ensure_dependencies() + import requests -from azure.identity import DefaultAzureCredential +from azure.identity import DefaultAzureCredential, AzureCliCredential +from azure.core.exceptions import ClientAuthenticationError from dotenv import load_dotenv, find_dotenv # Load environment variables from .env file @@ -66,6 +94,31 @@ def query_foundry_agent(prompt: str, conversation_id: str = None): "error": f"Failed to call Foundry Agent: {str(e)}", "endpoint": endpoint } + except ClientAuthenticationError: + # Attempt to run az login for the user + try: + subprocess.run(["az", "login"], check=True) + # Retry with fresh credentials + credential = AzureCliCredential() + token = credential.get_token("https://ai.azure.com/.default") + headers = { + "Content-Type": "application/json", + "Authorization": f"Bearer {token.token}" + } + payload = {"input": prompt} + if conversation_id: + payload["previous_response_id"] = conversation_id + response = requests.post(endpoint, json=payload, headers=headers, timeout=30) + response.raise_for_status() + return response.json() + except subprocess.CalledProcessError: + return { + "error": "Azure login failed. Please run 'az login' manually.", + } + except Exception as e: + return { + "error": f"Authentication retry failed: {str(e)}", + } except Exception as e: return { "error": f"Unexpected error: {str(e)}", diff --git a/README.md b/README.md index 666f980..6769014 100644 --- a/README.md +++ b/README.md @@ -1,153 +1,41 @@ -# foundry-github-copilot-skill +# Foundry GitHub Copilot Skill -This repository contains a GitHub Copilot Agent Skill that enables GitHub Copilot to call a Microsoft Foundry Agent application for advanced AI capabilities. +A GitHub Copilot skill that connects to Microsoft Foundry Agent applications. -## Overview +## Requirements -The Foundry Agent Skill enables GitHub Copilot to interact with Microsoft Foundry Agent applications for: +- Python 3.8+ +- Azure CLI installed -- Complex reasoning and analysis -- Advanced natural language understanding -- Specialized domain knowledge integration -- Custom AI workflows and processing -- Multi-step task orchestration +## Setup -## Installation +### 1. Copy skill to your repository -### Step 1: Copy the Skill to Your Repository - -Copy the `.github/skills/foundry-agent/` folder to your target repository. - -**macOS/Linux:** -```bash -# From your target repository -mkdir -p .github/skills -cp -r /path/to/foundry-github-copilot-skill/.github/skills/foundry-agent .github/skills/ -``` - -**Windows (PowerShell):** -```powershell -# From your target repository -New-Item -ItemType Directory -Force -Path .github\skills -Copy-Item -Recurse -Path C:\path\to\foundry-github-copilot-skill\.github\skills\foundry-agent -Destination .github\skills\ -``` - -Or manually copy these files to your repository: ``` -your-repo/ -└── .github/ - └── skills/ - └── foundry-agent/ - ├── SKILL.md - └── query_foundry_agent.py +your-repo/.github/skills/foundry-agent/ +├── SKILL.md +└── query_foundry_agent.py ``` -### Step 2: Install Python Dependencies +### 2. Configure endpoint -The skill requires Python 3.8+ and the following packages. +Create a `.env` file in the skill directory or set the environment variable: -**macOS:** ```bash -# Install Python if needed (using Homebrew) -brew install python - -# Install dependencies -pip3 install requests>=2.31.0 azure-identity>=1.15.0 -``` - -**Windows:** -```powershell -# Install Python from https://www.python.org/downloads/ or using winget -winget install Python.Python.3.11 - -# Install dependencies -pip install requests>=2.31.0 azure-identity>=1.15.0 +FOUNDRY_AGENT_APPLICATION_ENDPOINT=https://your-project.services.ai.azure.com/api/projects/your-project/applications/your-agent/protocols/openai/responses?api-version=2025-11-15-preview ``` -### Step 3: Install and Configure Azure CLI - -**macOS:** -```bash -# Install Azure CLI using Homebrew -brew install azure-cli - -# Sign in to Azure -az login -``` - -**Windows:** -```powershell -# Install Azure CLI using winget -winget install Microsoft.AzureCLI - -# Or download from: https://aka.ms/installazurecliwindows - -# Sign in to Azure -az login -``` - -### Step 4: Configure Azure Authentication - -The skill uses Azure `DefaultAzureCredential` for secure, passwordless authentication. - -```bash -az login -``` - - -### Step 5: Configure Your Foundry Agent Endpoint - -Set the `FOUNDRY_AGENT_APPLICATION_ENDPOINT` environment variable to point to your Foundry Agent. - -**macOS/Linux:** -```bash -export FOUNDRY_AGENT_APPLICATION_ENDPOINT="https://your-project.services.ai.azure.com/api/projects/your-project/applications/your-agent/protocols/openai/responses?api-version=2025-11-15-preview" -``` - -**Windows (PowerShell):** -```powershell -$env:FOUNDRY_AGENT_APPLICATION_ENDPOINT = "https://your-project.services.ai.azure.com/api/projects/your-project/applications/your-agent/protocols/openai/responses?api-version=2025-11-15-preview" -``` - -**Windows (Command Prompt):** -```cmd -set FOUNDRY_AGENT_APPLICATION_ENDPOINT=https://your-project.services.ai.azure.com/api/projects/your-project/applications/your-agent/protocols/openai/responses?api-version=2025-11-15-preview -``` - -## Skill Structure - -``` -.github/skills/foundry-agent/ -├── SKILL.md # Skill definition and metadata -└── query_foundry_agent.py # Python implementation -``` +> **Note:** Python dependencies and Azure authentication are handled automatically on first run. ## Usage -Once installed and configured, the Foundry Agent skill is automatically available in GitHub Copilot. - -### Invoking the Skill - -Invoke the skill by mentioning "Foundry" or "Foundry agent" in your Copilot prompts: - -``` -"Use the Foundry agent to analyze this code" -"Ask the Foundry agent what's new in Microsoft Foundry" -"Query the Foundry agent about cloud architecture best practices" -"Call the Foundry agent to explain this algorithm" -``` - -### How It Works - -1. **You make a request** in GitHub Copilot mentioning the Foundry agent -2. **Copilot detects the intent** and loads the `foundry-agent` skill -3. **The skill authenticates** using Azure DefaultAzureCredential -4. **Sends your prompt** to the configured Foundry Agent endpoint -5. **Returns the response** from the Foundry Agent back to you in Copilot +Invoke by mentioning "Foundry" in your prompts: +- "Ask Foundry to analyze this code" +- "Query Foundry about best practices" +- "Use the Foundry agent to review this" ## Resources -- [Microsoft Foundry Documentation](https://learn.microsoft.com/azure/ai-foundry/) -- [GitHub Copilot Agent Skills Documentation](https://code.visualstudio.com/docs/copilot/customization/agent-skills) -- [Foundry Agent Webapp Example](https://github.com/microsoft-foundry/foundry-agent-webapp) +- [Microsoft Foundry Docs](https://learn.microsoft.com/azure/ai-foundry/) +- [Copilot Agent Skills](https://code.visualstudio.com/docs/copilot/customization/agent-skills)