{ "cells": [ { "cell_type": "markdown", "id": "43adcae5", "metadata": {}, "source": [ "# 🚀 Exploring Agent Framework with GitHub Models (Python)\n", "\n", "## 📋 GitHub Models Integration Tutorial\n", "\n", "This notebook explores the integration between Microsoft Agent Framework and **GitHub Models**, GitHub's AI model inference service. Learn how to build intelligent agents that leverage cutting-edge AI models through GitHub's managed infrastructure.\n", "\n", "## 🎯 Learning Objectives\n", "\n", "### 🌐 **GitHub Models Platform**\n", "- **Model Access**: Leveraging GitHub's curated collection of AI models\n", "- **API Integration**: Connecting to GitHub's model inference endpoints\n", "- **Cost-Effective AI**: Using GitHub's competitive pricing for AI workloads\n", "- **Developer-Friendly**: GitHub-native AI development experience\n", "\n", "### 🔧 **Technical Integration**\n", "- **OpenAI Compatibility**: Using OpenAI client patterns with GitHub Models\n", "- **Environment Configuration**: Secure credential management with GitHub tokens\n", "- **Streaming Responses**: Real-time agent interactions and response processing\n", "- **Error Handling**: Robust error management for production deployments\n", "\n", "### 🏢 **Enterprise Benefits**\n", "- **GitHub Ecosystem**: Native integration with GitHub development workflows\n", "- **Security**: GitHub's enterprise-grade security and compliance\n", "- **Scalability**: Global infrastructure with automatic scaling\n", "- **Cost Management**: Transparent usage tracking and billing\n", "\n", "## ⚙️ Prerequisites & Setup\n", "\n", "### 📦 **Required Dependencies**\n", "\n", "Install the Agent Framework with complete dependencies:\n", "\n", "```bash\n", "pip install agent-framework-core -U\n", "```\n", "\n", "### 🔑 **GitHub Models Configuration**\n", "\n", "**Setup Requirements:**\n", "1. **GitHub Models Access**: Request access to GitHub Models (currently in preview)\n", "2. **Personal Access Token**: Generate a token with model access permissions\n", "3. **Environment Variables**: Configure API credentials securely\n", "\n", "**Environment Configuration (.env file):**\n", "```env\n", "GITHUB_TOKEN=your_github_personal_access_token\n", "GITHUB_ENDPOINT=https://models.inference.ai.azure.com\n", "GITHUB_MODEL_ID=gpt-4o-mini\n", "```\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "9e2c4c8d", "metadata": {}, "outputs": [], "source": [ "# ! pip install -r ../../../Installation/requirements.txt -U" ] }, { "cell_type": "code", "execution_count": 2, "id": "b6280fda", "metadata": {}, "outputs": [], "source": [ "# 📦 Import Essential Libraries\n", "# Core system utilities and environment configuration\n", "\n", "import os # Environment variable access\n", "from dotenv import load_dotenv # Secure environment configuration loading" ] }, { "cell_type": "code", "execution_count": 3, "id": "b63147e1", "metadata": {}, "outputs": [], "source": [ "# 🤖 Import Microsoft Agent Framework with GitHub Models Support\n", "# Agent Framework components for building intelligent conversational agents\n", "from agent_framework import Agent\n", "from agent_framework.openai import OpenAIChatCompletionClient" ] }, { "cell_type": "code", "execution_count": 4, "id": "d95ec338", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 🔧 Load Environment Configuration\n", "# Initialize API credentials from .env file for secure access to GitHub Models\n", "load_dotenv()" ] }, { "cell_type": "code", "execution_count": 5, "id": "a312a074", "metadata": {}, "outputs": [], "source": [ "# 🔗 Initialize GitHub Models Client\n", "# Create the API client that connects to GitHub's AI model inference service\n", "openai_chat_client = OpenAIChatCompletionClient(\n", " base_url=os.environ.get(\"GITHUB_ENDPOINT\"), # GitHub Models endpoint\n", " api_key=os.environ.get(\"GITHUB_TOKEN\"), # GitHub personal access token\n", " model=os.environ.get(\"GITHUB_MODEL_ID\") # Selected model (e.g., gpt-4o-mini)\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "id": "cde85093", "metadata": {}, "outputs": [], "source": [ "# 🤖 Create AI Agent with GitHub Models Integration\n", "# Build an intelligent agent powered by GitHub's model infrastructure\n", "agent = Agent(\n", " client=openai_chat_client, # 🔗 GitHub Models connection\n", " instructions=\"You are a helpful weather agent.\" # 📝 Agent role and personality\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "id": "781c7c2a", "metadata": {}, "outputs": [], "source": [ "# 🎯 Test Your GitHub Models Agent\n", "# Send a creative writing request to demonstrate agent capabilities\n", "query = \"Write a haiku about Agent Framework.\"\n", "response = await agent.run(query)" ] }, { "cell_type": "code", "execution_count": 8, "id": "25b44f81", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "🤖 AI-Generated Haiku:\n", "==============================\n", "Agents work as one, \n", "Framework weaves their tasks with care, \n", "Harmony in code.\n", "==============================\n", "✨ Powered by GitHub Models via Microsoft Agent Framework!\n" ] } ], "source": [ "# 📖 Display the Agent's Creative Response\n", "# Extract and show the AI-generated haiku about Agent Framework\n", "last_message = response.messages[-1]\n", "text_content = last_message.contents[0].text\n", "\n", "print(\"🤖 AI-Generated Haiku:\")\n", "print(\"=\" * 30)\n", "print(text_content)\n", "print(\"=\" * 30)\n", "print(\"✨ Powered by GitHub Models via Microsoft Agent Framework!\")" ] } ], "metadata": { "kernelspec": { "display_name": "agentdev", "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.12.10" } }, "nbformat": 4, "nbformat_minor": 5 }