{ "cells": [ { "cell_type": "markdown", "id": "2b91961c", "metadata": {}, "source": [ "## Két egymást követő ügynök:\n", "\n", "1. **Recepciós ügynök**: Kezdeti városi látnivaló ajánlásokat tesz\n", "2. **Concierge ügynök**: Áttekinti és értékeli a recepciós ajánlását a népszerűség alapján\n", "\n", "## Az egymás utáni összehangolás fő előnyei:\n", "\n", "- **Ismétlődő finomítás**: A második ügynök javítja az első ügynök munkáját\n", "- **Specializáció**: Minden ügynöknek speciális szerepe van a folyamatban\n", "- **Minőségellenőrzés**: Beépített átnézési és érvényesítési lépés\n", "- **Világos információáramlás**: Strukturált átadás az ügynökök között\n", "\n", "## Előfeltételek:\n", "- Telepítve a Microsoft Agent Framework\n", "- Azure AI Foundry projekt végpont és modell telepítés konfigurálva (`AZURE_AI_PROJECT_ENDPOINT`, `AZURE_AI_MODEL_DEPLOYMENT_NAME`)\n", "- Azure CLI-val hitelesítve (`az login`)\n", "- Alapvető ügynökfogalmak megértése\n" ] }, { "cell_type": "code", "execution_count": null, "id": "0981c0bb", "metadata": {}, "outputs": [], "source": [ "import asyncio\n", "import json\n", "import os\n", "from typing import Any, cast\n", "\n", "from agent_framework import Message, WorkflowBuilder\n", "from agent_framework.azure import AzureAIProjectAgentProvider\n", "from azure.identity import AzureCliCredential\n", "from dotenv import load_dotenv\n", "from IPython.display import HTML, display\n", "from pydantic import BaseModel\n", "\n", "print(\"All imports successful!\")" ] }, { "cell_type": "markdown", "id": "790b74bd", "metadata": {}, "source": [ "## 1. lépés: Pydantic modellek definiálása strukturált kimenetekhez\n", "\n", "Ezek a modellek határozzák meg a sémát, amelyet minden ügynök vissza fog adni. A recepciós ügynök egy ajánlást nyújt, a concierge ügynök pedig egy értékelést és minősítést ad.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "3436dc8d", "metadata": {}, "outputs": [], "source": [ "class AttractionRecommendation(BaseModel):\n", " \"\"\"Attraction recommendation from the front desk agent.\"\"\"\n", "\n", " city: str\n", " attraction_name: str\n", " description: str\n", " category: str # e.g., \"museum\", \"landmark\", \"park\", \"entertainment\"\n", " recommended_duration: str # e.g., \"2-3 hours\", \"half day\"\n", " why_recommended: str\n", " best_time_to_visit: str\n", "\n", "\n", "class AttractionReview(BaseModel):\n", " \"\"\"Expert review and rating from the concierge agent.\"\"\"\n", "\n", " attraction_name: str\n", " city: str\n", " popularity_score: int # 1-10 scale\n", " popularity_reasoning: str\n", " visitor_rating: float # 1.0-5.0 scale\n", " pros: list[str]\n", " cons: list[str]\n", " concierge_recommendation: str\n", " alternative_suggestions: list[str]" ] }, { "cell_type": "markdown", "id": "f4269b29", "metadata": {}, "source": [ "## 2. lépés: Környezeti változók betöltése és a Foundry szolgáltató konfigurálása\n", "\n", "Használja az `AzureAIProjectAgentProvider`-t kulcs nélküli `AzureCliCredential` hitelesítéssel, az 01–13. leckékben alkalmazott mintának megfelelően.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "2152c7d3", "metadata": {}, "outputs": [], "source": [ "# Load environment variables\n", "load_dotenv()\n", "\n", "# Configure the Azure AI Foundry provider with keyless authentication\n", "provider = AzureAIProjectAgentProvider(credential=AzureCliCredential())\n", "\n", "print(\"Azure AI Foundry provider configured successfully!\")" ] }, { "cell_type": "markdown", "id": "e63c63dd", "metadata": {}, "source": [ "## 3. lépés: Két szekvenciális ügynök létrehozása\n", "\n", "Minden ügynöknek meghatározott szerepe van a szekvenciális munkafolyamatban. A recepciós ügynök javaslatokat tesz, a concierge ügynök pedig felülvizsgálja és értékeli azokat.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "3f862eee", "metadata": {}, "outputs": [], "source": [ "# Agent 1: Front Desk Agent (Makes initial recommendations)\n", "front_desk_agent = await provider.create_agent(\n", " name=\"front-desk-agent\",\n", " instructions=(\n", " \"You are a knowledgeable hotel front desk agent who specializes in local attractions. \"\n", " \"When a guest asks about attractions in a city, provide a single, well-researched recommendation \"\n", " \"for a popular tourist attraction. Focus on giving practical information including what makes \"\n", " \"this attraction special, how long to spend there, and the best time to visit. \"\n", " \"Be helpful and enthusiastic about your recommendation. \"\n", " \"Return structured JSON matching the AttractionRecommendation schema.\"\n", " ),\n", ")\n", "\n", "# Agent 2: Concierge Agent (Reviews and rates recommendations)\n", "concierge_agent = await provider.create_agent(\n", " name=\"concierge-agent\",\n", " instructions=(\n", " \"You are an expert concierge with extensive knowledge of tourist attractions worldwide. \"\n", " \"You will receive an attraction recommendation and must provide an expert review and rating. \"\n", " \"Evaluate the recommendation based on the attraction's popularity, visitor satisfaction, \"\n", " \"and overall quality. Provide a popularity score (1-10), visitor rating (1.0-5.0), \"\n", " \"list pros and cons, and give your professional assessment. \"\n", " \"Also suggest alternative attractions if appropriate. \"\n", " \"Return structured JSON matching the AttractionReview schema.\"\n", " ),\n", ")\n" ] }, { "cell_type": "markdown", "id": "0afa99f5", "metadata": {}, "source": [ "## 4. lépés: Az egymás utáni munkafolyamat felépítése\n", "\n", "A `WorkflowBuilder` létrehoz egy munkafolyamatot, ahol:\n", "1. A **Recepciós ügynök** fogadja a felhasználói bemenetet és ajánlást tesz\n", "2. A **Konzierzs ügynök** megkapja a recepciós ajánlását, és szakértői véleményt ad\n", "3. A **Kimenet** tartalmazza mind az eredeti ajánlást, mind a szakértői véleményt\n" ] }, { "cell_type": "code", "execution_count": null, "id": "d76c5b11", "metadata": {}, "outputs": [], "source": [ "# Build the sequential workflow with WorkflowBuilder\n", "workflow = (\n", " WorkflowBuilder(\n", " start_executor=front_desk_agent,\n", " output_executors=[front_desk_agent, concierge_agent],\n", " )\n", " .add_edge(front_desk_agent, concierge_agent)\n", " .build()\n", ")\n", "\n", "display(HTML(\"\"\"\n", "
\n",
" Flow:
\n",
" • User Input → Front Desk Agent (recommendation)
\n",
" • Front Desk Output → Concierge Agent (review & rating)
\n",
" • Final Output → Combined recommendation + expert review\n",
"
Status: Running sequential workflow...
\n", "Generated by sequential agent workflow
\n", "Examining agent interactions and information handoff...
\n", "