From a2408d3ee18853241eb8af87475919526c9a3f07 Mon Sep 17 00:00:00 2001 From: AgentGenie Date: Tue, 3 Dec 2024 13:08:28 -0800 Subject: [PATCH 01/20] GraphRAG Demo: Data Setup --- .pre-commit-config.yaml | 3 +- ...gentchat_swarm_graphrag_trip_planner.ipynb | 353 ++++++++++++++++++ .../trip_planner_data/attractions.json | 142 +++++++ .../graph_rag/trip_planner_data/cities.json | 72 ++++ .../trip_planner_data/restaurants.json | 90 +++++ 5 files changed, 659 insertions(+), 1 deletion(-) create mode 100644 notebook/agentchat_swarm_graphrag_trip_planner.ipynb create mode 100644 test/agentchat/contrib/graph_rag/trip_planner_data/attractions.json create mode 100644 test/agentchat/contrib/graph_rag/trip_planner_data/cities.json create mode 100644 test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ae197c54e4..57db0b7fb4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,7 +47,8 @@ repos: website/docs/tutorial/code-executors.ipynb | website/docs/topics/code-execution/custom-executor.ipynb | website/docs/topics/non-openai-models/cloud-gemini.ipynb | - notebook/.* + notebook/.* | + test/agentchat/contrib/graph_rag/trip_planner_data/.* )$ # See https://jaredkhan.com/blog/mypy-pre-commit - repo: local diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb new file mode 100644 index 0000000000..0e6673f233 --- /dev/null +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -0,0 +1,353 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "import autogen\n", + "\n", + "config_list = autogen.config_list_from_json(env_or_file=\"../OAI_CONFIG_LIST\")\n", + "\n", + "# Put the OpenAI API key into the environment\n", + "os.environ[\"OPENAI_API_KEY\"] = config_list[0][\"api_key\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from graphrag_sdk import (\n", + " Attribute,\n", + " AttributeType,\n", + " Entity,\n", + " Ontology,\n", + " Relation,\n", + ")\n", + "\n", + "# Attraction + Restaurant + City + Country Ontology\n", + "trip_data_ontology = Ontology()\n", + "\n", + "\n", + "# Manually created Ontology by adding entities and relations\n", + "trip_data_ontology.add_entity(\n", + " Entity(\n", + " label=\"Country\",\n", + " attributes=[\n", + " Attribute(\n", + " name=\"name\",\n", + " attr_type=AttributeType.STRING,\n", + " required=True,\n", + " unique=True,\n", + " ),\n", + " ],\n", + " )\n", + ")\n", + "trip_data_ontology.add_entity(\n", + " Entity(\n", + " label=\"City\",\n", + " attributes=[\n", + " Attribute(\n", + " name=\"name\",\n", + " attr_type=AttributeType.STRING,\n", + " required=True,\n", + " unique=True,\n", + " ),\n", + " Attribute(\n", + " name=\"weather\",\n", + " attr_type=AttributeType.STRING,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " Attribute(\n", + " name=\"population\",\n", + " attr_type=AttributeType.NUMBER,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " ],\n", + " )\n", + ")\n", + "trip_data_ontology.add_entity(\n", + " Entity(\n", + " label=\"Restaurant\",\n", + " attributes=[\n", + " Attribute(\n", + " name=\"name\",\n", + " attr_type=AttributeType.STRING,\n", + " required=True,\n", + " unique=True,\n", + " ),\n", + " Attribute(\n", + " name=\"description\",\n", + " attr_type=AttributeType.STRING,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " Attribute(\n", + " name=\"rating\",\n", + " attr_type=AttributeType.NUMBER,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " Attribute(\n", + " name=\"food_type\",\n", + " attr_type=AttributeType.STRING,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " ],\n", + " )\n", + ")\n", + "trip_data_ontology.add_relation(\n", + " Relation(\n", + " label=\"IN_COUNTRY\",\n", + " source=\"City\",\n", + " target=\"Country\",\n", + " )\n", + ")\n", + "trip_data_ontology.add_relation(\n", + " Relation(\n", + " label=\"IN_CITY\",\n", + " source=\"Restaurant\",\n", + " target=\"City\",\n", + " )\n", + ")\n", + "\n", + "trip_data_ontology.add_entity(\n", + " Entity(\n", + " label=\"Country\",\n", + " attributes=[\n", + " Attribute(\n", + " name=\"name\",\n", + " attr_type=AttributeType.STRING,\n", + " required=True,\n", + " unique=True,\n", + " ),\n", + " ],\n", + " )\n", + ")\n", + "trip_data_ontology.add_entity(\n", + " Entity(\n", + " label=\"City\",\n", + " attributes=[\n", + " Attribute(\n", + " name=\"name\",\n", + " attr_type=AttributeType.STRING,\n", + " required=True,\n", + " unique=True,\n", + " ),\n", + " Attribute(\n", + " name=\"weather\",\n", + " attr_type=AttributeType.STRING,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " Attribute(\n", + " name=\"population\",\n", + " attr_type=AttributeType.NUMBER,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " ],\n", + " )\n", + ")\n", + "trip_data_ontology.add_entity(\n", + " Entity(\n", + " label=\"Attraction\",\n", + " attributes=[\n", + " Attribute(\n", + " name=\"name\",\n", + " attr_type=AttributeType.STRING,\n", + " required=True,\n", + " unique=True,\n", + " ),\n", + " Attribute(\n", + " name=\"description\",\n", + " attr_type=AttributeType.STRING,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " Attribute(\n", + " name=\"type\",\n", + " attr_type=AttributeType.STRING,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " ],\n", + " )\n", + ")\n", + "trip_data_ontology.add_relation(\n", + " Relation(\n", + " label=\"IN_COUNTRY\",\n", + " source=\"City\",\n", + " target=\"Country\",\n", + " )\n", + ")\n", + "trip_data_ontology.add_relation(\n", + " Relation(\n", + " label=\"IN_CITY\",\n", + " source=\"Attraction\",\n", + " target=\"City\",\n", + " )\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33muser_proxy\u001b[0m (to graph_rag_agent):\n", + "\n", + "Find 3 restaurant in Milan.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33mgraph_rag_agent\u001b[0m (to user_proxy):\n", + "\n", + "Bros' Burger in Milan is known for its gourmet burgers and offers a relaxed vibe.\n", + "\n", + "--------------------------------------------------------------------------------\n" + ] + }, + { + "data": { + "text/plain": [ + "ChatResult(chat_id=None, chat_history=[{'content': 'Find 3 restaurant in Milan.', 'role': 'assistant', 'name': 'user_proxy'}, {'content': \"Bros' Burger in Milan is known for its gourmet burgers and offers a relaxed vibe.\", 'role': 'user', 'name': 'graph_rag_agent'}], summary=\"Bros' Burger in Milan is known for its gourmet burgers and offers a relaxed vibe.\", cost={'usage_including_cached_inference': {'total_cost': 0}, 'usage_excluding_cached_inference': {'total_cost': 0}}, human_input=['exit'])" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from autogen import ConversableAgent, UserProxyAgent\n", + "from autogen.agentchat.contrib.graph_rag.document import Document, DocumentType\n", + "from autogen.agentchat.contrib.graph_rag.falkor_graph_query_engine import FalkorGraphQueryEngine\n", + "from autogen.agentchat.contrib.graph_rag.falkor_graph_rag_capability import FalkorGraphRagCapability\n", + "\n", + "# Auto generate graph schema from unstructured data\n", + "input_paths = [\n", + " \"../test/agentchat/contrib/graph_rag/trip_planner_data/attractions.json\",\n", + " \"../test/agentchat/contrib/graph_rag/trip_planner_data/cities.json\",\n", + " \"../test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json\",\n", + "]\n", + "input_documents = [Document(doctype=DocumentType.TEXT, path_or_url=input_path) for input_path in input_paths]\n", + "\n", + "# Create FalkorGraphQueryEngine\n", + "query_engine = FalkorGraphQueryEngine(\n", + " name=\"trip_data\",\n", + " host=\"172.18.0.3\", # Change\n", + " port=6379, # if needed\n", + " ontology=trip_data_ontology,\n", + ")\n", + "\n", + "# Ingest data and initialize the database\n", + "query_engine.init_db(input_doc=input_documents)\n", + "\n", + "# Create a ConversableAgent (no LLM configuration)\n", + "graph_rag_agent = ConversableAgent(\n", + " name=\"graph_rag_agent\",\n", + " human_input_mode=\"NEVER\",\n", + ")\n", + "\n", + "# Associate the capability with the agent\n", + "graph_rag_capability = FalkorGraphRagCapability(query_engine)\n", + "graph_rag_capability.add_to_agent(graph_rag_agent)\n", + "\n", + "# Create a user proxy agent to converse with our RAG agent\n", + "user_proxy = UserProxyAgent(\n", + " name=\"user_proxy\",\n", + " human_input_mode=\"ALWAYS\",\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33muser_proxy\u001b[0m (to graph_rag_agent):\n", + "\n", + "Find 3 restaurants in Rome.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33mgraph_rag_agent\u001b[0m (to user_proxy):\n", + "\n", + "Three restaurants in Rome are Trattoria da Enzo, known for its traditional Roman dishes and welcoming atmosphere; Il Pagliaccio, an elegant Michelin-starred restaurant offering contemporary Italian cuisine; and Tonnarello, a casual spot for pasta, meatballs, and other simple Roman dishes with patio seating and acoustic guitar music.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33muser_proxy\u001b[0m (to graph_rag_agent):\n", + "\n", + "Find 3 attractions in Rome.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33mgraph_rag_agent\u001b[0m (to user_proxy):\n", + "\n", + "Three attractions in Rome are the Colosseum, an ancient amphitheater known for gladiatorial contests and public spectacles; the Vatican Museums, a complex of museums and galleries showcasing works of art collected by Popes over centuries; and the Trevi Fountain, a Baroque fountain famous for its stunning sculptures and the tradition of tossing coins.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33muser_proxy\u001b[0m (to graph_rag_agent):\n", + "\n", + "How many attractions in Rome are in the database?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33mgraph_rag_agent\u001b[0m (to user_proxy):\n", + "\n", + "There are 4 attractions in Rome listed in the database.\n", + "\n", + "--------------------------------------------------------------------------------\n" + ] + }, + { + "data": { + "text/plain": [ + "ChatResult(chat_id=None, chat_history=[{'content': 'Find 3 restaurants in Rome.', 'role': 'assistant', 'name': 'user_proxy'}, {'content': 'Three restaurants in Rome are Trattoria da Enzo, known for its traditional Roman dishes and welcoming atmosphere; Il Pagliaccio, an elegant Michelin-starred restaurant offering contemporary Italian cuisine; and Tonnarello, a casual spot for pasta, meatballs, and other simple Roman dishes with patio seating and acoustic guitar music.', 'role': 'user', 'name': 'graph_rag_agent'}, {'content': 'Find 3 attractions in Rome.', 'role': 'assistant', 'name': 'user_proxy'}, {'content': 'Three attractions in Rome are the Colosseum, an ancient amphitheater known for gladiatorial contests and public spectacles; the Vatican Museums, a complex of museums and galleries showcasing works of art collected by Popes over centuries; and the Trevi Fountain, a Baroque fountain famous for its stunning sculptures and the tradition of tossing coins.', 'role': 'user', 'name': 'graph_rag_agent'}, {'content': 'How many attractions in Rome are in the database?', 'role': 'assistant', 'name': 'user_proxy'}, {'content': 'There are 4 attractions in Rome listed in the database.', 'role': 'user', 'name': 'graph_rag_agent'}], summary='There are 4 attractions in Rome listed in the database.', cost={'usage_including_cached_inference': {'total_cost': 0}, 'usage_excluding_cached_inference': {'total_cost': 0}}, human_input=['Find 3 attractions in Rome.', 'How many attractions in Rome are in the database?', 'exit'])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "user_proxy.initiate_chat(graph_rag_agent, message=\"Find 3 restaurants in Rome.\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.11.10" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/test/agentchat/contrib/graph_rag/trip_planner_data/attractions.json b/test/agentchat/contrib/graph_rag/trip_planner_data/attractions.json new file mode 100644 index 0000000000..c929eb4c0e --- /dev/null +++ b/test/agentchat/contrib/graph_rag/trip_planner_data/attractions.json @@ -0,0 +1,142 @@ +[ + { + "id": 1, + "name": "Colosseum", + "description": "An ancient amphitheater known for gladiatorial contests and public spectacles.", + "city": "Rome", + "type": "Historical" + }, + { + "id": 2, + "name": "Vatican Museums", + "description": "A complex of museums and galleries showcasing works of art collected by Popes over centuries.", + "city": "Rome", + "type": "Art" + }, + { + "id": 3, + "name": "Trevi Fountain", + "description": "A Baroque fountain known for its stunning sculptures and tradition of tossing coins.", + "city": "Rome", + "type": "Landmark" + }, + { + "id": 4, + "name": "Duomo", + "description": "Florence's main cathedral, known for its red-tiled dome designed by Brunelleschi.", + "city": "Florence", + "type": "Religious" + }, + { + "id": 5, + "name": "Uffizi Gallery", + "description": "A prominent art museum featuring works by Botticelli, Michelangelo, and da Vinci.", + "city": "Florence", + "type": "Art" + }, + { + "id": 6, + "name": "Ponte Vecchio", + "description": "A medieval stone bridge over the Arno River, lined with shops selling jewelry and art.", + "city": "Florence", + "type": "Landmark" + }, + { + "id": 7, + "name": "Grand Canal", + "description": "The main waterway of Venice, lined with stunning palaces and bridges.", + "city": "Venice", + "type": "Scenic" + }, + { + "id": 8, + "name": "St. Mark's Basilica", + "description": "Venice's famous cathedral known for its Byzantine architecture and gilded mosaics.", + "city": "Venice", + "type": "Religious" + }, + { + "id": 9, + "name": "Rialto Bridge", + "description": "One of Venice's iconic bridges crossing the Grand Canal, offering beautiful views.", + "city": "Venice", + "type": "Landmark" + }, + { + "id": 10, + "name": "Mole Antonelliana", + "description": "A landmark building in Turin known for its towering spire and as the Museum of Cinema.", + "city": "Turin", + "type": "Landmark" + }, + { + "id": 11, + "name": "Royal Palace of Naples", + "description": "A historic palace in Naples, once home to the Bourbon Kings of Naples and Sicily.", + "city": "Naples", + "type": "Historical" + }, + { + "id": 12, + "name": "Teatro San Carlo", + "description": "The oldest continuously active opera house in the world, located in Naples.", + "city": "Naples", + "type": "Cultural" + }, + { + "id": 13, + "name": "Teatro alla Scala", + "description": "One of the world's most famous opera houses, located in Milan.", + "city": "Milan", + "type": "Cultural" + }, + { + "id": 14, + "name": "Galleria Vittorio Emanuele II", + "description": "A historic shopping arcade and a major landmark in Milan, known for its stunning architecture.", + "city": "Milan", + "type": "Landmark" + }, + { + "id": 15, + "name": "Teatro Regio", + "description": "A prominent opera house in Turin, known for its rich history and performances.", + "city": "Turin", + "type": "Cultural" + }, + { + "id": 16, + "name": "Palazzo dei Normanni", + "description": "A royal palace in Palermo, originally built in the 9th century.", + "city": "Palermo", + "type": "Historical" + }, + { + "id": 17, + "name": "Cattedrale di Palermo", + "description": "The cathedral church of the Roman Catholic Archdiocese of Palermo, dedicated to the Assumption of the Virgin Mary.", + "city": "Palermo", + "type": "Religious" + }, + { + "id": 18, + "name": "San Giovanni degli Eremiti", + "description": "A church in Palermo, renowned for its distinctive red domes.", + "city": "Palermo", + "type": "Religious" + }, + { + "id": 19, + "name": "San Lorenzo Maggiore", + "description": "A church in Naples, one of the oldest in the city, featuring Roman and early Christian remains.", + "city": "Naples", + "type": "Religious" + }, + { + "id": 20, + "name": "Basilica di Santa Maria Maggiore", + "description": "A major basilica in Rome, known for its rich history and impressive architecture.", + "city": "Rome", + "type": "Religious" + } +] diff --git a/test/agentchat/contrib/graph_rag/trip_planner_data/cities.json b/test/agentchat/contrib/graph_rag/trip_planner_data/cities.json new file mode 100644 index 0000000000..46eb4a98a0 --- /dev/null +++ b/test/agentchat/contrib/graph_rag/trip_planner_data/cities.json @@ -0,0 +1,72 @@ +[ + { + "id": 1, + "name": "Rome", + "country": "Italy", + "population": 2800000, + "weather": "Mediterranean" + }, + { + "id": 2, + "name": "Milan", + "country": "Italy", + "population": 1370000, + "weather": "Humid subtropical" + }, + { + "id": 3, + "name": "Naples", + "country": "Italy", + "population": 967000, + "weather": "Mediterranean" + }, + { + "id": 4, + "name": "Turin", + "country": "Italy", + "population": 875000, + "weather": "Humid subtropical" + }, + { + "id": 5, + "name": "Palermo", + "country": "Italy", + "population": 673000, + "weather": "Mediterranean" + }, + { + "id": 6, + "name": "Genoa", + "country": "Italy", + "population": 580000, + "weather": "Mediterranean" + }, + { + "id": 7, + "name": "Bologna", + "country": "Italy", + "population": 390000, + "weather": "Humid subtropical" + }, + { + "id": 8, + "name": "Florence", + "country": "Italy", + "population": 383000, + "weather": "Temperate" + }, + { + "id": 9, + "name": "Venice", + "country": "Italy", + "population": 260000, + "weather": "Humid subtropical" + }, + { + "id": 10, + "name": "Verona", + "country": "Italy", + "population": 258000, + "weather": "Humid subtropical" + } +] diff --git a/test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json b/test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json new file mode 100644 index 0000000000..70763a9111 --- /dev/null +++ b/test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json @@ -0,0 +1,90 @@ +[ + { + "id": 1, + "name": "Trattoria da Enzo", + "description": "A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.", + "city": "Rome", + "rating": 4.5, + "food_type": "Italian" + }, + { + "id": 2, + "name": "Il Pagliaccio", + "description": "An elegant Michelin-starred restaurant offering contemporary Italian cuisine.", + "city": "Rome", + "rating": 4.8, + "food_type": "Italian" + }, + { + "id": 3, + "name": "Bros' Burger", + "description": "A popular burger joint in Milan known for its gourmet burgers and relaxed vibe.", + "city": "Milan", + "rating": 4.3, + "food_type": "Burgers" + }, + { + "id": 4, + "name": "Osteria Francescana", + "description": "A world-renowned restaurant in Modena, known for its innovative Italian cuisine.", + "city": "Modena", + "rating": 4.9, + "food_type": "Italian" + }, + { + "id": 5, + "name": "La Bottega del Buon Caffè", + "description": "An upscale restaurant in Florence offering seasonal Tuscan cuisine with a modern twist.", + "city": "Florence", + "rating": 4.7, + "food_type": "Italian" + }, + { + "id": 6, + "name": "Antiche Carampane", + "description": "A charming trattoria in Venice known for its seafood dishes and Venetian specialties.", + "city": "Venice", + "rating": 4.6, + "food_type": "Seafood" + }, + { + "id": 7, + "name": "Ristorante Quadri", + "description": "A historic restaurant in Venice's Piazza San Marco, offering gourmet Italian cuisine.", + "city": "Venice", + "rating": 4.8, + "food_type": "Italian" + }, + { + "id": 8, + "name": "Da Cimino", + "description": "A family-run trattoria in Palermo known for its authentic Sicilian cuisine.", + "city": "Palermo", + "rating": 4.4, + "food_type": "Sicilian" + }, + { + "id": 9, + "name": "Il Gambero Rosso", + "description": "A renowned seafood restaurant in Naples, offering fresh catch of the day and traditional dishes.", + "city": "Naples", + "rating": 4.5, + "food_type": "Seafood" + }, + { + "id": 10, + "name": "Taverna del Capitano", + "description": "A charming restaurant in Sorrento known for its seafood and stunning views of the Bay of Naples.", + "city": "Sorrento", + "rating": 4.7, + "food_type": "Seafood" + }, + { + "id": 11, + "name": "Tonnarello", + "description": "Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.", + "city": "Rome", + "rating": 4.7, + "food_type": "Italian" + } +] From 2537fbf7f89bbbee244c00ddd5765cac0db1ff6f Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Tue, 3 Dec 2024 22:53:32 +0000 Subject: [PATCH 02/20] Added ability to connect to existing knowledge graph, falkordb added as requirement Signed-off-by: Mark Sze --- .../graph_rag/falkor_graph_query_engine.py | 55 ++++++++++++++----- setup.py | 4 +- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py index 114e6d8ed3..0721e4c549 100644 --- a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +++ b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py @@ -6,6 +6,7 @@ from dataclasses import dataclass, field from typing import List +from falkordb import FalkorDB from graphrag_sdk import KnowledgeGraph, Source from graphrag_sdk.model_config import KnowledgeGraphModelConfig from graphrag_sdk.models import GenerativeModel @@ -53,11 +54,43 @@ def __init__( self.model = model self.model_config = KnowledgeGraphModelConfig.with_model(model) self.ontology = ontology + self.knowledge_graph = None - def init_db(self, input_doc: List[Document] | None): + def connect_db(self): + """ + Connect to an existing knowledge graph. + """ + falkordb = FalkorDB(host=self.host, port=self.port, username=self.username, password=self.password) + if self.name in falkordb.list_graphs(): + self.knowledge_graph = KnowledgeGraph( + name=self.name, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + model_config=self.model_config, + ontology=self.ontology, + ) + + # Establishing a chat session will maintain the history + self._chat_session = self.knowledge_graph.chat_session() + else: + raise ValueError(f"Knowledge graph '{self.name}' does not exist") + + def init_db(self, input_doc: List[Document]): """ Build the knowledge graph with input documents. """ + self.knowledge_graph = KnowledgeGraph( + name=self.name, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + model_config=KnowledgeGraphModelConfig.with_model(self.model), + ontology=self.ontology, + ) + sources = [] for doc in input_doc: if os.path.exists(doc.path_or_url): @@ -71,20 +104,14 @@ def init_db(self, input_doc: List[Document] | None): model=self.model, ) - self.knowledge_graph = KnowledgeGraph( - name=self.name, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - model_config=KnowledgeGraphModelConfig.with_model(self.model), - ontology=self.ontology, - ) - - # Establish a chat session, this will maintain the history - self._chat_session = self.knowledge_graph.chat_session() self.knowledge_graph.process_sources(sources) + else: + raise ValueError("No input documents could be loaded.") + + # Establishing a chat session will maintain the history + self._chat_session = self.knowledge_graph.chat_session() + def add_records(self, new_records: List) -> bool: raise NotImplementedError("This method is not supported by FalkorDB SDK yet.") @@ -101,7 +128,7 @@ def query(self, question: str, n_results: int = 1, **kwargs) -> GraphStoreQueryR Returns: FalkorGraphQueryResult """ if self.knowledge_graph is None: - raise ValueError("Knowledge graph is not created.") + raise ValueError("Knowledge graph has not been selected or created.") response = self._chat_session.send_message(question) diff --git a/setup.py b/setup.py index d8b1446932..df1d4f51d4 100644 --- a/setup.py +++ b/setup.py @@ -60,9 +60,7 @@ retrieve_chat_pgvector = [*retrieve_chat, "pgvector>=0.2.5"] -graph_rag_falkor_db = [ - "graphrag_sdk==0.3.3", -] +graph_rag_falkor_db = ["graphrag_sdk==0.3.3", "falkordb>=1.0.10"] if current_os in ["Windows", "Darwin"]: retrieve_chat_pgvector.extend(["psycopg[binary]>=3.1.18"]) From 5ae2fccb498cfd5c70839823adae974ee4b6fc86 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Tue, 3 Dec 2024 22:55:49 +0000 Subject: [PATCH 03/20] Tweaked order in init Signed-off-by: Mark Sze --- .../graph_rag/falkor_graph_query_engine.py | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py index 0721e4c549..c007c640b9 100644 --- a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +++ b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py @@ -81,16 +81,6 @@ def init_db(self, input_doc: List[Document]): """ Build the knowledge graph with input documents. """ - self.knowledge_graph = KnowledgeGraph( - name=self.name, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - model_config=KnowledgeGraphModelConfig.with_model(self.model), - ontology=self.ontology, - ) - sources = [] for doc in input_doc: if os.path.exists(doc.path_or_url): @@ -104,14 +94,23 @@ def init_db(self, input_doc: List[Document]): model=self.model, ) + self.knowledge_graph = KnowledgeGraph( + name=self.name, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + model_config=KnowledgeGraphModelConfig.with_model(self.model), + ontology=self.ontology, + ) + self.knowledge_graph.process_sources(sources) + # Establishing a chat session will maintain the history + self._chat_session = self.knowledge_graph.chat_session() else: raise ValueError("No input documents could be loaded.") - # Establishing a chat session will maintain the history - self._chat_session = self.knowledge_graph.chat_session() - def add_records(self, new_records: List) -> bool: raise NotImplementedError("This method is not supported by FalkorDB SDK yet.") From bf81c0004ed970590b82405a182708bbfbd02b29 Mon Sep 17 00:00:00 2001 From: AgentGenie Date: Tue, 3 Dec 2024 17:16:29 -0800 Subject: [PATCH 04/20] Add one more Roman restaurant to the data --- ...gentchat_swarm_graphrag_trip_planner.ipynb | 39 +++---------------- .../trip_planner_data/restaurants.json | 8 ++++ 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 0e6673f233..2b3edb7f5b 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -200,36 +200,9 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[33muser_proxy\u001b[0m (to graph_rag_agent):\n", - "\n", - "Find 3 restaurant in Milan.\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[33mgraph_rag_agent\u001b[0m (to user_proxy):\n", - "\n", - "Bros' Burger in Milan is known for its gourmet burgers and offers a relaxed vibe.\n", - "\n", - "--------------------------------------------------------------------------------\n" - ] - }, - { - "data": { - "text/plain": [ - "ChatResult(chat_id=None, chat_history=[{'content': 'Find 3 restaurant in Milan.', 'role': 'assistant', 'name': 'user_proxy'}, {'content': \"Bros' Burger in Milan is known for its gourmet burgers and offers a relaxed vibe.\", 'role': 'user', 'name': 'graph_rag_agent'}], summary=\"Bros' Burger in Milan is known for its gourmet burgers and offers a relaxed vibe.\", cost={'usage_including_cached_inference': {'total_cost': 0}, 'usage_excluding_cached_inference': {'total_cost': 0}}, human_input=['exit'])" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from autogen import ConversableAgent, UserProxyAgent\n", "from autogen.agentchat.contrib.graph_rag.document import Document, DocumentType\n", @@ -238,8 +211,8 @@ "\n", "# Auto generate graph schema from unstructured data\n", "input_paths = [\n", - " \"../test/agentchat/contrib/graph_rag/trip_planner_data/attractions.json\",\n", - " \"../test/agentchat/contrib/graph_rag/trip_planner_data/cities.json\",\n", + " # \"../test/agentchat/contrib/graph_rag/trip_planner_data/attractions.json\",\n", + " # \"../test/agentchat/contrib/graph_rag/trip_planner_data/cities.json\",\n", " \"../test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json\",\n", "]\n", "input_documents = [Document(doctype=DocumentType.TEXT, path_or_url=input_path) for input_path in input_paths]\n", diff --git a/test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json b/test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json index 70763a9111..9500173b31 100644 --- a/test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json +++ b/test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json @@ -86,5 +86,13 @@ "city": "Rome", "rating": 4.7, "food_type": "Italian" + }, + { + "id": 12, + "name": "Osteria delle Commari", + "description": "Local home style Roman restaurant near Vatican Museums.", + "city": "Rome", + "rating": 4.3, + "food_type": "Italian" } ] From b61c2238a33476d9169cfa7a3ad8e085e1dcbc2c Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 4 Dec 2024 01:45:12 +0000 Subject: [PATCH 05/20] Update to FalkorDB GraphRAG agent to utilise conversation history for context and agent's system message. Signed-off-by: Mark Sze --- .../graph_rag/falkor_graph_rag_capability.py | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py b/autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py index 7e8bf9cc90..b5432403c5 100644 --- a/autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +++ b/autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py @@ -55,6 +55,8 @@ def _reply_using_falkordb_query( Query FalkorDB and return the message. Internally, it utilises OpenAI to generate a reply based on the given messages. The history with FalkorDB is also logged and updated. + The agent's system message will be incorporated into the query, if it's not blank. + If no results are found, a default message is returned: "I'm sorry, I don't have an answer for that." Args: @@ -66,16 +68,38 @@ def _reply_using_falkordb_query( Returns: A tuple containing a boolean indicating success and the assistant's reply. """ - question = self._get_last_question(messages[-1]) + # question = self._get_last_question(messages[-1]) + question = self._messages_summary(messages, recipient.system_message) result: GraphStoreQueryResult = self.query_engine.query(question) return True, result.answer if result.answer else "I'm sorry, I don't have an answer for that." - def _get_last_question(self, message: Union[Dict, str]): - """Retrieves the last message from the conversation history.""" - if isinstance(message, str): - return message - if isinstance(message, Dict): - if "content" in message: - return message["content"] - return None + def _messages_summary(self, messages: Union[Dict, str], system_message: str) -> str: + """Summarize the messages in the conversation history. Excluding any message with 'tool_calls' and 'tool_responses' + Includes the 'name' (if it exists) and the 'content', with a new line between each one, like: + customer: + + + agent: + + """ + + if isinstance(messages, str): + if system_message: + summary = f"IMPORTANT: {system_message}\nContext:\n\n{messages}" + else: + return messages + + elif isinstance(messages, List): + summary = "" + for message in messages: + if "content" in message and "tool_calls" not in message and "tool_responses" not in message: + summary += f"{message.get('name', '')}: {message.get('content','')}\n\n" + + if system_message: + summary = f"IMPORTANT: {system_message}\nContext:\n\n{summary}" + + return summary + + else: + raise ValueError("Invalid messages format. Must be a list of messages or a string.") From b33d8bbd921f05377a6a682ee2553443fe963d62 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 4 Dec 2024 03:35:46 +0000 Subject: [PATCH 06/20] FalkorDB notebook example and updated examples listing Signed-off-by: Mark Sze --- ...gentchat_swarm_graphrag_trip_planner.ipynb | 835 +++++++++++++++--- website/docs/Examples.md | 7 + 2 files changed, 735 insertions(+), 107 deletions(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 2b3edb7f5b..43bced8570 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -1,40 +1,146 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Trip planning with a FalkorDB GraphRAG agent in Swarm\n", + "\n", + "In this notebook, we're building a trip planning swarm which has an objective to create an itinerary together with a customer. The end result will be an itinerary that has route times and distances calculated between activities.\n", + "\n", + "The following diagram outlines the key components of the Swarm, with highlights being:\n", + "\n", + "- FalkorDB agent using a GraphRAG database of restaurants and attractions\n", + "- Structured Output agent that will enforce a strict format for the accepted itinerary\n", + "- Routing agent that utilises the Google Maps API to calculate distances between activites\n", + "- Swarm orchestration with hand offs, system message updates, and context variables\n", + "\n", + "[DIAGRAM OF THE PLAN]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "````{=mdx}\n", + ":::info Requirements\n", + "FalkorDB's GraphRAG-SDK is a dependency for this notebook, which can be installed with ag2 via pip:\n", + "\n", + "```bash\n", + "pip install ag2[graph_rag_falkor_db]\n", + "```\n", + "\n", + "For more information, please refer to the [installation guide](/docs/installation/).\n", + ":::\n", + "````" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Running a FalkorDB\n", + "\n", + "**Note:** You need to have a FalkorDB graph database running. If you are running one in a Docker container, please ensure your Docker network is setup to allow access to it.\n", + "\n", + "In this example, we've set the FalkorDB host and port, please adjust them accordingly. For how to set up FalkorDB, please refer to [https://docs.falkordb.com/](https://docs.falkordb.com/).\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Set Configuration and OpenAI API Key\n", + "\n", + "By default, FalkorDB uses OpenAI LLMs and that requires an OpenAI key in your environment variable `OPENAI_API_KEY`.\n", + "\n", + "You can utilise an OAI_CONFIG_LIST file and extract the OpenAI API key and put it in the environment, as will be shown in the following cell.\n", + "\n", + "Alternatively, you can load the environment variable yourself.\n", + "\n", + "````{=mdx}\n", + ":::tip\n", + "Learn more about configuring LLMs for agents [here](/docs/topics/llm_configuration).\n", + ":::\n", + "````" + ] + }, { "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n" + ] + } + ], "source": [ "import os\n", "\n", "import autogen\n", "\n", - "config_list = autogen.config_list_from_json(env_or_file=\"../OAI_CONFIG_LIST\")\n", + "config_list = autogen.config_list_from_json(env_or_file=\"../OAI_CONFIG_LIST\", filter_dict={\"model\": [\"gpt-4o-mini\"]})\n", + "llm_config = {\"config_list\": config_list, \"timeout\": 120}\n", "\n", "# Put the OpenAI API key into the environment\n", "os.environ[\"OPENAI_API_KEY\"] = config_list[0][\"api_key\"]" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Prepare the FalkorDB GraphRAG database\n", + "\n", + "Using 3 sample JSON data files from our GitHub repository, we will create a specific ontology for our GraphRAG database and then populate it.\n", + "\n", + "Creating a specific ontology that matches with the types of queries makes for a more optimal database and is more cost efficient when populating the knowledge graph." + ] + }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "from graphrag_sdk import (\n", - " Attribute,\n", - " AttributeType,\n", - " Entity,\n", - " Ontology,\n", - " Relation,\n", - ")\n", + "from autogen.agentchat.contrib.graph_rag.document import Document, DocumentType\n", + "\n", + "# 3 Files (adjust path as necessary)\n", + "input_paths = [\n", + " \"../test/agentchat/contrib/graph_rag/trip_planner_data/attractions.json\",\n", + " \"../test/agentchat/contrib/graph_rag/trip_planner_data/cities.json\",\n", + " \"../test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json\",\n", + "]\n", + "input_documents = [Document(doctype=DocumentType.TEXT, path_or_url=input_path) for input_path in input_paths]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create Ontology\n", + "\n", + "Entities: Country, City, Attraction, Restaurant\n", + "\n", + "Relationships: City in Country, Attraction in City, Restaurant in City" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from graphrag_sdk import Attribute, AttributeType, Entity, Ontology, Relation\n", "\n", "# Attraction + Restaurant + City + Country Ontology\n", "trip_data_ontology = Ontology()\n", "\n", - "\n", - "# Manually created Ontology by adding entities and relations\n", "trip_data_ontology.add_entity(\n", " Entity(\n", " label=\"Country\",\n", @@ -48,6 +154,7 @@ " ],\n", " )\n", ")\n", + "\n", "trip_data_ontology.add_entity(\n", " Entity(\n", " label=\"City\",\n", @@ -73,6 +180,15 @@ " ],\n", " )\n", ")\n", + "\n", + "trip_data_ontology.add_relation(\n", + " Relation(\n", + " label=\"IN_COUNTRY\",\n", + " source=\"City\",\n", + " target=\"Country\",\n", + " )\n", + ")\n", + "\n", "trip_data_ontology.add_entity(\n", " Entity(\n", " label=\"Restaurant\",\n", @@ -106,13 +222,6 @@ ")\n", "trip_data_ontology.add_relation(\n", " Relation(\n", - " label=\"IN_COUNTRY\",\n", - " source=\"City\",\n", - " target=\"Country\",\n", - " )\n", - ")\n", - "trip_data_ontology.add_relation(\n", - " Relation(\n", " label=\"IN_CITY\",\n", " source=\"Restaurant\",\n", " target=\"City\",\n", @@ -121,44 +230,6 @@ "\n", "trip_data_ontology.add_entity(\n", " Entity(\n", - " label=\"Country\",\n", - " attributes=[\n", - " Attribute(\n", - " name=\"name\",\n", - " attr_type=AttributeType.STRING,\n", - " required=True,\n", - " unique=True,\n", - " ),\n", - " ],\n", - " )\n", - ")\n", - "trip_data_ontology.add_entity(\n", - " Entity(\n", - " label=\"City\",\n", - " attributes=[\n", - " Attribute(\n", - " name=\"name\",\n", - " attr_type=AttributeType.STRING,\n", - " required=True,\n", - " unique=True,\n", - " ),\n", - " Attribute(\n", - " name=\"weather\",\n", - " attr_type=AttributeType.STRING,\n", - " required=False,\n", - " unique=False,\n", - " ),\n", - " Attribute(\n", - " name=\"population\",\n", - " attr_type=AttributeType.NUMBER,\n", - " required=False,\n", - " unique=False,\n", - " ),\n", - " ],\n", - " )\n", - ")\n", - "trip_data_ontology.add_entity(\n", - " Entity(\n", " label=\"Attraction\",\n", " attributes=[\n", " Attribute(\n", @@ -184,13 +255,6 @@ ")\n", "trip_data_ontology.add_relation(\n", " Relation(\n", - " label=\"IN_COUNTRY\",\n", - " source=\"City\",\n", - " target=\"Country\",\n", - " )\n", - ")\n", - "trip_data_ontology.add_relation(\n", - " Relation(\n", " label=\"IN_CITY\",\n", " source=\"Attraction\",\n", " target=\"City\",\n", @@ -198,107 +262,664 @@ ")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Establish FalkorDB and load\n", + "\n", + "Remember: Change your host, port, and preferred OpenAI model if needed (gpt-4o-mini and better is recommended)." + ] + }, { "cell_type": "code", "execution_count": 4, "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ".\n" + ] + } + ], + "source": [ + "print(os.curdir)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ - "from autogen import ConversableAgent, UserProxyAgent\n", - "from autogen.agentchat.contrib.graph_rag.document import Document, DocumentType\n", + "from graphrag_sdk.models.openai import OpenAiGenerativeModel\n", + "\n", "from autogen.agentchat.contrib.graph_rag.falkor_graph_query_engine import FalkorGraphQueryEngine\n", "from autogen.agentchat.contrib.graph_rag.falkor_graph_rag_capability import FalkorGraphRagCapability\n", "\n", - "# Auto generate graph schema from unstructured data\n", - "input_paths = [\n", - " # \"../test/agentchat/contrib/graph_rag/trip_planner_data/attractions.json\",\n", - " # \"../test/agentchat/contrib/graph_rag/trip_planner_data/cities.json\",\n", - " \"../test/agentchat/contrib/graph_rag/trip_planner_data/restaurants.json\",\n", - "]\n", - "input_documents = [Document(doctype=DocumentType.TEXT, path_or_url=input_path) for input_path in input_paths]\n", - "\n", "# Create FalkorGraphQueryEngine\n", "query_engine = FalkorGraphQueryEngine(\n", " name=\"trip_data\",\n", - " host=\"172.18.0.3\", # Change\n", + " host=\"192.168.0.115\", # Change\n", " port=6379, # if needed\n", " ontology=trip_data_ontology,\n", + " model=OpenAiGenerativeModel(\"gpt-4o\"),\n", ")\n", "\n", "# Ingest data and initialize the database\n", "query_engine.init_db(input_doc=input_documents)\n", "\n", - "# Create a ConversableAgent (no LLM configuration)\n", - "graph_rag_agent = ConversableAgent(\n", - " name=\"graph_rag_agent\",\n", - " human_input_mode=\"NEVER\",\n", + "# If you have already ingested and created the database, you can use this connect_db instead of init_db\n", + "# query_engine.connect_db()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Swarm\n", + "\n", + "### Context Variables\n", + "Our swarm agents will have access to a couple of context variables in relation to the itinerary." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "from enum import Enum\n", + "from typing import Any, Dict\n", + "\n", + "from pydantic import BaseModel\n", + "\n", + "from autogen import (\n", + " AFTER_WORK,\n", + " ON_CONDITION,\n", + " AfterWorkOption,\n", + " SwarmAgent,\n", + " SwarmResult,\n", + " UserProxyAgent,\n", + " config_list_from_json,\n", + " initiate_swarm_chat,\n", ")\n", "\n", - "# Associate the capability with the agent\n", + "trip_context = {\"itinerary_confirmed\": False, \"itinerary\": \"\"}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Agent Functions\n", + "\n", + "We're providing a function to our Planner agent to mark an itinerary as confirmed by the customer and to store the final itinerary. This will then transfer to our Structured Output agent." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def mark_itinerary_as_complete(final_itinerary: str, context_variables: Dict[str, Any]) -> SwarmResult:\n", + " \"\"\"Store and mark our itinerary as accepted by the customer.\"\"\"\n", + " context_variables[\"itinerary_confirmed\"] = True\n", + " context_variables[\"itinerary\"] = final_itinerary\n", + "\n", + " # This will update the context variables and then transfer to the Structured Output agent\n", + " return SwarmResult(\n", + " agent=\"structured_output_agent\", context_variables=context_variables, values=\"Itinerary recorded and confirmed.\"\n", + " )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Pydantic model for Structured Output\n", + "\n", + "Utilising OpenAI's [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs), our Structured Output agent's responses will be constrained to this Pydantic model.\n", + "\n", + "The itinerary is structured as:\n", + "Itinerary has Day(s) has Event(s)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "class TypeEnum(str, Enum):\n", + " attraction = \"Attraction\"\n", + " restaurant = \"Restaurant\"\n", + "\n", + "\n", + "class Event(BaseModel):\n", + " type: str\n", + " location: str\n", + " city: str\n", + " description: str\n", + "\n", + "\n", + "class Day(BaseModel):\n", + " events: list[Event]\n", + "\n", + "\n", + "class Itinerary(BaseModel):\n", + " days: list[Day]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Agents\n", + "\n", + "Our SwarmAgents and a UserProxyAgent (human) which the swarm will interact with." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "# Planner agent, interacting with the customer and GraphRag agent, to create an itinerary\n", + "planner_agent = SwarmAgent(\n", + " name=\"planner_agent\",\n", + " system_message=\"You are a trip planner agent. It is important to know where the customer is going, how many days, what they want to do.\"\n", + " + \"You will work with another agent, graphrag_agent, to get information about restaurant and attractions. \"\n", + " + \"You are also working with the customer, so you must ask the customer what they want to do if you don’t have LOCATION, NUMBER OF DAYS, MEALS, and ATTRACTIONS. \"\n", + " + \"When you have the customer's requirements, work with graphrag_agent to get information for an itinerary.\"\n", + " + \"You are responsible for creating the itinerary and for each day in the itinerary you MUST HAVE events and EACH EVENT MUST HAVE a 'type' ('Restaurant' or 'Attraction'), 'location' (name of restaurant or attraction), 'city', and 'description'. \"\n", + " + \"Finally, YOU MUST ask the customer if they are happy with the itinerary before marking the itinerary as complete.\",\n", + " functions=[mark_itinerary_as_complete],\n", + " llm_config=llm_config,\n", + ")\n", + "\n", + "# FalkorDB GraphRAG agent, utilising the FalkorDB to gather data for the Planner agent\n", + "graphrag_agent = SwarmAgent(\n", + " name=\"graphrag_agent\",\n", + " system_message=\"Return a list of restaurants and/or attractions. List them separately and provide ALL the options in the location. Do not provide travel advice.\",\n", + ")\n", + "\n", + "# Adding the FalkorDB capability to the agent\n", "graph_rag_capability = FalkorGraphRagCapability(query_engine)\n", - "graph_rag_capability.add_to_agent(graph_rag_agent)\n", + "graph_rag_capability.add_to_agent(graphrag_agent)\n", + "\n", + "# Structured Output agent, formatting the itinerary into a structured format through the response_format parameter\n", + "structured_output_agent = SwarmAgent(\n", + " name=\"structured_output_agent\",\n", + " system_message=\"You are a data formatting agent, format the provided itinerary in the context below into the provided format.\",\n", + " llm_config=llm_config,\n", + " response_format=Itinerary,\n", + ")\n", + "\n", + "# Route Timing agent, adding estimated travel times to the itinerary by utilising the Google Maps API\n", + "route_timing_agent = SwarmAgent(\n", + " name=\"route_timing_agent\",\n", + " system_message=\"You are a route timing agent. You will add estimated travel times to the itinerary\",\n", + " llm_config=llm_config, # Not sure if you need this, YZ\n", + ")\n", + "\n", + "# Our customer will be a human in the loop\n", + "customer = UserProxyAgent(name=\"customer\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Hand offs and After works\n", + "\n", + "In conjunction with the agent's associated functions, we establish rules that govern the swarm orchestration through hand offs and After works.\n", "\n", - "# Create a user proxy agent to converse with our RAG agent\n", - "user_proxy = UserProxyAgent(\n", - " name=\"user_proxy\",\n", - " human_input_mode=\"ALWAYS\",\n", + "For more details on the swarm orchestration, [see the documentation](https://ag2ai.github.io/ag2/docs/topics/swarm)." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "planner_agent.register_hand_off(\n", + " hand_to=[\n", + " ON_CONDITION(\n", + " graphrag_agent,\n", + " \"Need information on the restaurants and attractions for a location. DO NOT call more than once at a time.\",\n", + " ), # Get info from FalkorDB GraphRAG\n", + " ON_CONDITION(structured_output_agent, \"Itinerary is confirmed by the customer\"),\n", + " AFTER_WORK(AfterWorkOption.REVERT_TO_USER), # Revert to the customer for more information on their plans\n", + " ]\n", + ")\n", + "\n", + "# Back to the Planner when information has been retrieved\n", + "graphrag_agent.register_hand_off(hand_to=[AFTER_WORK(planner_agent)])\n", + "\n", + "# Once we have formatted our itinerary, we can hand off to the route timing agent to add in the travel timings\n", + "structured_output_agent.register_hand_off(hand_to=[AFTER_WORK(route_timing_agent)])\n", + "\n", + "# Finally, once the route timing agent has finished, we can terminate the swarm\n", + "route_timing_agent.register_hand_off(\n", + " hand_to=[AFTER_WORK(AfterWorkOption.TERMINATE)] # Once this agent has finished, the swarm can terminate\n", ")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run the swarm\n", + "\n", + "Let's get an itinerary for a couple of days in Rome." + ] + }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\u001b[33muser_proxy\u001b[0m (to graph_rag_agent):\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "I want to go to Rome for a couple of days. Can you help me plan my trip?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "Of course! I'd love to help you plan your trip to Rome. \n", + "\n", + "To get started, could you please provide me with the following information:\n", + "1. How many days will you be staying in Rome?\n", + "2. What activities or attractions are you interested in? (e.g., historical sites, museums, shopping, dining, etc.)\n", + "3. Do you have any specific preferences for meals or restaurants? \n", + "\n", + "Once I have this information, I can start creating an itinerary for you!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", "\n", - "Find 3 restaurants in Rome.\n", + "2 days please, I want lunch and dinner, with an attraction to see in the morning and after lunch.\n", "\n", "--------------------------------------------------------------------------------\n", - "\u001b[33mgraph_rag_agent\u001b[0m (to user_proxy):\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", "\n", - "Three restaurants in Rome are Trattoria da Enzo, known for its traditional Roman dishes and welcoming atmosphere; Il Pagliaccio, an elegant Michelin-starred restaurant offering contemporary Italian cuisine; and Tonnarello, a casual spot for pasta, meatballs, and other simple Roman dishes with patio seating and acoustic guitar music.\n", + "\u001b[32m***** Suggested tool call (call_2dmMbckU5YjaCsL6Y8pWbrdK): transfer_to_graphrag_agent *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m*******************************************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", - "\u001b[33muser_proxy\u001b[0m (to graph_rag_agent):\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION transfer_to_graphrag_agent...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", - "Find 3 attractions in Rome.\n", + "\u001b[32m***** Response from calling tool (call_2dmMbckU5YjaCsL6Y8pWbrdK) *****\u001b[0m\n", + "SwarmAgent --> graphrag_agent\n", + "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", - "\u001b[33mgraph_rag_agent\u001b[0m (to user_proxy):\n", + "\u001b[32m\n", + "Next speaker: graphrag_agent\n", + "\u001b[0m\n", + "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", "\n", - "Three attractions in Rome are the Colosseum, an ancient amphitheater known for gladiatorial contests and public spectacles; the Vatican Museums, a complex of museums and galleries showcasing works of art collected by Popes over centuries; and the Trevi Fountain, a Baroque fountain famous for its stunning sculptures and the tradition of tossing coins.\n", + "Restaurants in Rome:\n", + "- Trattoria da Enzo: A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", + "- Il Pagliaccio: An elegant Michelin-starred restaurant offering contemporary Italian cuisine.\n", + "- Tonnarello: Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\n", + "- Osteria delle Commari: Local home style Roman restaurant near Vatican Museums.\n", + "- Armando al Pantheon: Traditional Roman cuisine since 1961 near the Pantheon.\n", + "- Salumeria Roscioli Ristorante: Known for pasta alla gricia and amatriciana, and boasts an impressive wine cellar.\n", + "- L'Arcangelo: Famous for supplì (Roman rice balls) and gnocchi on Thursdays.\n", + "\n", + "Attractions in Rome:\n", + "- Colosseum: An ancient amphitheater known for gladiatorial contests and public spectacles.\n", + "- Vatican Museums: A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + "- Trevi Fountain: A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", + "- Basilica di Santa Maria Maggiore: A major basilica in Rome, known for its rich history and impressive architecture.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "Great! Here's a preliminary itinerary for your 2-day trip to Rome, including attractions and meals. \n", + "\n", + "### Day 1:\n", + "- **Morning Attraction:** \n", + " - **Type:** Attraction \n", + " - **Location:** Colosseum \n", + " - **City:** Rome \n", + " - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\n", + "\n", + "- **Lunch:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Trattoria da Enzo \n", + " - **City:** Rome \n", + " - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", + "\n", + "- **Afternoon Attraction:** \n", + " - **Type:** Attraction \n", + " - **Location:** Trevi Fountain \n", + " - **City:** Rome \n", + " - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", + "\n", + "- **Dinner:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Armando al Pantheon \n", + " - **City:** Rome \n", + " - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\n", + "\n", + "### Day 2:\n", + "- **Morning Attraction:** \n", + " - **Type:** Attraction \n", + " - **Location:** Vatican Museums \n", + " - **City:** Rome \n", + " - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + "\n", + "- **Lunch:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Osteria delle Commari \n", + " - **City:** Rome \n", + " - **Description:** Local home-style Roman restaurant near Vatican Museums.\n", + "\n", + "- **Afternoon Attraction:** \n", + " - **Type:** Attraction \n", + " - **Location:** Basilica di Santa Maria Maggiore \n", + " - **City:** Rome \n", + " - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\n", + "\n", + "- **Dinner:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Il Pagliaccio \n", + " - **City:** Rome \n", + " - **Description:** An elegant Michelin-starred restaurant offering contemporary Italian cuisine.\n", + "\n", + "Please review this itinerary and let me know if it looks good to you or if you'd like to make any adjustments!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "I've eaten at Il Pagliaccio and didn't like it.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_8RcnbYXeN4Hq862VMhtOA9Rl): transfer_to_graphrag_agent *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m*******************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION transfer_to_graphrag_agent...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_8RcnbYXeN4Hq862VMhtOA9Rl) *****\u001b[0m\n", + "SwarmAgent --> graphrag_agent\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: graphrag_agent\n", + "\u001b[0m\n", + "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", + "\n", + "Restaurants in Rome:\n", + "- Trattoria da Enzo: A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", + "- Tonnarello: Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\n", + "- Osteria delle Commari: Local home-style Roman restaurant near Vatican Museums.\n", + "- Armando al Pantheon: Traditional Roman cuisine since 1961 near the Pantheon.\n", + "- Salumeria Roscioli Ristorante: Known for pasta alla gricia and amatriciana, and boasts an impressive wine cellar.\n", + "- L'Arcangelo: Famous for supplì (Roman rice balls) and gnocchi on Thursdays.\n", + "\n", + "Attractions in Rome:\n", + "- Colosseum: An ancient amphitheater known for gladiatorial contests and public spectacles.\n", + "- Vatican Museums: A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + "- Trevi Fountain: A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", + "- Basilica di Santa Maria Maggiore: A major basilica in Rome, known for its rich history and impressive architecture.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "Thank you for the feedback! Here's an updated itinerary with a different restaurant for your second dinner:\n", + "\n", + "### Day 1:\n", + "- **Morning Attraction:** \n", + " - **Type:** Attraction \n", + " - **Location:** Colosseum \n", + " - **City:** Rome \n", + " - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\n", + "\n", + "- **Lunch:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Trattoria da Enzo \n", + " - **City:** Rome \n", + " - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", + "\n", + "- **Afternoon Attraction:** \n", + " - **Type:** Attraction \n", + " - **Location:** Trevi Fountain \n", + " - **City:** Rome \n", + " - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", + "\n", + "- **Dinner:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Armando al Pantheon \n", + " - **City:** Rome \n", + " - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\n", + "\n", + "### Day 2:\n", + "- **Morning Attraction:** \n", + " - **Type:** Attraction \n", + " - **Location:** Vatican Museums \n", + " - **City:** Rome \n", + " - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + "\n", + "- **Lunch:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Osteria delle Commari \n", + " - **City:** Rome \n", + " - **Description:** Local home-style Roman restaurant near Vatican Museums.\n", + "\n", + "- **Afternoon Attraction:** \n", + " - **Type:** Attraction \n", + " - **Location:** Basilica di Santa Maria Maggiore \n", + " - **City:** Rome \n", + " - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\n", + "\n", + "- **Dinner:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Tonnarello \n", + " - **City:** Rome \n", + " - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\n", + "\n", + "Please take a look at this updated itinerary and let me know if you're happy with it or if you'd like to make further changes!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "Great, lock it in.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_yZeiuwaTMJIwthHTxUt7NGEx): mark_itinerary_as_complete *****\u001b[0m\n", + "Arguments: \n", + "{\"final_itinerary\":\"### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\"}\n", + "\u001b[32m*******************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION mark_itinerary_as_complete...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_yZeiuwaTMJIwthHTxUt7NGEx) *****\u001b[0m\n", + "Itinerary recorded and confirmed.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", - "\u001b[33muser_proxy\u001b[0m (to graph_rag_agent):\n", + "\u001b[32m\n", + "Next speaker: structured_output_agent\n", + "\u001b[0m\n", + "\u001b[33mstructured_output_agent\u001b[0m (to chat_manager):\n", "\n", - "How many attractions in Rome are in the database?\n", + "{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and public spectacles.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Traditional Roman cuisine since 1961, located near the Pantheon.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing works of art collected by Popes over centuries.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"Local home-style Roman restaurant near Vatican Museums.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica in Rome, known for its rich history and impressive architecture.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\"}]}]}\n", "\n", "--------------------------------------------------------------------------------\n", - "\u001b[33mgraph_rag_agent\u001b[0m (to user_proxy):\n", + "\u001b[32m\n", + "Next speaker: route_timing_agent\n", + "\u001b[0m\n", + "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", + "\n", + "Your itinerary for your 2-day trip to Rome is confirmed! Here are the details:\n", + "\n", + "### Day 1:\n", + "- **Morning Attraction:** \n", + " - **Location:** Colosseum \n", + " - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\n", + "\n", + "- **Lunch:** \n", + " - **Location:** Trattoria da Enzo \n", + " - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", + "\n", + "- **Afternoon Attraction:** \n", + " - **Location:** Trevi Fountain \n", + " - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", + "\n", + "- **Dinner:** \n", + " - **Location:** Armando al Pantheon \n", + " - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\n", + "\n", + "### Day 2:\n", + "- **Morning Attraction:** \n", + " - **Location:** Vatican Museums \n", + " - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + "\n", + "- **Lunch:** \n", + " - **Location:** Osteria delle Commari \n", + " - **Description:** Local home-style Roman restaurant near Vatican Museums.\n", "\n", - "There are 4 attractions in Rome listed in the database.\n", + "- **Afternoon Attraction:** \n", + " - **Location:** Basilica di Santa Maria Maggiore \n", + " - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\n", + "\n", + "- **Dinner:** \n", + " - **Location:** Tonnarello \n", + " - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\n", + "\n", + "If you need any further assistance or modifications before your trip, just let me know. Enjoy your time in Rome!\n", "\n", "--------------------------------------------------------------------------------\n" ] - }, + } + ], + "source": [ + "# 6. Start the conversation\n", + "\n", + "chat_result, context_variables, last_agent = initiate_swarm_chat(\n", + " initial_agent=planner_agent,\n", + " agents=[planner_agent, graphrag_agent, structured_output_agent, route_timing_agent],\n", + " user_agent=customer,\n", + " context_variables=trip_context,\n", + " messages=\"I want to go to Rome for a couple of days. Can you help me plan my trip?\",\n", + " after_work=AfterWorkOption.TERMINATE,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ { - "data": { - "text/plain": [ - "ChatResult(chat_id=None, chat_history=[{'content': 'Find 3 restaurants in Rome.', 'role': 'assistant', 'name': 'user_proxy'}, {'content': 'Three restaurants in Rome are Trattoria da Enzo, known for its traditional Roman dishes and welcoming atmosphere; Il Pagliaccio, an elegant Michelin-starred restaurant offering contemporary Italian cuisine; and Tonnarello, a casual spot for pasta, meatballs, and other simple Roman dishes with patio seating and acoustic guitar music.', 'role': 'user', 'name': 'graph_rag_agent'}, {'content': 'Find 3 attractions in Rome.', 'role': 'assistant', 'name': 'user_proxy'}, {'content': 'Three attractions in Rome are the Colosseum, an ancient amphitheater known for gladiatorial contests and public spectacles; the Vatican Museums, a complex of museums and galleries showcasing works of art collected by Popes over centuries; and the Trevi Fountain, a Baroque fountain famous for its stunning sculptures and the tradition of tossing coins.', 'role': 'user', 'name': 'graph_rag_agent'}, {'content': 'How many attractions in Rome are in the database?', 'role': 'assistant', 'name': 'user_proxy'}, {'content': 'There are 4 attractions in Rome listed in the database.', 'role': 'user', 'name': 'graph_rag_agent'}], summary='There are 4 attractions in Rome listed in the database.', cost={'usage_including_cached_inference': {'total_cost': 0}, 'usage_excluding_cached_inference': {'total_cost': 0}}, human_input=['Find 3 attractions in Rome.', 'How many attractions in Rome are in the database?', 'exit'])" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "Context: {'itinerary_confirmed': True, 'itinerary': '### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.'}\n" + ] + } + ], + "source": [ + "print(f\"Context: {context_variables}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'content': 'I want to go to Rome for a couple of days. Can you help me plan my trip?', 'role': 'assistant', 'name': 'customer'}\n", + "{'content': \"Of course! I'd love to help you plan your trip to Rome. \\n\\nTo get started, could you please provide me with the following information:\\n1. How many days will you be staying in Rome?\\n2. What activities or attractions are you interested in? (e.g., historical sites, museums, shopping, dining, etc.)\\n3. Do you have any specific preferences for meals or restaurants? \\n\\nOnce I have this information, I can start creating an itinerary for you!\", 'name': 'planner_agent', 'role': 'user'}\n", + "{'content': '2 days please, I want lunch and dinner, with an attraction to see in the morning and after lunch.', 'role': 'assistant', 'name': 'customer'}\n", + "{'content': 'None', 'tool_calls': [{'id': 'call_2dmMbckU5YjaCsL6Y8pWbrdK', 'function': {'arguments': '{}', 'name': 'transfer_to_graphrag_agent'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", + "{'content': 'SwarmAgent --> graphrag_agent', 'tool_responses': [{'tool_call_id': 'call_2dmMbckU5YjaCsL6Y8pWbrdK', 'role': 'tool', 'content': 'SwarmAgent --> graphrag_agent'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", + "{'content': \"Restaurants in Rome:\\n- Trattoria da Enzo: A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n- Il Pagliaccio: An elegant Michelin-starred restaurant offering contemporary Italian cuisine.\\n- Tonnarello: Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\\n- Osteria delle Commari: Local home style Roman restaurant near Vatican Museums.\\n- Armando al Pantheon: Traditional Roman cuisine since 1961 near the Pantheon.\\n- Salumeria Roscioli Ristorante: Known for pasta alla gricia and amatriciana, and boasts an impressive wine cellar.\\n- L'Arcangelo: Famous for supplì (Roman rice balls) and gnocchi on Thursdays.\\n\\nAttractions in Rome:\\n- Colosseum: An ancient amphitheater known for gladiatorial contests and public spectacles.\\n- Vatican Museums: A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n- Trevi Fountain: A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n- Basilica di Santa Maria Maggiore: A major basilica in Rome, known for its rich history and impressive architecture.\", 'name': 'graphrag_agent', 'role': 'user'}\n", + "{'content': \"Great! Here's a preliminary itinerary for your 2-day trip to Rome, including attractions and meals. \\n\\n### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Il Pagliaccio \\n - **City:** Rome \\n - **Description:** An elegant Michelin-starred restaurant offering contemporary Italian cuisine.\\n\\nPlease review this itinerary and let me know if it looks good to you or if you'd like to make any adjustments!\", 'name': 'planner_agent', 'role': 'user'}\n", + "{'content': \"I've eaten at Il Pagliaccio and didn't like it.\", 'role': 'assistant', 'name': 'customer'}\n", + "{'content': 'None', 'tool_calls': [{'id': 'call_8RcnbYXeN4Hq862VMhtOA9Rl', 'function': {'arguments': '{}', 'name': 'transfer_to_graphrag_agent'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", + "{'content': 'SwarmAgent --> graphrag_agent', 'tool_responses': [{'tool_call_id': 'call_8RcnbYXeN4Hq862VMhtOA9Rl', 'role': 'tool', 'content': 'SwarmAgent --> graphrag_agent'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", + "{'content': \"Restaurants in Rome:\\n- Trattoria da Enzo: A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n- Tonnarello: Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\\n- Osteria delle Commari: Local home-style Roman restaurant near Vatican Museums.\\n- Armando al Pantheon: Traditional Roman cuisine since 1961 near the Pantheon.\\n- Salumeria Roscioli Ristorante: Known for pasta alla gricia and amatriciana, and boasts an impressive wine cellar.\\n- L'Arcangelo: Famous for supplì (Roman rice balls) and gnocchi on Thursdays.\\n\\nAttractions in Rome:\\n- Colosseum: An ancient amphitheater known for gladiatorial contests and public spectacles.\\n- Vatican Museums: A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n- Trevi Fountain: A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n- Basilica di Santa Maria Maggiore: A major basilica in Rome, known for its rich history and impressive architecture.\", 'name': 'graphrag_agent', 'role': 'user'}\n", + "{'content': \"Thank you for the feedback! Here's an updated itinerary with a different restaurant for your second dinner:\\n\\n### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\\n\\nPlease take a look at this updated itinerary and let me know if you're happy with it or if you'd like to make further changes!\", 'name': 'planner_agent', 'role': 'user'}\n", + "{'content': 'Great, lock it in.', 'role': 'assistant', 'name': 'customer'}\n", + "{'content': 'None', 'tool_calls': [{'id': 'call_yZeiuwaTMJIwthHTxUt7NGEx', 'function': {'arguments': '{\"final_itinerary\":\"### Day 1:\\\\n- **Morning Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Colosseum \\\\n - **City:** Rome \\\\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\\\n\\\\n- **Lunch:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Trattoria da Enzo \\\\n - **City:** Rome \\\\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\\\n\\\\n- **Afternoon Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Trevi Fountain \\\\n - **City:** Rome \\\\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\\\n\\\\n- **Dinner:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Armando al Pantheon \\\\n - **City:** Rome \\\\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\\\n\\\\n### Day 2:\\\\n- **Morning Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Vatican Museums \\\\n - **City:** Rome \\\\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\\\n\\\\n- **Lunch:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Osteria delle Commari \\\\n - **City:** Rome \\\\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\\\n\\\\n- **Afternoon Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Basilica di Santa Maria Maggiore \\\\n - **City:** Rome \\\\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\\\n\\\\n- **Dinner:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Tonnarello \\\\n - **City:** Rome \\\\n - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\"}', 'name': 'mark_itinerary_as_complete'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", + "{'content': 'Itinerary recorded and confirmed.', 'tool_responses': [{'tool_call_id': 'call_yZeiuwaTMJIwthHTxUt7NGEx', 'role': 'tool', 'content': 'Itinerary recorded and confirmed.'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", + "{'content': '{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and public spectacles.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Traditional Roman cuisine since 1961, located near the Pantheon.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing works of art collected by Popes over centuries.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"Local home-style Roman restaurant near Vatican Museums.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica in Rome, known for its rich history and impressive architecture.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\"}]}]}', 'name': 'structured_output_agent', 'role': 'user'}\n", + "{'content': 'Your itinerary for your 2-day trip to Rome is confirmed! Here are the details:\\n\\n### Day 1:\\n- **Morning Attraction:** \\n - **Location:** Colosseum \\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:** \\n - **Location:** Trattoria da Enzo \\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n\\n- **Afternoon Attraction:** \\n - **Location:** Trevi Fountain \\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n\\n- **Dinner:** \\n - **Location:** Armando al Pantheon \\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Location:** Vatican Museums \\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch:** \\n - **Location:** Osteria delle Commari \\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\n\\n- **Afternoon Attraction:** \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\n\\n- **Dinner:** \\n - **Location:** Tonnarello \\n - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\\n\\nIf you need any further assistance or modifications before your trip, just let me know. Enjoy your time in Rome!', 'name': 'route_timing_agent', 'role': 'user'}\n" + ] } ], "source": [ - "user_proxy.initiate_chat(graph_rag_agent, message=\"Find 3 restaurants in Rome.\")" + "for message in chat_result.chat_history:\n", + " print(message)" ] } ], diff --git a/website/docs/Examples.md b/website/docs/Examples.md index e1f4884e5c..c4e0bce998 100644 --- a/website/docs/Examples.md +++ b/website/docs/Examples.md @@ -36,12 +36,19 @@ Links to notebook examples: - OptiGuide for Solving a Supply Chain Optimization Problem with Nested Chats with a Coding Agent and a Safeguard Agent - [View Notebook](/docs/notebooks/agentchat_nestedchat_optiguide) - Conversational Chess with Nested Chats and Tool Use - [View Notebook](/docs/notebooks/agentchat_nested_chats_chess) +### Swarms +- Orchestrating agents in a Swarm - [View Notebook](/docs/notebooks/agentchat_swarm) + ### Applications - Automated Continual Learning from New Data - [View Notebook](/docs/notebooks/agentchat_stream) - [AutoAnny](https://github.com/ag2ai/build-with-ag2/tree/main/samples/apps/auto-anny) - A Discord bot built using AutoGen +### RAG + +- GraphRAG agent using FalkorDB (feat. swarms and Google Maps API) - [View Notebook](/docs/notebooks/agentchat_swarm_graphrag_trip_planner) + ### Tool Use - **Web Search**: Solve Tasks Requiring Web Info - [View Notebook](/docs/notebooks/agentchat_web_info) From 3f2b8d07987e8ce9535aaf80a4f5cef1b29bdfd0 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 4 Dec 2024 03:38:51 +0000 Subject: [PATCH 07/20] Notebook tidy. Signed-off-by: Mark Sze --- ...gentchat_swarm_graphrag_trip_planner.ipynb | 57 ++----------------- 1 file changed, 4 insertions(+), 53 deletions(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 43bced8570..463c77f0dc 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -271,23 +271,6 @@ "Remember: Change your host, port, and preferred OpenAI model if needed (gpt-4o-mini and better is recommended)." ] }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - ".\n" - ] - } - ], - "source": [ - "print(os.curdir)" - ] - }, { "cell_type": "code", "execution_count": null, @@ -873,50 +856,18 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Context: {'itinerary_confirmed': True, 'itinerary': '### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.'}\n" - ] - } - ], + "outputs": [], "source": [ "print(f\"Context: {context_variables}\")" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'content': 'I want to go to Rome for a couple of days. Can you help me plan my trip?', 'role': 'assistant', 'name': 'customer'}\n", - "{'content': \"Of course! I'd love to help you plan your trip to Rome. \\n\\nTo get started, could you please provide me with the following information:\\n1. How many days will you be staying in Rome?\\n2. What activities or attractions are you interested in? (e.g., historical sites, museums, shopping, dining, etc.)\\n3. Do you have any specific preferences for meals or restaurants? \\n\\nOnce I have this information, I can start creating an itinerary for you!\", 'name': 'planner_agent', 'role': 'user'}\n", - "{'content': '2 days please, I want lunch and dinner, with an attraction to see in the morning and after lunch.', 'role': 'assistant', 'name': 'customer'}\n", - "{'content': 'None', 'tool_calls': [{'id': 'call_2dmMbckU5YjaCsL6Y8pWbrdK', 'function': {'arguments': '{}', 'name': 'transfer_to_graphrag_agent'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", - "{'content': 'SwarmAgent --> graphrag_agent', 'tool_responses': [{'tool_call_id': 'call_2dmMbckU5YjaCsL6Y8pWbrdK', 'role': 'tool', 'content': 'SwarmAgent --> graphrag_agent'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", - "{'content': \"Restaurants in Rome:\\n- Trattoria da Enzo: A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n- Il Pagliaccio: An elegant Michelin-starred restaurant offering contemporary Italian cuisine.\\n- Tonnarello: Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\\n- Osteria delle Commari: Local home style Roman restaurant near Vatican Museums.\\n- Armando al Pantheon: Traditional Roman cuisine since 1961 near the Pantheon.\\n- Salumeria Roscioli Ristorante: Known for pasta alla gricia and amatriciana, and boasts an impressive wine cellar.\\n- L'Arcangelo: Famous for supplì (Roman rice balls) and gnocchi on Thursdays.\\n\\nAttractions in Rome:\\n- Colosseum: An ancient amphitheater known for gladiatorial contests and public spectacles.\\n- Vatican Museums: A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n- Trevi Fountain: A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n- Basilica di Santa Maria Maggiore: A major basilica in Rome, known for its rich history and impressive architecture.\", 'name': 'graphrag_agent', 'role': 'user'}\n", - "{'content': \"Great! Here's a preliminary itinerary for your 2-day trip to Rome, including attractions and meals. \\n\\n### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Il Pagliaccio \\n - **City:** Rome \\n - **Description:** An elegant Michelin-starred restaurant offering contemporary Italian cuisine.\\n\\nPlease review this itinerary and let me know if it looks good to you or if you'd like to make any adjustments!\", 'name': 'planner_agent', 'role': 'user'}\n", - "{'content': \"I've eaten at Il Pagliaccio and didn't like it.\", 'role': 'assistant', 'name': 'customer'}\n", - "{'content': 'None', 'tool_calls': [{'id': 'call_8RcnbYXeN4Hq862VMhtOA9Rl', 'function': {'arguments': '{}', 'name': 'transfer_to_graphrag_agent'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", - "{'content': 'SwarmAgent --> graphrag_agent', 'tool_responses': [{'tool_call_id': 'call_8RcnbYXeN4Hq862VMhtOA9Rl', 'role': 'tool', 'content': 'SwarmAgent --> graphrag_agent'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", - "{'content': \"Restaurants in Rome:\\n- Trattoria da Enzo: A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n- Tonnarello: Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\\n- Osteria delle Commari: Local home-style Roman restaurant near Vatican Museums.\\n- Armando al Pantheon: Traditional Roman cuisine since 1961 near the Pantheon.\\n- Salumeria Roscioli Ristorante: Known for pasta alla gricia and amatriciana, and boasts an impressive wine cellar.\\n- L'Arcangelo: Famous for supplì (Roman rice balls) and gnocchi on Thursdays.\\n\\nAttractions in Rome:\\n- Colosseum: An ancient amphitheater known for gladiatorial contests and public spectacles.\\n- Vatican Museums: A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n- Trevi Fountain: A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n- Basilica di Santa Maria Maggiore: A major basilica in Rome, known for its rich history and impressive architecture.\", 'name': 'graphrag_agent', 'role': 'user'}\n", - "{'content': \"Thank you for the feedback! Here's an updated itinerary with a different restaurant for your second dinner:\\n\\n### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\\n\\nPlease take a look at this updated itinerary and let me know if you're happy with it or if you'd like to make further changes!\", 'name': 'planner_agent', 'role': 'user'}\n", - "{'content': 'Great, lock it in.', 'role': 'assistant', 'name': 'customer'}\n", - "{'content': 'None', 'tool_calls': [{'id': 'call_yZeiuwaTMJIwthHTxUt7NGEx', 'function': {'arguments': '{\"final_itinerary\":\"### Day 1:\\\\n- **Morning Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Colosseum \\\\n - **City:** Rome \\\\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\\\n\\\\n- **Lunch:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Trattoria da Enzo \\\\n - **City:** Rome \\\\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\\\n\\\\n- **Afternoon Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Trevi Fountain \\\\n - **City:** Rome \\\\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\\\n\\\\n- **Dinner:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Armando al Pantheon \\\\n - **City:** Rome \\\\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\\\n\\\\n### Day 2:\\\\n- **Morning Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Vatican Museums \\\\n - **City:** Rome \\\\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\\\n\\\\n- **Lunch:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Osteria delle Commari \\\\n - **City:** Rome \\\\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\\\n\\\\n- **Afternoon Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Basilica di Santa Maria Maggiore \\\\n - **City:** Rome \\\\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\\\n\\\\n- **Dinner:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Tonnarello \\\\n - **City:** Rome \\\\n - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\"}', 'name': 'mark_itinerary_as_complete'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", - "{'content': 'Itinerary recorded and confirmed.', 'tool_responses': [{'tool_call_id': 'call_yZeiuwaTMJIwthHTxUt7NGEx', 'role': 'tool', 'content': 'Itinerary recorded and confirmed.'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", - "{'content': '{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and public spectacles.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Traditional Roman cuisine since 1961, located near the Pantheon.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing works of art collected by Popes over centuries.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"Local home-style Roman restaurant near Vatican Museums.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica in Rome, known for its rich history and impressive architecture.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\"}]}]}', 'name': 'structured_output_agent', 'role': 'user'}\n", - "{'content': 'Your itinerary for your 2-day trip to Rome is confirmed! Here are the details:\\n\\n### Day 1:\\n- **Morning Attraction:** \\n - **Location:** Colosseum \\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:** \\n - **Location:** Trattoria da Enzo \\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n\\n- **Afternoon Attraction:** \\n - **Location:** Trevi Fountain \\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n\\n- **Dinner:** \\n - **Location:** Armando al Pantheon \\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Location:** Vatican Museums \\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch:** \\n - **Location:** Osteria delle Commari \\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\n\\n- **Afternoon Attraction:** \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\n\\n- **Dinner:** \\n - **Location:** Tonnarello \\n - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\\n\\nIf you need any further assistance or modifications before your trip, just let me know. Enjoy your time in Rome!', 'name': 'route_timing_agent', 'role': 'user'}\n" - ] - } - ], + "outputs": [], "source": [ "for message in chat_result.chat_history:\n", " print(message)" From 92679e636c321dece75399151a1377e0dd5234c9 Mon Sep 17 00:00:00 2001 From: AgentGenie Date: Wed, 4 Dec 2024 00:06:25 -0800 Subject: [PATCH 08/20] Save knowledge graph ontology for future access. --- .../contrib/graph_rag/falkor_graph_query_engine.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py index c007c640b9..bcc41a00da 100644 --- a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +++ b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py @@ -55,13 +55,18 @@ def __init__( self.model_config = KnowledgeGraphModelConfig.with_model(model) self.ontology = ontology self.knowledge_graph = None + self.falkordb = FalkorDB(host=self.host, port=self.port, username=self.username, password=self.password) def connect_db(self): """ Connect to an existing knowledge graph. """ - falkordb = FalkorDB(host=self.host, port=self.port, username=self.username, password=self.password) - if self.name in falkordb.list_graphs(): + if self.name in self.falkordb.list_graphs(): + graph = self.falkordb.select_graph(self.name) + self.ontology = Ontology.from_graph(graph) + if self.ontology is None: + raise ValueError(f"Ontology of the knowledge graph '{self.name}' can't be None.") + self.knowledge_graph = KnowledgeGraph( name=self.name, host=self.host, @@ -108,6 +113,10 @@ def init_db(self, input_doc: List[Document]): # Establishing a chat session will maintain the history self._chat_session = self.knowledge_graph.chat_session() + + # Save Ontology to graph for future access. + graph = self.falkordb.select_graph(self.name) + self.ontology.save_to_graph(graph) else: raise ValueError("No input documents could be loaded.") From fd0811ba4f933bb8fb50ef6bb5d50d46aa691f02 Mon Sep 17 00:00:00 2001 From: AgentGenie Date: Wed, 4 Dec 2024 12:33:49 -0800 Subject: [PATCH 09/20] Fetch travel time and update Itinerary for route_timing_agent --- .../graph_rag/falkor_graph_query_engine.py | 9 +- ...gentchat_swarm_graphrag_trip_planner.ipynb | 120 +++++++++++++++--- website/docs/topics/swarm.ipynb | 6 +- 3 files changed, 113 insertions(+), 22 deletions(-) diff --git a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py index bcc41a00da..0bd3755dfc 100644 --- a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +++ b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import os -from dataclasses import dataclass, field +import warnings from typing import List from falkordb import FalkorDB @@ -63,7 +63,12 @@ def connect_db(self): """ if self.name in self.falkordb.list_graphs(): graph = self.falkordb.select_graph(self.name) - self.ontology = Ontology.from_graph(graph) + + try: + self.ontology = Ontology.from_graph(graph) + except Exception: + warnings.warn("Graph Ontology is not loaded.") + if self.ontology is None: raise ValueError(f"Ontology of the knowledge graph '{self.name}' can't be None.") diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 463c77f0dc..3949d6f057 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -67,18 +67,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/usr/local/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], + "outputs": [], "source": [ "import os\n", "\n", @@ -132,7 +123,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -285,7 +276,7 @@ "# Create FalkorGraphQueryEngine\n", "query_engine = FalkorGraphQueryEngine(\n", " name=\"trip_data\",\n", - " host=\"192.168.0.115\", # Change\n", + " host=\"172.18.0.3\", # Change\n", " port=6379, # if needed\n", " ontology=trip_data_ontology,\n", " model=OpenAiGenerativeModel(\"gpt-4o\"),\n", @@ -310,7 +301,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -373,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -397,6 +388,101 @@ " days: list[Day]" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We provide a function to the Route Timing agent to add travel time in between places." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "\n", + "# Load Google API key\n", + "API_KEY = os.environ.get(\"GOOGLE_MAP_API_KEY\")\n", + "\n", + "\n", + "def _fetch_travel_time(origin: str, destination: str) -> dict:\n", + " \"\"\"\n", + " Retrieves route information using Google Maps Directions API.\n", + " API documentation at https://developers.google.com/maps/documentation/directions/get-directions\n", + "\n", + " Parameters:\n", + " - origin (str): The starting point of the route.\n", + " - destination (str): The endpoint of the route.\n", + " - api_key (str): Google Maps API key.\n", + "\n", + " Returns:\n", + " - str: travel time in mins\n", + " \"\"\"\n", + " endpoint = \"https://maps.googleapis.com/maps/api/directions/json\"\n", + " params = {\n", + " \"origin\": origin,\n", + " \"destination\": destination,\n", + " \"mode\": \"walking\", # driving (default), bicycling, transit\n", + " \"key\": API_KEY,\n", + " }\n", + "\n", + " response = requests.get(endpoint, params=params)\n", + " if response.status_code == 200:\n", + " return response.json()\n", + " else:\n", + " return {\"error\": \"Failed to retrieve the route information\", \"status_code\": response.status_code}\n", + "\n", + "\n", + "def update_with_route_information(context_variables: dict) -> SwarmResult:\n", + " \"\"\"\n", + " Retrieves route information using Google Maps Directions API.\n", + " API documentation at https://developers.google.com/maps/documentation/directions/get-directions\n", + "\n", + " Parameters:\n", + " - context_variables from SwarmAgent hand-off\n", + " - origin (str): The starting point of the route.\n", + " - destination (str): The endpoint of the route.\n", + " - api_key (str): Google Maps API key.\n", + "\n", + " Returns:\n", + " - dict: The route information, or an error message.\n", + " \"\"\"\n", + " itinerary_output: Itinerary = context_variables[\"itinerary_structured\"]\n", + " for day in itinerary_output.days:\n", + " events = day.events\n", + " new_events = []\n", + " pre_event, cur_event = None, None\n", + " event_count = len(events)\n", + " index = 0\n", + " while index < event_count:\n", + " if index > 0:\n", + " pre_event = events[index - 1]\n", + " cur_event = events[index]\n", + " if pre_event:\n", + " origin = \", \".join([pre_event.location, pre_event.city])\n", + " destination = \", \".join([cur_event.location, cur_event.city])\n", + " maps_api_response = _fetch_travel_time(origin=origin, destination=destination)\n", + " try:\n", + " travel_time_txt = maps_api_response[\"routes\"][\"legs\"][\"duration\"][\"text\"]\n", + " new_events.append(\n", + " Event(\n", + " type=\"travel_time_in_between\",\n", + " location=\"walking\",\n", + " city=\" to \".join([pre_event.city, cur_event.city]),\n", + " description=travel_time_txt,\n", + " )\n", + " )\n", + " except Exception:\n", + " raise ValueError(\"Unable to get travel time from {} to {}\".format(origin, destination))\n", + " new_events.append(cur_event)\n", + " index += 1\n", + " day.events = new_events\n", + "\n", + " return SwarmResult(context_variables=context_variables, values=\"Itinerary updated with travel times\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -408,7 +494,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -447,7 +533,7 @@ "route_timing_agent = SwarmAgent(\n", " name=\"route_timing_agent\",\n", " system_message=\"You are a route timing agent. You will add estimated travel times to the itinerary\",\n", - " llm_config=llm_config, # Not sure if you need this, YZ\n", + " functions=[update_with_route_information],\n", ")\n", "\n", "# Our customer will be a human in the loop\n", diff --git a/website/docs/topics/swarm.ipynb b/website/docs/topics/swarm.ipynb index a445fb5db3..7b8aaf30b1 100644 --- a/website/docs/topics/swarm.ipynb +++ b/website/docs/topics/swarm.ipynb @@ -164,7 +164,7 @@ "\n", "\n", "# 1. A function that returns a value of \"success\" and updates the context variable \"1\" to True\n", - "def update_context_1(context_variables: dict) -> str:\n", + "def update_context_1(context_variables: dict) -> SwarmResult:\n", " context_variables[\"1\"] = True\n", " return SwarmResult(value=\"success\", context_variables=context_variables)\n", "\n", @@ -176,7 +176,7 @@ "\n", "\n", "# 3. A function that returns the value of \"success\", updates the context variable and transfers to agent 3\n", - "def update_context_2_and_transfer_to_3(context_variables: dict) -> str:\n", + "def update_context_2_and_transfer_to_3(context_variables: dict) -> SwarmResult:\n", " context_variables[\"2\"] = True\n", " return SwarmResult(value=\"success\", context_variables=context_variables, agent=agent_3)\n", "\n", @@ -186,7 +186,7 @@ " return random.randint(1, 100)\n", "\n", "\n", - "def update_context_3_with_random_number(context_variables: dict, random_number: int) -> str:\n", + "def update_context_3_with_random_number(context_variables: dict, random_number: int) -> SwarmResult:\n", " context_variables[\"3\"] = random_number\n", " return SwarmResult(value=\"success\", context_variables=context_variables)\n", "\n", From aea0c1a7356ccc2b1f5d6b78c86b4b8e40635689 Mon Sep 17 00:00:00 2001 From: AgentGenie Date: Wed, 4 Dec 2024 14:03:13 -0800 Subject: [PATCH 10/20] Fix Ontology save and load, use a separate table for ontology storage. --- .../graph_rag/falkor_graph_query_engine.py | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py index 0bd3755dfc..e5ea955dec 100644 --- a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +++ b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py @@ -6,7 +6,7 @@ import warnings from typing import List -from falkordb import FalkorDB +from falkordb import FalkorDB, Graph from graphrag_sdk import KnowledgeGraph, Source from graphrag_sdk.model_config import KnowledgeGraphModelConfig from graphrag_sdk.models import GenerativeModel @@ -62,10 +62,8 @@ def connect_db(self): Connect to an existing knowledge graph. """ if self.name in self.falkordb.list_graphs(): - graph = self.falkordb.select_graph(self.name) - try: - self.ontology = Ontology.from_graph(graph) + self.ontology = self._load_ontology_from_db(self.name) except Exception: warnings.warn("Graph Ontology is not loaded.") @@ -120,8 +118,7 @@ def init_db(self, input_doc: List[Document]): self._chat_session = self.knowledge_graph.chat_session() # Save Ontology to graph for future access. - graph = self.falkordb.select_graph(self.name) - self.ontology.save_to_graph(graph) + self._save_ontology_to_db(self.name, self.ontology) else: raise ValueError("No input documents could be loaded.") @@ -149,3 +146,18 @@ def query(self, question: str, n_results: int = 1, **kwargs) -> GraphStoreQueryR self._chat_session.last_answer = response["response"] return GraphStoreQueryResult(answer=response["response"], results=[]) + + def __get_ontology_storage_graph(self, graph_name: str) -> Graph: + ontology_table_name = graph_name + "_ontology" + return self.falkor_db.select_graph(ontology_table_name) + + def _save_ontology_to_db(self, graph_name: str, ontology: Ontology): + """ + Save graph ontology to a separate table with {graph_name}_ontology + """ + graph = self.__get_ontology_storage_graph(graph_name) + ontology.save_to_graph(graph) + + def _load_ontology_from_db(self, graph_name: str) -> Ontology: + graph = self.__get_ontology_storage_graph(graph_name) + return Ontology.from_graph(graph) From d05812c05ded5c53596adefc9824006ce7ba3acc Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 4 Dec 2024 23:31:18 +0000 Subject: [PATCH 11/20] Demo notebook updated - runs through Signed-off-by: Mark Sze --- ...gentchat_swarm_graphrag_trip_planner.ipynb | 723 +++++++++++++----- 1 file changed, 514 insertions(+), 209 deletions(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 3949d6f057..d65b149eda 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -32,7 +32,14 @@ "\n", "For more information, please refer to the [installation guide](/docs/installation/).\n", ":::\n", - "````" + "````\n", + "\n", + "### Pydantic\n", + "\n", + "Please ensure you have Pydantic version 2+ installed.\n", + "```bash\n", + "pip install --upgrade pydantic\n", + "```\n" ] }, { @@ -46,6 +53,17 @@ "In this example, we've set the FalkorDB host and port, please adjust them accordingly. For how to set up FalkorDB, please refer to [https://docs.falkordb.com/](https://docs.falkordb.com/).\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Google Maps API Key\n", + "\n", + "To use Google's API to calculate travel times, you will need to have enabled the `Directions API` in your Google Maps Platform. You can get an API key and free quota, see [here](https://developers.google.com/maps/documentation/directions/overview) and [here](https://developers.google.com/maps/get-started) for more details.\n", + "\n", + "Once you have your API key, set your environment variable `GOOGLE_MAP_API_KEY` to the key" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -67,9 +85,18 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n" + ] + } + ], "source": [ "import os\n", "\n", @@ -95,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -123,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -145,7 +172,6 @@ " ],\n", " )\n", ")\n", - "\n", "trip_data_ontology.add_entity(\n", " Entity(\n", " label=\"City\",\n", @@ -171,15 +197,6 @@ " ],\n", " )\n", ")\n", - "\n", - "trip_data_ontology.add_relation(\n", - " Relation(\n", - " label=\"IN_COUNTRY\",\n", - " source=\"City\",\n", - " target=\"Country\",\n", - " )\n", - ")\n", - "\n", "trip_data_ontology.add_entity(\n", " Entity(\n", " label=\"Restaurant\",\n", @@ -213,6 +230,13 @@ ")\n", "trip_data_ontology.add_relation(\n", " Relation(\n", + " label=\"IN_COUNTRY\",\n", + " source=\"City\",\n", + " target=\"Country\",\n", + " )\n", + ")\n", + "trip_data_ontology.add_relation(\n", + " Relation(\n", " label=\"IN_CITY\",\n", " source=\"Restaurant\",\n", " target=\"City\",\n", @@ -221,6 +245,44 @@ "\n", "trip_data_ontology.add_entity(\n", " Entity(\n", + " label=\"Country\",\n", + " attributes=[\n", + " Attribute(\n", + " name=\"name\",\n", + " attr_type=AttributeType.STRING,\n", + " required=True,\n", + " unique=True,\n", + " ),\n", + " ],\n", + " )\n", + ")\n", + "trip_data_ontology.add_entity(\n", + " Entity(\n", + " label=\"City\",\n", + " attributes=[\n", + " Attribute(\n", + " name=\"name\",\n", + " attr_type=AttributeType.STRING,\n", + " required=True,\n", + " unique=True,\n", + " ),\n", + " Attribute(\n", + " name=\"weather\",\n", + " attr_type=AttributeType.STRING,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " Attribute(\n", + " name=\"population\",\n", + " attr_type=AttributeType.NUMBER,\n", + " required=False,\n", + " unique=False,\n", + " ),\n", + " ],\n", + " )\n", + ")\n", + "trip_data_ontology.add_entity(\n", + " Entity(\n", " label=\"Attraction\",\n", " attributes=[\n", " Attribute(\n", @@ -246,6 +308,13 @@ ")\n", "trip_data_ontology.add_relation(\n", " Relation(\n", + " label=\"IN_COUNTRY\",\n", + " source=\"City\",\n", + " target=\"Country\",\n", + " )\n", + ")\n", + "trip_data_ontology.add_relation(\n", + " Relation(\n", " label=\"IN_CITY\",\n", " source=\"Attraction\",\n", " target=\"City\",\n", @@ -264,9 +333,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/autogen/ag2/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py:70: UserWarning: Graph Ontology is not loaded.\n", + " warnings.warn(\"Graph Ontology is not loaded.\")\n" + ] + } + ], "source": [ "from graphrag_sdk.models.openai import OpenAiGenerativeModel\n", "\n", @@ -276,38 +354,33 @@ "# Create FalkorGraphQueryEngine\n", "query_engine = FalkorGraphQueryEngine(\n", " name=\"trip_data\",\n", - " host=\"172.18.0.3\", # Change\n", + " host=\"192.168.0.115\", # Change\n", " port=6379, # if needed\n", " ontology=trip_data_ontology,\n", " model=OpenAiGenerativeModel(\"gpt-4o\"),\n", ")\n", "\n", "# Ingest data and initialize the database\n", - "query_engine.init_db(input_doc=input_documents)\n", + "# query_engine.init_db(input_doc=input_documents)\n", "\n", "# If you have already ingested and created the database, you can use this connect_db instead of init_db\n", - "# query_engine.connect_db()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Swarm\n", - "\n", - "### Context Variables\n", - "Our swarm agents will have access to a couple of context variables in relation to the itinerary." + "query_engine.connect_db()" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ + "# IMPORTS\n", + "\n", + "import ast\n", + "import os\n", "from enum import Enum\n", "from typing import Any, Dict\n", "\n", + "import requests\n", "from pydantic import BaseModel\n", "\n", "from autogen import (\n", @@ -316,38 +389,9 @@ " AfterWorkOption,\n", " SwarmAgent,\n", " SwarmResult,\n", - " UserProxyAgent,\n", " config_list_from_json,\n", " initiate_swarm_chat,\n", - ")\n", - "\n", - "trip_context = {\"itinerary_confirmed\": False, \"itinerary\": \"\"}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Agent Functions\n", - "\n", - "We're providing a function to our Planner agent to mark an itinerary as confirmed by the customer and to store the final itinerary. This will then transfer to our Structured Output agent." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def mark_itinerary_as_complete(final_itinerary: str, context_variables: Dict[str, Any]) -> SwarmResult:\n", - " \"\"\"Store and mark our itinerary as accepted by the customer.\"\"\"\n", - " context_variables[\"itinerary_confirmed\"] = True\n", - " context_variables[\"itinerary\"] = final_itinerary\n", - "\n", - " # This will update the context variables and then transfer to the Structured Output agent\n", - " return SwarmResult(\n", - " agent=\"structured_output_agent\", context_variables=context_variables, values=\"Itinerary recorded and confirmed.\"\n", - " )" + ")" ] }, { @@ -364,17 +408,12 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "class TypeEnum(str, Enum):\n", - " attraction = \"Attraction\"\n", - " restaurant = \"Restaurant\"\n", - "\n", - "\n", "class Event(BaseModel):\n", - " type: str\n", + " type: str # Attraction, Restaurant, Travel\n", " location: str\n", " city: str\n", " description: str\n", @@ -392,40 +431,28 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We provide a function to the Route Timing agent to add travel time in between places." + "### Google Maps Platform\n", + "\n", + "The functions necessary to query the Directions API to get travel times." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ - "import requests\n", - "\n", - "# Load Google API key\n", - "API_KEY = os.environ.get(\"GOOGLE_MAP_API_KEY\")\n", - "\n", - "\n", "def _fetch_travel_time(origin: str, destination: str) -> dict:\n", " \"\"\"\n", " Retrieves route information using Google Maps Directions API.\n", " API documentation at https://developers.google.com/maps/documentation/directions/get-directions\n", - "\n", - " Parameters:\n", - " - origin (str): The starting point of the route.\n", - " - destination (str): The endpoint of the route.\n", - " - api_key (str): Google Maps API key.\n", - "\n", - " Returns:\n", - " - str: travel time in mins\n", " \"\"\"\n", " endpoint = \"https://maps.googleapis.com/maps/api/directions/json\"\n", " params = {\n", " \"origin\": origin,\n", " \"destination\": destination,\n", " \"mode\": \"walking\", # driving (default), bicycling, transit\n", - " \"key\": API_KEY,\n", + " \"key\": os.environ.get(\"GOOGLE_MAP_API_KEY\"),\n", " }\n", "\n", " response = requests.get(endpoint, params=params)\n", @@ -435,22 +462,24 @@ " return {\"error\": \"Failed to retrieve the route information\", \"status_code\": response.status_code}\n", "\n", "\n", - "def update_with_route_information(context_variables: dict) -> SwarmResult:\n", + "def update_itinerary_with_travel_times(context_variables: dict) -> SwarmResult:\n", + " \"\"\"Update the complete itinerary with travel times between each event.\"\"\"\n", + "\n", " \"\"\"\n", " Retrieves route information using Google Maps Directions API.\n", " API documentation at https://developers.google.com/maps/documentation/directions/get-directions\n", + " \"\"\"\n", "\n", - " Parameters:\n", - " - context_variables from SwarmAgent hand-off\n", - " - origin (str): The starting point of the route.\n", - " - destination (str): The endpoint of the route.\n", - " - api_key (str): Google Maps API key.\n", + " # Ensure that we have a structured itinerary, if not, back to the structured_output_agent to make it\n", + " if context_variables.get(\"structured_itinerary\") is None:\n", + " return SwarmResult(\n", + " agent=\"structured_output_agent\",\n", + " values=\"Structured itinerary not found, please create the structured output, structured_output_agent.\",\n", + " )\n", "\n", - " Returns:\n", - " - dict: The route information, or an error message.\n", - " \"\"\"\n", - " itinerary_output: Itinerary = context_variables[\"itinerary_structured\"]\n", - " for day in itinerary_output.days:\n", + " # Process the itinerary, converting it back to an object and working through each event to work out travel time and distance\n", + " itinerary_object = Itinerary.model_validate(context_variables[\"structured_itinerary\"])\n", + " for day in itinerary_object.days:\n", " events = day.events\n", " new_events = []\n", " pre_event, cur_event = None, None\n", @@ -459,28 +488,109 @@ " while index < event_count:\n", " if index > 0:\n", " pre_event = events[index - 1]\n", + "\n", " cur_event = events[index]\n", " if pre_event:\n", " origin = \", \".join([pre_event.location, pre_event.city])\n", " destination = \", \".join([cur_event.location, cur_event.city])\n", " maps_api_response = _fetch_travel_time(origin=origin, destination=destination)\n", " try:\n", - " travel_time_txt = maps_api_response[\"routes\"][\"legs\"][\"duration\"][\"text\"]\n", + " leg = maps_api_response[\"routes\"][0][\"legs\"][0]\n", + " travel_time_txt = f\"{leg['duration']['text']}, ({leg['distance']['text']})\"\n", " new_events.append(\n", " Event(\n", - " type=\"travel_time_in_between\",\n", - " location=\"walking\",\n", - " city=\" to \".join([pre_event.city, cur_event.city]),\n", + " type=\"Travel\",\n", + " location=f\"walking from {pre_event.location} to {cur_event.location}\",\n", + " city=cur_event.city,\n", " description=travel_time_txt,\n", " )\n", " )\n", " except Exception:\n", - " raise ValueError(\"Unable to get travel time from {} to {}\".format(origin, destination))\n", + " print(f\"Note: Unable to get travel time from {origin} to {destination}\")\n", + " # raise ValueError(\"Unable to get travel time from {} to {}\".format(origin, destination))\n", " new_events.append(cur_event)\n", " index += 1\n", " day.events = new_events\n", "\n", - " return SwarmResult(context_variables=context_variables, values=\"Itinerary updated with travel times\")" + " context_variables[\"timed_itinerary\"] = itinerary_object.model_dump()\n", + "\n", + " return SwarmResult(context_variables=context_variables, values=\"Timed itinerary added to context with travel times\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Swarm\n", + "\n", + "### Context Variables\n", + "Our swarm agents will have access to a couple of context variables in relation to the itinerary." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "from autogen import (\n", + " SwarmResult,\n", + " UserProxyAgent,\n", + ")\n", + "\n", + "trip_context = {\n", + " \"itinerary_confirmed\": False,\n", + " \"itinerary\": \"\",\n", + " \"structured_itinerary\": None,\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Agent Functions\n", + "\n", + "We have two functions/tools for our agents.\n", + "\n", + "One for our Planner agent to mark an itinerary as confirmed by the customer and to store the final text itinerary. This will then transfer to our Structured Output agent.\n", + "\n", + "Another for the Structured Output Agent to save the structured itinerary and transfer to the Route Timing agent." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "def mark_itinerary_as_complete(final_itinerary: str, context_variables: Dict[str, Any]) -> SwarmResult:\n", + " \"\"\"Store and mark our itinerary as accepted by the customer.\"\"\"\n", + " context_variables[\"itinerary_confirmed\"] = True\n", + " context_variables[\"itinerary\"] = final_itinerary\n", + "\n", + " # This will update the context variables and then transfer to the Structured Output agent\n", + " return SwarmResult(\n", + " agent=\"structured_output_agent\", context_variables=context_variables, values=\"Itinerary recorded and confirmed.\"\n", + " )\n", + "\n", + "\n", + "def create_structured_itinerary(context_variables: Dict[str, Any], structured_itinerary: Itinerary) -> SwarmResult:\n", + " \"\"\"Once a structured itinerary is created, store it and pass on to the Route Timing agent.\"\"\"\n", + "\n", + " # Ensure the itinerary is confirmed, if not, back to the Planner agent to confirm it with the customer\n", + " if not context_variables[\"itinerary_confirmed\"]:\n", + " return SwarmResult(\n", + " agent=\"planner_agent\",\n", + " values=\"Itinerary not confirmed, please confirm the itinerary with the customer first.\",\n", + " )\n", + "\n", + " context_variables[\"structured_itinerary\"] = structured_itinerary\n", + "\n", + " # This will update the context variables and then transfer to the Route Timing agent\n", + " return SwarmResult(\n", + " agent=\"route_timing_agent\", context_variables=context_variables, values=\"Structured itinerary stored.\"\n", + " )" ] }, { @@ -494,7 +604,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -526,14 +636,16 @@ " name=\"structured_output_agent\",\n", " system_message=\"You are a data formatting agent, format the provided itinerary in the context below into the provided format.\",\n", " llm_config=llm_config,\n", + " functions=[create_structured_itinerary],\n", " response_format=Itinerary,\n", ")\n", "\n", - "# Route Timing agent, adding estimated travel times to the itinerary by utilising the Google Maps API\n", + "# Route Timing agent, adding estimated travel times to the itinerary by utilising the Google Maps Platform\n", "route_timing_agent = SwarmAgent(\n", " name=\"route_timing_agent\",\n", - " system_message=\"You are a route timing agent. You will add estimated travel times to the itinerary\",\n", - " functions=[update_with_route_information],\n", + " system_message=\"You are a route timing agent. IMPORTANT - you must call the update_itinerary_with_travel_times function until 'Timed itinerary added to context with travel times' is seen in this conversation. After that, you can tell the customer 'Your itinerary is ready!'.\",\n", + " llm_config=llm_config,\n", + " functions=[update_itinerary_with_travel_times],\n", ")\n", "\n", "# Our customer will be a human in the loop\n", @@ -553,12 +665,13 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "planner_agent.register_hand_off(\n", " hand_to=[\n", + " # Update to 'target' rather than 'agent'\n", " ON_CONDITION(\n", " graphrag_agent,\n", " \"Need information on the restaurants and attractions for a location. DO NOT call more than once at a time.\",\n", @@ -568,6 +681,7 @@ " ]\n", ")\n", "\n", + "\n", "# Back to the Planner when information has been retrieved\n", "graphrag_agent.register_hand_off(hand_to=[AFTER_WORK(planner_agent)])\n", "\n", @@ -591,7 +705,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -655,19 +769,19 @@ "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", "\n", "Restaurants in Rome:\n", - "- Trattoria da Enzo: A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", - "- Il Pagliaccio: An elegant Michelin-starred restaurant offering contemporary Italian cuisine.\n", - "- Tonnarello: Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\n", - "- Osteria delle Commari: Local home style Roman restaurant near Vatican Museums.\n", - "- Armando al Pantheon: Traditional Roman cuisine since 1961 near the Pantheon.\n", - "- Salumeria Roscioli Ristorante: Known for pasta alla gricia and amatriciana, and boasts an impressive wine cellar.\n", - "- L'Arcangelo: Famous for supplì (Roman rice balls) and gnocchi on Thursdays.\n", + "1. Trattoria da Enzo - Known for its traditional Roman dishes and welcoming atmosphere with a rating of 4.5.\n", + "2. Il Pagliaccio - An elegant Michelin-starred restaurant offering contemporary Italian cuisine with a rating of 4.8.\n", + "3. Tonnarello - Casual stop for pasta and other simple Roman dishes with a rating of 4.7.\n", + "4. Osteria delle Commari - Local home-style Roman restaurant near Vatican Museums with a rating of 4.3.\n", + "5. Armando al Pantheon - Traditional Roman cuisine near the Pantheon with a rating of 4.8.\n", + "6. Salumeria Roscioli Ristorante - Known for Pasta alla gricia and an impressive wine cellar with a rating of 4.5.\n", + "7. L'Arcangelo - Supplì are considered among the best in the city with a rating of 4.8.\n", "\n", "Attractions in Rome:\n", - "- Colosseum: An ancient amphitheater known for gladiatorial contests and public spectacles.\n", - "- Vatican Museums: A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", - "- Trevi Fountain: A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", - "- Basilica di Santa Maria Maggiore: A major basilica in Rome, known for its rich history and impressive architecture.\n", + "1. Colosseum - An ancient amphitheater known for gladiatorial contests.\n", + "2. Vatican Museums - A complex of museums and galleries showcasing art collected by Popes.\n", + "3. Trevi Fountain - A Baroque fountain famous for its stunning sculptures.\n", + "4. Basilica di Santa Maria Maggiore - A major basilica known for its history and architecture.\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -675,59 +789,63 @@ "\u001b[0m\n", "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", "\n", - "Great! Here's a preliminary itinerary for your 2-day trip to Rome, including attractions and meals. \n", + "Thank you for your patience! Here’s a preliminary itinerary for your 2-day trip to Rome:\n", "\n", "### Day 1:\n", "- **Morning Attraction:** \n", " - **Type:** Attraction \n", " - **Location:** Colosseum \n", " - **City:** Rome \n", - " - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\n", + " - **Description:** An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history. \n", "\n", "- **Lunch:** \n", " - **Type:** Restaurant \n", " - **Location:** Trattoria da Enzo \n", " - **City:** Rome \n", - " - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", + " - **Description:** Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\n", "\n", "- **Afternoon Attraction:** \n", " - **Type:** Attraction \n", " - **Location:** Trevi Fountain \n", " - **City:** Rome \n", - " - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", + " - **Description:** A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\n", "\n", "- **Dinner:** \n", " - **Type:** Restaurant \n", " - **Location:** Armando al Pantheon \n", " - **City:** Rome \n", - " - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\n", + " - **Description:** Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\n", + "\n", + "---\n", "\n", "### Day 2:\n", "- **Morning Attraction:** \n", " - **Type:** Attraction \n", " - **Location:** Vatican Museums \n", " - **City:** Rome \n", - " - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + " - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\n", "\n", "- **Lunch:** \n", " - **Type:** Restaurant \n", " - **Location:** Osteria delle Commari \n", " - **City:** Rome \n", - " - **Description:** Local home-style Roman restaurant near Vatican Museums.\n", + " - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\n", "\n", "- **Afternoon Attraction:** \n", " - **Type:** Attraction \n", " - **Location:** Basilica di Santa Maria Maggiore \n", " - **City:** Rome \n", - " - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\n", + " - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\n", "\n", "- **Dinner:** \n", " - **Type:** Restaurant \n", " - **Location:** Il Pagliaccio \n", " - **City:** Rome \n", - " - **Description:** An elegant Michelin-starred restaurant offering contemporary Italian cuisine.\n", + " - **Description:** An elegant Michelin-starred restaurant offering contemporary Italian cuisine for a special dining experience.\n", "\n", - "Please review this itinerary and let me know if it looks good to you or if you'd like to make any adjustments!\n", + "---\n", + "\n", + "Does this itinerary look good to you, or would you like to make any changes?\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -735,7 +853,7 @@ "\u001b[0m\n", "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", "\n", - "I've eaten at Il Pagliaccio and didn't like it.\n", + "Change out Il Pagliaccio please\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -743,7 +861,7 @@ "\u001b[0m\n", "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", "\n", - "\u001b[32m***** Suggested tool call (call_8RcnbYXeN4Hq862VMhtOA9Rl): transfer_to_graphrag_agent *****\u001b[0m\n", + "\u001b[32m***** Suggested tool call (call_kK43xij89ce8xnIyFP4S33zn): transfer_to_graphrag_agent *****\u001b[0m\n", "Arguments: \n", "{}\n", "\u001b[32m*******************************************************************************************\u001b[0m\n", @@ -756,7 +874,7 @@ ">>>>>>>> EXECUTING FUNCTION transfer_to_graphrag_agent...\u001b[0m\n", "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", - "\u001b[32m***** Response from calling tool (call_8RcnbYXeN4Hq862VMhtOA9Rl) *****\u001b[0m\n", + "\u001b[32m***** Response from calling tool (call_kK43xij89ce8xnIyFP4S33zn) *****\u001b[0m\n", "SwarmAgent --> graphrag_agent\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", @@ -767,18 +885,18 @@ "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", "\n", "Restaurants in Rome:\n", - "- Trattoria da Enzo: A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", - "- Tonnarello: Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\n", - "- Osteria delle Commari: Local home-style Roman restaurant near Vatican Museums.\n", - "- Armando al Pantheon: Traditional Roman cuisine since 1961 near the Pantheon.\n", - "- Salumeria Roscioli Ristorante: Known for pasta alla gricia and amatriciana, and boasts an impressive wine cellar.\n", - "- L'Arcangelo: Famous for supplì (Roman rice balls) and gnocchi on Thursdays.\n", + "1. Trattoria da Enzo - Known for its traditional Roman dishes and welcoming atmosphere with a rating of 4.5.\n", + "2. Tonnarello - Casual stop for pasta and other simple Roman dishes with a rating of 4.7.\n", + "3. Osteria delle Commari - Local home-style Roman restaurant near Vatican Museums with a rating of 4.3.\n", + "4. Armando al Pantheon - Traditional Roman cuisine near the Pantheon with a rating of 4.8.\n", + "5. Salumeria Roscioli Ristorante - Known for Pasta alla gricia and an impressive wine cellar with a rating of 4.5.\n", + "6. L'Arcangelo - Supplì are considered among the best in the city with a rating of 4.8.\n", "\n", "Attractions in Rome:\n", - "- Colosseum: An ancient amphitheater known for gladiatorial contests and public spectacles.\n", - "- Vatican Museums: A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", - "- Trevi Fountain: A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", - "- Basilica di Santa Maria Maggiore: A major basilica in Rome, known for its rich history and impressive architecture.\n", + "1. Colosseum - An ancient amphitheater known for gladiatorial contests.\n", + "2. Vatican Museums - A complex of museums and galleries showcasing art collected by Popes.\n", + "3. Trevi Fountain - A Baroque fountain famous for its stunning sculptures.\n", + "4. Basilica di Santa Maria Maggiore - A major basilica known for its history and architecture.\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -786,59 +904,38 @@ "\u001b[0m\n", "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", "\n", - "Thank you for the feedback! Here's an updated itinerary with a different restaurant for your second dinner:\n", - "\n", - "### Day 1:\n", - "- **Morning Attraction:** \n", - " - **Type:** Attraction \n", - " - **Location:** Colosseum \n", - " - **City:** Rome \n", - " - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\n", - "\n", - "- **Lunch:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Trattoria da Enzo \n", - " - **City:** Rome \n", - " - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", + "Thank you for your response! Since you want to change out Il Pagliaccio, here’s an updated itinerary for your second evening in Rome:\n", "\n", - "- **Afternoon Attraction:** \n", - " - **Type:** Attraction \n", - " - **Location:** Trevi Fountain \n", - " - **City:** Rome \n", - " - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", - "\n", - "- **Dinner:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Armando al Pantheon \n", - " - **City:** Rome \n", - " - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\n", + "---\n", "\n", "### Day 2:\n", "- **Morning Attraction:** \n", " - **Type:** Attraction \n", " - **Location:** Vatican Museums \n", " - **City:** Rome \n", - " - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + " - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\n", "\n", "- **Lunch:** \n", " - **Type:** Restaurant \n", " - **Location:** Osteria delle Commari \n", " - **City:** Rome \n", - " - **Description:** Local home-style Roman restaurant near Vatican Museums.\n", + " - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\n", "\n", "- **Afternoon Attraction:** \n", " - **Type:** Attraction \n", " - **Location:** Basilica di Santa Maria Maggiore \n", " - **City:** Rome \n", - " - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\n", + " - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\n", "\n", "- **Dinner:** \n", " - **Type:** Restaurant \n", " - **Location:** Tonnarello \n", " - **City:** Rome \n", - " - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\n", + " - **Description:** A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\n", + "\n", + "---\n", "\n", - "Please take a look at this updated itinerary and let me know if you're happy with it or if you'd like to make further changes!\n", + "Please review this updated itinerary. Are you happy with it, or would you like to make any other changes?\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -846,7 +943,7 @@ "\u001b[0m\n", "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", "\n", - "Great, lock it in.\n", + "Perfect, let's go!\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -854,9 +951,9 @@ "\u001b[0m\n", "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", "\n", - "\u001b[32m***** Suggested tool call (call_yZeiuwaTMJIwthHTxUt7NGEx): mark_itinerary_as_complete *****\u001b[0m\n", + "\u001b[32m***** Suggested tool call (call_AQmHaXoGospsVPDE0hMiHcKm): mark_itinerary_as_complete *****\u001b[0m\n", "Arguments: \n", - "{\"final_itinerary\":\"### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** Local home-style Roman restaurant near Vatican Museums.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\"}\n", + "{\"final_itinerary\":\"### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history. \\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\\n\\n---\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}\n", "\u001b[32m*******************************************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", @@ -867,7 +964,7 @@ ">>>>>>>> EXECUTING FUNCTION mark_itinerary_as_complete...\u001b[0m\n", "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", - "\u001b[32m***** Response from calling tool (call_yZeiuwaTMJIwthHTxUt7NGEx) *****\u001b[0m\n", + "\u001b[32m***** Response from calling tool (call_AQmHaXoGospsVPDE0hMiHcKm) *****\u001b[0m\n", "Itinerary recorded and confirmed.\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", @@ -877,7 +974,7 @@ "\u001b[0m\n", "\u001b[33mstructured_output_agent\u001b[0m (to chat_manager):\n", "\n", - "{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and public spectacles.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Traditional Roman cuisine since 1961, located near the Pantheon.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing works of art collected by Popes over centuries.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"Local home-style Roman restaurant near Vatican Museums.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica in Rome, known for its rich history and impressive architecture.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\"}]}]}\n", + "{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}]}]}\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -885,43 +982,76 @@ "\u001b[0m\n", "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", "\n", - "Your itinerary for your 2-day trip to Rome is confirmed! Here are the details:\n", + "\u001b[32m***** Suggested tool call (call_YbfQMAB7sauRv0038iGdBYCG): update_itinerary_with_travel_times *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m***************************************************************************************************\u001b[0m\n", "\n", - "### Day 1:\n", - "- **Morning Attraction:** \n", - " - **Location:** Colosseum \n", - " - **Description:** An ancient amphitheater known for gladiatorial contests and public spectacles.\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION update_itinerary_with_travel_times...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", - "- **Lunch:** \n", - " - **Location:** Trattoria da Enzo \n", - " - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", + "\u001b[32m***** Response from calling tool (call_YbfQMAB7sauRv0038iGdBYCG) *****\u001b[0m\n", + "Structured itinerary not found, please create the structured output, structured_output_agent.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", "\n", - "- **Afternoon Attraction:** \n", - " - **Location:** Trevi Fountain \n", - " - **Description:** A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: structured_output_agent\n", + "\u001b[0m\n", + "\u001b[33mstructured_output_agent\u001b[0m (to chat_manager):\n", "\n", - "- **Dinner:** \n", - " - **Location:** Armando al Pantheon \n", - " - **Description:** Traditional Roman cuisine since 1961, located near the Pantheon.\n", + "\u001b[32m***** Suggested tool call (call_ZXP5Ibumjwi4fQ3i2BxmIwmf): create_structured_itinerary *****\u001b[0m\n", + "Arguments: \n", + "{\"structured_itinerary\":{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}]}]}}\n", + "\u001b[32m********************************************************************************************\u001b[0m\n", "\n", - "### Day 2:\n", - "- **Morning Attraction:** \n", - " - **Location:** Vatican Museums \n", - " - **Description:** A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION create_structured_itinerary...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", - "- **Lunch:** \n", - " - **Location:** Osteria delle Commari \n", - " - **Description:** Local home-style Roman restaurant near Vatican Museums.\n", + "\u001b[32m***** Response from calling tool (call_ZXP5Ibumjwi4fQ3i2BxmIwmf) *****\u001b[0m\n", + "Structured itinerary stored.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", "\n", - "- **Afternoon Attraction:** \n", - " - **Location:** Basilica di Santa Maria Maggiore \n", - " - **Description:** A major basilica in Rome, known for its rich history and impressive architecture.\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: route_timing_agent\n", + "\u001b[0m\n", + "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", "\n", - "- **Dinner:** \n", - " - **Location:** Tonnarello \n", - " - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\n", + "\u001b[32m***** Suggested tool call (call_JWlxdrbVQMuItq9NAMMmT2DC): update_itinerary_with_travel_times *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m***************************************************************************************************\u001b[0m\n", "\n", - "If you need any further assistance or modifications before your trip, just let me know. Enjoy your time in Rome!\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION update_itinerary_with_travel_times...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_JWlxdrbVQMuItq9NAMMmT2DC) *****\u001b[0m\n", + "Timed itinerary added to context with travel times\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: route_timing_agent\n", + "\u001b[0m\n", + "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", + "\n", + "Your itinerary is ready! Enjoy your trip to Rome!\n", "\n", "--------------------------------------------------------------------------------\n" ] @@ -937,27 +1067,202 @@ " context_variables=trip_context,\n", " messages=\"I want to go to Rome for a couple of days. Can you help me plan my trip?\",\n", " after_work=AfterWorkOption.TERMINATE,\n", + " max_rounds=100,\n", ")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Context: {'itinerary_confirmed': True, 'itinerary': \"### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history. \\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\\n\\n---\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\", 'structured_itinerary': {'days': [{'events': [{'type': 'Attraction', 'location': 'Colosseum', 'city': 'Rome', 'description': \"An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history.\"}, {'type': 'Restaurant', 'location': 'Trattoria da Enzo', 'city': 'Rome', 'description': 'Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.'}, {'type': 'Attraction', 'location': 'Trevi Fountain', 'city': 'Rome', 'description': 'A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.'}, {'type': 'Restaurant', 'location': 'Armando al Pantheon', 'city': 'Rome', 'description': 'Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.'}]}, {'events': [{'type': 'Attraction', 'location': 'Vatican Museums', 'city': 'Rome', 'description': 'A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.'}, {'type': 'Restaurant', 'location': 'Osteria delle Commari', 'city': 'Rome', 'description': 'A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.'}, {'type': 'Attraction', 'location': 'Basilica di Santa Maria Maggiore', 'city': 'Rome', 'description': 'A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.'}, {'type': 'Restaurant', 'location': 'Tonnarello', 'city': 'Rome', 'description': 'A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.'}]}]}, 'timed_itinerary': {'days': [{'events': [{'type': 'Attraction', 'location': 'Colosseum', 'city': 'Rome', 'description': \"An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history.\"}, {'type': 'Travel', 'location': 'walking from Colosseum to Trattoria da Enzo', 'city': 'Rome', 'description': '24 mins, (1.8 km)'}, {'type': 'Restaurant', 'location': 'Trattoria da Enzo', 'city': 'Rome', 'description': 'Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.'}, {'type': 'Travel', 'location': 'walking from Trattoria da Enzo to Trevi Fountain', 'city': 'Rome', 'description': '28 mins, (2.0 km)'}, {'type': 'Attraction', 'location': 'Trevi Fountain', 'city': 'Rome', 'description': 'A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.'}, {'type': 'Travel', 'location': 'walking from Trevi Fountain to Armando al Pantheon', 'city': 'Rome', 'description': '9 mins, (0.7 km)'}, {'type': 'Restaurant', 'location': 'Armando al Pantheon', 'city': 'Rome', 'description': 'Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.'}]}, {'events': [{'type': 'Attraction', 'location': 'Vatican Museums', 'city': 'Rome', 'description': 'A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.'}, {'type': 'Travel', 'location': 'walking from Vatican Museums to Osteria delle Commari', 'city': 'Rome', 'description': '2 mins, (0.2 km)'}, {'type': 'Restaurant', 'location': 'Osteria delle Commari', 'city': 'Rome', 'description': 'A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.'}, {'type': 'Travel', 'location': 'walking from Osteria delle Commari to Basilica di Santa Maria Maggiore', 'city': 'Rome', 'description': '1 hour 5 mins, (4.6 km)'}, {'type': 'Attraction', 'location': 'Basilica di Santa Maria Maggiore', 'city': 'Rome', 'description': 'A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.'}, {'type': 'Travel', 'location': 'walking from Basilica di Santa Maria Maggiore to Tonnarello', 'city': 'Rome', 'description': '44 mins, (3.2 km)'}, {'type': 'Restaurant', 'location': 'Tonnarello', 'city': 'Rome', 'description': 'A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.'}]}]}}\n" + ] + } + ], "source": [ "print(f\"Context: {context_variables}\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'content': 'I want to go to Rome for a couple of days. Can you help me plan my trip?', 'role': 'assistant', 'name': 'customer'}\n", + "{'content': \"Of course! I'd love to help you plan your trip to Rome. \\n\\nTo get started, could you please provide me with the following information:\\n1. How many days will you be staying in Rome?\\n2. What activities or attractions are you interested in? (e.g., historical sites, museums, shopping, dining, etc.)\\n3. Do you have any specific preferences for meals or restaurants? \\n\\nOnce I have this information, I can start creating an itinerary for you!\", 'name': 'planner_agent', 'role': 'user'}\n", + "{'content': '2 days please, I want lunch and dinner, with an attraction to see in the morning and after lunch.', 'role': 'assistant', 'name': 'customer'}\n", + "{'content': 'None', 'tool_calls': [{'id': 'call_2dmMbckU5YjaCsL6Y8pWbrdK', 'function': {'arguments': '{}', 'name': 'transfer_to_graphrag_agent'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", + "{'content': 'SwarmAgent --> graphrag_agent', 'tool_responses': [{'tool_call_id': 'call_2dmMbckU5YjaCsL6Y8pWbrdK', 'role': 'tool', 'content': 'SwarmAgent --> graphrag_agent'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", + "{'content': \"Restaurants in Rome:\\n1. Trattoria da Enzo - Known for its traditional Roman dishes and welcoming atmosphere with a rating of 4.5.\\n2. Il Pagliaccio - An elegant Michelin-starred restaurant offering contemporary Italian cuisine with a rating of 4.8.\\n3. Tonnarello - Casual stop for pasta and other simple Roman dishes with a rating of 4.7.\\n4. Osteria delle Commari - Local home-style Roman restaurant near Vatican Museums with a rating of 4.3.\\n5. Armando al Pantheon - Traditional Roman cuisine near the Pantheon with a rating of 4.8.\\n6. Salumeria Roscioli Ristorante - Known for Pasta alla gricia and an impressive wine cellar with a rating of 4.5.\\n7. L'Arcangelo - Supplì are considered among the best in the city with a rating of 4.8.\\n\\nAttractions in Rome:\\n1. Colosseum - An ancient amphitheater known for gladiatorial contests.\\n2. Vatican Museums - A complex of museums and galleries showcasing art collected by Popes.\\n3. Trevi Fountain - A Baroque fountain famous for its stunning sculptures.\\n4. Basilica di Santa Maria Maggiore - A major basilica known for its history and architecture.\", 'name': 'graphrag_agent', 'role': 'user'}\n", + "{'content': \"Thank you for your patience! Here’s a preliminary itinerary for your 2-day trip to Rome:\\n\\n### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history. \\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\\n\\n---\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Il Pagliaccio \\n - **City:** Rome \\n - **Description:** An elegant Michelin-starred restaurant offering contemporary Italian cuisine for a special dining experience.\\n\\n---\\n\\nDoes this itinerary look good to you, or would you like to make any changes?\", 'name': 'planner_agent', 'role': 'user'}\n", + "{'content': 'Change out Il Pagliaccio please', 'role': 'assistant', 'name': 'customer'}\n", + "{'content': 'None', 'tool_calls': [{'id': 'call_kK43xij89ce8xnIyFP4S33zn', 'function': {'arguments': '{}', 'name': 'transfer_to_graphrag_agent'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", + "{'content': 'SwarmAgent --> graphrag_agent', 'tool_responses': [{'tool_call_id': 'call_kK43xij89ce8xnIyFP4S33zn', 'role': 'tool', 'content': 'SwarmAgent --> graphrag_agent'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", + "{'content': \"Restaurants in Rome:\\n1. Trattoria da Enzo - Known for its traditional Roman dishes and welcoming atmosphere with a rating of 4.5.\\n2. Tonnarello - Casual stop for pasta and other simple Roman dishes with a rating of 4.7.\\n3. Osteria delle Commari - Local home-style Roman restaurant near Vatican Museums with a rating of 4.3.\\n4. Armando al Pantheon - Traditional Roman cuisine near the Pantheon with a rating of 4.8.\\n5. Salumeria Roscioli Ristorante - Known for Pasta alla gricia and an impressive wine cellar with a rating of 4.5.\\n6. L'Arcangelo - Supplì are considered among the best in the city with a rating of 4.8.\\n\\nAttractions in Rome:\\n1. Colosseum - An ancient amphitheater known for gladiatorial contests.\\n2. Vatican Museums - A complex of museums and galleries showcasing art collected by Popes.\\n3. Trevi Fountain - A Baroque fountain famous for its stunning sculptures.\\n4. Basilica di Santa Maria Maggiore - A major basilica known for its history and architecture.\", 'name': 'graphrag_agent', 'role': 'user'}\n", + "{'content': 'Thank you for your response! Since you want to change out Il Pagliaccio, here’s an updated itinerary for your second evening in Rome:\\n\\n---\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\\n\\n---\\n\\nPlease review this updated itinerary. Are you happy with it, or would you like to make any other changes?', 'name': 'planner_agent', 'role': 'user'}\n", + "{'content': \"Perfect, let's go!\", 'role': 'assistant', 'name': 'customer'}\n", + "{'content': 'None', 'tool_calls': [{'id': 'call_AQmHaXoGospsVPDE0hMiHcKm', 'function': {'arguments': '{\"final_itinerary\":\"### Day 1:\\\\n- **Morning Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Colosseum \\\\n - **City:** Rome \\\\n - **Description:** An ancient amphitheater known for gladiatorial contests and a symbol of the city\\'s rich history. \\\\n\\\\n- **Lunch:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Trattoria da Enzo \\\\n - **City:** Rome \\\\n - **Description:** Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\\\\n\\\\n- **Afternoon Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Trevi Fountain \\\\n - **City:** Rome \\\\n - **Description:** A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\\\\n\\\\n- **Dinner:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Armando al Pantheon \\\\n - **City:** Rome \\\\n - **Description:** Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\\\\n\\\\n---\\\\n\\\\n### Day 2:\\\\n- **Morning Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Vatican Museums \\\\n - **City:** Rome \\\\n - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\\\\n\\\\n- **Lunch:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Osteria delle Commari \\\\n - **City:** Rome \\\\n - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\\\\n\\\\n- **Afternoon Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Basilica di Santa Maria Maggiore \\\\n - **City:** Rome \\\\n - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\\\\n\\\\n- **Dinner:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Tonnarello \\\\n - **City:** Rome \\\\n - **Description:** A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}', 'name': 'mark_itinerary_as_complete'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", + "{'content': 'Itinerary recorded and confirmed.', 'tool_responses': [{'tool_call_id': 'call_AQmHaXoGospsVPDE0hMiHcKm', 'role': 'tool', 'content': 'Itinerary recorded and confirmed.'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", + "{'content': '{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and a symbol of the city\\'s rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}]}]}', 'name': 'structured_output_agent', 'role': 'user'}\n", + "{'content': 'None', 'tool_calls': [{'id': 'call_YbfQMAB7sauRv0038iGdBYCG', 'function': {'arguments': '{}', 'name': 'update_itinerary_with_travel_times'}, 'type': 'function'}], 'name': 'route_timing_agent', 'role': 'assistant'}\n", + "{'content': 'Structured itinerary not found, please create the structured output, structured_output_agent.', 'tool_responses': [{'tool_call_id': 'call_YbfQMAB7sauRv0038iGdBYCG', 'role': 'tool', 'content': 'Structured itinerary not found, please create the structured output, structured_output_agent.'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", + "{'content': 'None', 'tool_calls': [{'id': 'call_ZXP5Ibumjwi4fQ3i2BxmIwmf', 'function': {'arguments': '{\"structured_itinerary\":{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and a symbol of the city\\'s rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}]}]}}', 'name': 'create_structured_itinerary'}, 'type': 'function'}], 'name': 'structured_output_agent', 'role': 'assistant'}\n", + "{'content': 'Structured itinerary stored.', 'tool_responses': [{'tool_call_id': 'call_ZXP5Ibumjwi4fQ3i2BxmIwmf', 'role': 'tool', 'content': 'Structured itinerary stored.'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", + "{'content': 'None', 'tool_calls': [{'id': 'call_JWlxdrbVQMuItq9NAMMmT2DC', 'function': {'arguments': '{}', 'name': 'update_itinerary_with_travel_times'}, 'type': 'function'}], 'name': 'route_timing_agent', 'role': 'assistant'}\n", + "{'content': 'Timed itinerary added to context with travel times', 'tool_responses': [{'tool_call_id': 'call_JWlxdrbVQMuItq9NAMMmT2DC', 'role': 'tool', 'content': 'Timed itinerary added to context with travel times'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", + "{'content': 'Your itinerary is ready! Enjoy your trip to Rome!', 'name': 'route_timing_agent', 'role': 'user'}\n" + ] + } + ], "source": [ "for message in chat_result.chat_history:\n", " print(message)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Bonus itinerary output" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " █ █ \n", + " █ █ \n", + " █ █████ █ \n", + " ██ ██ \n", + " █ █ \n", + " █ ███████ █ \n", + " █ ██ ███ ██ █ \n", + " █████████ \n", + " \n", + " ██ ███ ███ \n", + " █ █ █ █ \n", + " ████ █ ██ ██ \n", + " █ █ █ █ █ \n", + " █ █ ██ ████ \n", + " \n", + " Itinerary for Rome \n", + "================================================================================\n", + " \n", + "Day 1 \n", + "--------------------------------------------------------------------------------\n", + "\n", + " 🏛️ Colosseum\n", + " An ancient amphitheater known for gladiatorial contests and a symbol of \n", + " the city's rich history. \n", + "\n", + " 🚶 walking from Colosseum to Trattoria da Enzo\n", + " 24 mins, (1.8 km)\n", + "\n", + " 🍽️ Trattoria da Enzo\n", + " Known for its traditional Roman dishes and a welcoming atmosphere, \n", + " perfect for a hearty lunch. \n", + "\n", + " 🚶 walking from Trattoria da Enzo to Trevi Fountain\n", + " 28 mins, (2.0 km)\n", + "\n", + " 🏛️ Trevi Fountain\n", + " A Baroque fountain famous for its stunning sculptures and a popular \n", + " spot for tourists to toss in a coin for good luck. \n", + "\n", + " 🚶 walking from Trevi Fountain to Armando al Pantheon\n", + " 9 mins, (0.7 km)\n", + "\n", + " 🍽️ Armando al Pantheon\n", + " Serves traditional Roman cuisine near the Pantheon, offering an \n", + " authentic dining experience. \n", + "\n", + "--------------------------------------------------------------------------------\n", + " \n", + "Day 2 \n", + "--------------------------------------------------------------------------------\n", + "\n", + " 🏛️ Vatican Museums\n", + " A complex of museums and galleries showcasing art collected by Popes, \n", + " including the Sistine Chapel. \n", + "\n", + " 🚶 walking from Vatican Museums to Osteria delle Commari\n", + " 2 mins, (0.2 km)\n", + "\n", + " 🍽️ Osteria delle Commari\n", + " A local home-style Roman restaurant near the Vatican Museums for a \n", + " delightful lunch. \n", + "\n", + " 🚶 walking from Osteria delle Commari to Basilica di Santa Maria Maggiore\n", + " 1 hour 5 mins, (4.6 km)\n", + "\n", + " 🏛️ Basilica di Santa Maria Maggiore\n", + " A major basilica known for its rich history and impressive \n", + " architecture, a serene spot to visit after lunch. \n", + "\n", + " 🚶 walking from Basilica di Santa Maria Maggiore to Tonnarello\n", + " 44 mins, (3.2 km)\n", + "\n", + " 🍽️ Tonnarello\n", + " A casual stop for pasta and other simple Roman dishes, perfect for a \n", + " relaxed dinner to cap off your trip. \n", + "\n", + "--------------------------------------------------------------------------------\n" + ] + } + ], + "source": [ + "def print_itinerary(itinerary_data):\n", + " header = \"█ █\\n █ █ \\n █ █████ █ \\n ██ ██ \\n █ █ \\n █ ███████ █ \\n █ ██ ███ ██ █ \\n █████████ \\n\\n ██ ███ ███ \\n█ █ █ █ \\n████ █ ██ ██ \\n█ █ █ █ █ \\n█ █ ██ ████ \\n\"\n", + " width = 80\n", + " icons = {\"Travel\": \"🚶\", \"Restaurant\": \"🍽️\", \"Attraction\": \"🏛️\"}\n", + "\n", + " for line in header.split(\"\\n\"):\n", + " print(line.center(width))\n", + " print(f\"Itinerary for {itinerary_data['days'][0]['events'][0]['city']}\".center(width))\n", + " print(\"=\" * width)\n", + "\n", + " for day_num, day in enumerate(itinerary_data[\"days\"], 1):\n", + " print(f\"\\nDay {day_num}\".center(width))\n", + " print(\"-\" * width)\n", + "\n", + " for event in day[\"events\"]:\n", + " event_type = event[\"type\"]\n", + " print(f\"\\n {icons[event_type]} {event['location']}\")\n", + " if event_type != \"Travel\":\n", + " words = event[\"description\"].split()\n", + " line = \" \"\n", + " for word in words:\n", + " if len(line) + len(word) + 1 <= 76:\n", + " line += word + \" \"\n", + " else:\n", + " print(line)\n", + " line = \" \" + word + \" \"\n", + " if line.strip():\n", + " print(line)\n", + " else:\n", + " print(f\" {event['description']}\")\n", + " print(\"\\n\" + \"-\" * width)\n", + "\n", + "\n", + "if \"timed_itinerary\" in context_variables:\n", + " print_itinerary(context_variables[\"timed_itinerary\"])\n", + "else:\n", + " print(\"No itinerary available to print.\")" + ] } ], "metadata": { From fa8cf6a551199cf24a11fb6764bff77618b997cb Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Thu, 5 Dec 2024 01:17:36 +0000 Subject: [PATCH 12/20] Fix reference: falkor_db to falkordb Signed-off-by: Mark Sze --- .../agentchat/contrib/graph_rag/falkor_graph_query_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py index e5ea955dec..58e6fcb889 100644 --- a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +++ b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py @@ -149,7 +149,7 @@ def query(self, question: str, n_results: int = 1, **kwargs) -> GraphStoreQueryR def __get_ontology_storage_graph(self, graph_name: str) -> Graph: ontology_table_name = graph_name + "_ontology" - return self.falkor_db.select_graph(ontology_table_name) + return self.falkordb.select_graph(ontology_table_name) def _save_ontology_to_db(self, graph_name: str, ontology: Ontology): """ From 2b1481d26d9cb3bad95407662cad58ed603f2035 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Thu, 5 Dec 2024 01:34:33 +0000 Subject: [PATCH 13/20] Tidy of notebook Signed-off-by: Mark Sze --- ...gentchat_swarm_graphrag_trip_planner.ipynb | 561 +----------------- 1 file changed, 21 insertions(+), 540 deletions(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index d65b149eda..40a52018c9 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Trip planning with a FalkorDB GraphRAG agent in Swarm\n", + "# Trip planning with a FalkorDB GraphRAG agent using a Swarm\n", "\n", "In this notebook, we're building a trip planning swarm which has an objective to create an itinerary together with a customer. The end result will be an itinerary that has route times and distances calculated between activities.\n", "\n", @@ -13,9 +13,7 @@ "- FalkorDB agent using a GraphRAG database of restaurants and attractions\n", "- Structured Output agent that will enforce a strict format for the accepted itinerary\n", "- Routing agent that utilises the Google Maps API to calculate distances between activites\n", - "- Swarm orchestration with hand offs, system message updates, and context variables\n", - "\n", - "[DIAGRAM OF THE PLAN]" + "- Swarm orchestration utilising context variables" ] }, { @@ -85,18 +83,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/usr/local/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], + "outputs": [], "source": [ "import os\n", "\n", @@ -122,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -150,7 +139,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -333,18 +322,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/autogen/ag2/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py:70: UserWarning: Graph Ontology is not loaded.\n", - " warnings.warn(\"Graph Ontology is not loaded.\")\n" - ] - } - ], + "outputs": [], "source": [ "from graphrag_sdk.models.openai import OpenAiGenerativeModel\n", "\n", @@ -369,15 +349,12 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# IMPORTS\n", - "\n", - "import ast\n", "import os\n", - "from enum import Enum\n", "from typing import Any, Dict\n", "\n", "import requests\n", @@ -389,7 +366,7 @@ " AfterWorkOption,\n", " SwarmAgent,\n", " SwarmResult,\n", - " config_list_from_json,\n", + " UserProxyAgent,\n", " initiate_swarm_chat,\n", ")" ] @@ -408,7 +385,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -438,7 +415,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -507,7 +484,6 @@ " )\n", " except Exception:\n", " print(f\"Note: Unable to get travel time from {origin} to {destination}\")\n", - " # raise ValueError(\"Unable to get travel time from {} to {}\".format(origin, destination))\n", " new_events.append(cur_event)\n", " index += 1\n", " day.events = new_events\n", @@ -529,15 +505,10 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "from autogen import (\n", - " SwarmResult,\n", - " UserProxyAgent,\n", - ")\n", - "\n", "trip_context = {\n", " \"itinerary_confirmed\": False,\n", " \"itinerary\": \"\",\n", @@ -560,7 +531,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -604,7 +575,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -665,7 +636,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -705,360 +676,11 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", - "\n", - "I want to go to Rome for a couple of days. Can you help me plan my trip?\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "Of course! I'd love to help you plan your trip to Rome. \n", - "\n", - "To get started, could you please provide me with the following information:\n", - "1. How many days will you be staying in Rome?\n", - "2. What activities or attractions are you interested in? (e.g., historical sites, museums, shopping, dining, etc.)\n", - "3. Do you have any specific preferences for meals or restaurants? \n", - "\n", - "Once I have this information, I can start creating an itinerary for you!\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: customer\n", - "\u001b[0m\n", - "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", - "\n", - "2 days please, I want lunch and dinner, with an attraction to see in the morning and after lunch.\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Suggested tool call (call_2dmMbckU5YjaCsL6Y8pWbrdK): transfer_to_graphrag_agent *****\u001b[0m\n", - "Arguments: \n", - "{}\n", - "\u001b[32m*******************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION transfer_to_graphrag_agent...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_2dmMbckU5YjaCsL6Y8pWbrdK) *****\u001b[0m\n", - "SwarmAgent --> graphrag_agent\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: graphrag_agent\n", - "\u001b[0m\n", - "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", - "\n", - "Restaurants in Rome:\n", - "1. Trattoria da Enzo - Known for its traditional Roman dishes and welcoming atmosphere with a rating of 4.5.\n", - "2. Il Pagliaccio - An elegant Michelin-starred restaurant offering contemporary Italian cuisine with a rating of 4.8.\n", - "3. Tonnarello - Casual stop for pasta and other simple Roman dishes with a rating of 4.7.\n", - "4. Osteria delle Commari - Local home-style Roman restaurant near Vatican Museums with a rating of 4.3.\n", - "5. Armando al Pantheon - Traditional Roman cuisine near the Pantheon with a rating of 4.8.\n", - "6. Salumeria Roscioli Ristorante - Known for Pasta alla gricia and an impressive wine cellar with a rating of 4.5.\n", - "7. L'Arcangelo - Supplì are considered among the best in the city with a rating of 4.8.\n", - "\n", - "Attractions in Rome:\n", - "1. Colosseum - An ancient amphitheater known for gladiatorial contests.\n", - "2. Vatican Museums - A complex of museums and galleries showcasing art collected by Popes.\n", - "3. Trevi Fountain - A Baroque fountain famous for its stunning sculptures.\n", - "4. Basilica di Santa Maria Maggiore - A major basilica known for its history and architecture.\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "Thank you for your patience! Here’s a preliminary itinerary for your 2-day trip to Rome:\n", - "\n", - "### Day 1:\n", - "- **Morning Attraction:** \n", - " - **Type:** Attraction \n", - " - **Location:** Colosseum \n", - " - **City:** Rome \n", - " - **Description:** An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history. \n", - "\n", - "- **Lunch:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Trattoria da Enzo \n", - " - **City:** Rome \n", - " - **Description:** Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\n", - "\n", - "- **Afternoon Attraction:** \n", - " - **Type:** Attraction \n", - " - **Location:** Trevi Fountain \n", - " - **City:** Rome \n", - " - **Description:** A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\n", - "\n", - "- **Dinner:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Armando al Pantheon \n", - " - **City:** Rome \n", - " - **Description:** Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\n", - "\n", - "---\n", - "\n", - "### Day 2:\n", - "- **Morning Attraction:** \n", - " - **Type:** Attraction \n", - " - **Location:** Vatican Museums \n", - " - **City:** Rome \n", - " - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\n", - "\n", - "- **Lunch:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Osteria delle Commari \n", - " - **City:** Rome \n", - " - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\n", - "\n", - "- **Afternoon Attraction:** \n", - " - **Type:** Attraction \n", - " - **Location:** Basilica di Santa Maria Maggiore \n", - " - **City:** Rome \n", - " - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\n", - "\n", - "- **Dinner:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Il Pagliaccio \n", - " - **City:** Rome \n", - " - **Description:** An elegant Michelin-starred restaurant offering contemporary Italian cuisine for a special dining experience.\n", - "\n", - "---\n", - "\n", - "Does this itinerary look good to you, or would you like to make any changes?\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: customer\n", - "\u001b[0m\n", - "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", - "\n", - "Change out Il Pagliaccio please\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Suggested tool call (call_kK43xij89ce8xnIyFP4S33zn): transfer_to_graphrag_agent *****\u001b[0m\n", - "Arguments: \n", - "{}\n", - "\u001b[32m*******************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION transfer_to_graphrag_agent...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_kK43xij89ce8xnIyFP4S33zn) *****\u001b[0m\n", - "SwarmAgent --> graphrag_agent\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: graphrag_agent\n", - "\u001b[0m\n", - "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", - "\n", - "Restaurants in Rome:\n", - "1. Trattoria da Enzo - Known for its traditional Roman dishes and welcoming atmosphere with a rating of 4.5.\n", - "2. Tonnarello - Casual stop for pasta and other simple Roman dishes with a rating of 4.7.\n", - "3. Osteria delle Commari - Local home-style Roman restaurant near Vatican Museums with a rating of 4.3.\n", - "4. Armando al Pantheon - Traditional Roman cuisine near the Pantheon with a rating of 4.8.\n", - "5. Salumeria Roscioli Ristorante - Known for Pasta alla gricia and an impressive wine cellar with a rating of 4.5.\n", - "6. L'Arcangelo - Supplì are considered among the best in the city with a rating of 4.8.\n", - "\n", - "Attractions in Rome:\n", - "1. Colosseum - An ancient amphitheater known for gladiatorial contests.\n", - "2. Vatican Museums - A complex of museums and galleries showcasing art collected by Popes.\n", - "3. Trevi Fountain - A Baroque fountain famous for its stunning sculptures.\n", - "4. Basilica di Santa Maria Maggiore - A major basilica known for its history and architecture.\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "Thank you for your response! Since you want to change out Il Pagliaccio, here’s an updated itinerary for your second evening in Rome:\n", - "\n", - "---\n", - "\n", - "### Day 2:\n", - "- **Morning Attraction:** \n", - " - **Type:** Attraction \n", - " - **Location:** Vatican Museums \n", - " - **City:** Rome \n", - " - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\n", - "\n", - "- **Lunch:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Osteria delle Commari \n", - " - **City:** Rome \n", - " - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\n", - "\n", - "- **Afternoon Attraction:** \n", - " - **Type:** Attraction \n", - " - **Location:** Basilica di Santa Maria Maggiore \n", - " - **City:** Rome \n", - " - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\n", - "\n", - "- **Dinner:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Tonnarello \n", - " - **City:** Rome \n", - " - **Description:** A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\n", - "\n", - "---\n", - "\n", - "Please review this updated itinerary. Are you happy with it, or would you like to make any other changes?\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: customer\n", - "\u001b[0m\n", - "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", - "\n", - "Perfect, let's go!\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Suggested tool call (call_AQmHaXoGospsVPDE0hMiHcKm): mark_itinerary_as_complete *****\u001b[0m\n", - "Arguments: \n", - "{\"final_itinerary\":\"### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history. \\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\\n\\n---\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}\n", - "\u001b[32m*******************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION mark_itinerary_as_complete...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_AQmHaXoGospsVPDE0hMiHcKm) *****\u001b[0m\n", - "Itinerary recorded and confirmed.\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: structured_output_agent\n", - "\u001b[0m\n", - "\u001b[33mstructured_output_agent\u001b[0m (to chat_manager):\n", - "\n", - "{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}]}]}\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: route_timing_agent\n", - "\u001b[0m\n", - "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Suggested tool call (call_YbfQMAB7sauRv0038iGdBYCG): update_itinerary_with_travel_times *****\u001b[0m\n", - "Arguments: \n", - "{}\n", - "\u001b[32m***************************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION update_itinerary_with_travel_times...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_YbfQMAB7sauRv0038iGdBYCG) *****\u001b[0m\n", - "Structured itinerary not found, please create the structured output, structured_output_agent.\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: structured_output_agent\n", - "\u001b[0m\n", - "\u001b[33mstructured_output_agent\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Suggested tool call (call_ZXP5Ibumjwi4fQ3i2BxmIwmf): create_structured_itinerary *****\u001b[0m\n", - "Arguments: \n", - "{\"structured_itinerary\":{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}]}]}}\n", - "\u001b[32m********************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION create_structured_itinerary...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_ZXP5Ibumjwi4fQ3i2BxmIwmf) *****\u001b[0m\n", - "Structured itinerary stored.\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: route_timing_agent\n", - "\u001b[0m\n", - "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Suggested tool call (call_JWlxdrbVQMuItq9NAMMmT2DC): update_itinerary_with_travel_times *****\u001b[0m\n", - "Arguments: \n", - "{}\n", - "\u001b[32m***************************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION update_itinerary_with_travel_times...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_JWlxdrbVQMuItq9NAMMmT2DC) *****\u001b[0m\n", - "Timed itinerary added to context with travel times\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: route_timing_agent\n", - "\u001b[0m\n", - "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", - "\n", - "Your itinerary is ready! Enjoy your trip to Rome!\n", - "\n", - "--------------------------------------------------------------------------------\n" - ] - } - ], + "outputs": [], "source": [ - "# 6. Start the conversation\n", + "# Start the conversation\n", "\n", "chat_result, context_variables, last_agent = initiate_swarm_chat(\n", " initial_agent=planner_agent,\n", @@ -1071,63 +693,6 @@ ")" ] }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Context: {'itinerary_confirmed': True, 'itinerary': \"### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history. \\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\\n\\n---\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\", 'structured_itinerary': {'days': [{'events': [{'type': 'Attraction', 'location': 'Colosseum', 'city': 'Rome', 'description': \"An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history.\"}, {'type': 'Restaurant', 'location': 'Trattoria da Enzo', 'city': 'Rome', 'description': 'Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.'}, {'type': 'Attraction', 'location': 'Trevi Fountain', 'city': 'Rome', 'description': 'A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.'}, {'type': 'Restaurant', 'location': 'Armando al Pantheon', 'city': 'Rome', 'description': 'Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.'}]}, {'events': [{'type': 'Attraction', 'location': 'Vatican Museums', 'city': 'Rome', 'description': 'A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.'}, {'type': 'Restaurant', 'location': 'Osteria delle Commari', 'city': 'Rome', 'description': 'A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.'}, {'type': 'Attraction', 'location': 'Basilica di Santa Maria Maggiore', 'city': 'Rome', 'description': 'A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.'}, {'type': 'Restaurant', 'location': 'Tonnarello', 'city': 'Rome', 'description': 'A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.'}]}]}, 'timed_itinerary': {'days': [{'events': [{'type': 'Attraction', 'location': 'Colosseum', 'city': 'Rome', 'description': \"An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history.\"}, {'type': 'Travel', 'location': 'walking from Colosseum to Trattoria da Enzo', 'city': 'Rome', 'description': '24 mins, (1.8 km)'}, {'type': 'Restaurant', 'location': 'Trattoria da Enzo', 'city': 'Rome', 'description': 'Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.'}, {'type': 'Travel', 'location': 'walking from Trattoria da Enzo to Trevi Fountain', 'city': 'Rome', 'description': '28 mins, (2.0 km)'}, {'type': 'Attraction', 'location': 'Trevi Fountain', 'city': 'Rome', 'description': 'A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.'}, {'type': 'Travel', 'location': 'walking from Trevi Fountain to Armando al Pantheon', 'city': 'Rome', 'description': '9 mins, (0.7 km)'}, {'type': 'Restaurant', 'location': 'Armando al Pantheon', 'city': 'Rome', 'description': 'Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.'}]}, {'events': [{'type': 'Attraction', 'location': 'Vatican Museums', 'city': 'Rome', 'description': 'A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.'}, {'type': 'Travel', 'location': 'walking from Vatican Museums to Osteria delle Commari', 'city': 'Rome', 'description': '2 mins, (0.2 km)'}, {'type': 'Restaurant', 'location': 'Osteria delle Commari', 'city': 'Rome', 'description': 'A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.'}, {'type': 'Travel', 'location': 'walking from Osteria delle Commari to Basilica di Santa Maria Maggiore', 'city': 'Rome', 'description': '1 hour 5 mins, (4.6 km)'}, {'type': 'Attraction', 'location': 'Basilica di Santa Maria Maggiore', 'city': 'Rome', 'description': 'A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.'}, {'type': 'Travel', 'location': 'walking from Basilica di Santa Maria Maggiore to Tonnarello', 'city': 'Rome', 'description': '44 mins, (3.2 km)'}, {'type': 'Restaurant', 'location': 'Tonnarello', 'city': 'Rome', 'description': 'A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.'}]}]}}\n" - ] - } - ], - "source": [ - "print(f\"Context: {context_variables}\")" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'content': 'I want to go to Rome for a couple of days. Can you help me plan my trip?', 'role': 'assistant', 'name': 'customer'}\n", - "{'content': \"Of course! I'd love to help you plan your trip to Rome. \\n\\nTo get started, could you please provide me with the following information:\\n1. How many days will you be staying in Rome?\\n2. What activities or attractions are you interested in? (e.g., historical sites, museums, shopping, dining, etc.)\\n3. Do you have any specific preferences for meals or restaurants? \\n\\nOnce I have this information, I can start creating an itinerary for you!\", 'name': 'planner_agent', 'role': 'user'}\n", - "{'content': '2 days please, I want lunch and dinner, with an attraction to see in the morning and after lunch.', 'role': 'assistant', 'name': 'customer'}\n", - "{'content': 'None', 'tool_calls': [{'id': 'call_2dmMbckU5YjaCsL6Y8pWbrdK', 'function': {'arguments': '{}', 'name': 'transfer_to_graphrag_agent'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", - "{'content': 'SwarmAgent --> graphrag_agent', 'tool_responses': [{'tool_call_id': 'call_2dmMbckU5YjaCsL6Y8pWbrdK', 'role': 'tool', 'content': 'SwarmAgent --> graphrag_agent'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", - "{'content': \"Restaurants in Rome:\\n1. Trattoria da Enzo - Known for its traditional Roman dishes and welcoming atmosphere with a rating of 4.5.\\n2. Il Pagliaccio - An elegant Michelin-starred restaurant offering contemporary Italian cuisine with a rating of 4.8.\\n3. Tonnarello - Casual stop for pasta and other simple Roman dishes with a rating of 4.7.\\n4. Osteria delle Commari - Local home-style Roman restaurant near Vatican Museums with a rating of 4.3.\\n5. Armando al Pantheon - Traditional Roman cuisine near the Pantheon with a rating of 4.8.\\n6. Salumeria Roscioli Ristorante - Known for Pasta alla gricia and an impressive wine cellar with a rating of 4.5.\\n7. L'Arcangelo - Supplì are considered among the best in the city with a rating of 4.8.\\n\\nAttractions in Rome:\\n1. Colosseum - An ancient amphitheater known for gladiatorial contests.\\n2. Vatican Museums - A complex of museums and galleries showcasing art collected by Popes.\\n3. Trevi Fountain - A Baroque fountain famous for its stunning sculptures.\\n4. Basilica di Santa Maria Maggiore - A major basilica known for its history and architecture.\", 'name': 'graphrag_agent', 'role': 'user'}\n", - "{'content': \"Thank you for your patience! Here’s a preliminary itinerary for your 2-day trip to Rome:\\n\\n### Day 1:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** An ancient amphitheater known for gladiatorial contests and a symbol of the city's rich history. \\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\\n\\n---\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Il Pagliaccio \\n - **City:** Rome \\n - **Description:** An elegant Michelin-starred restaurant offering contemporary Italian cuisine for a special dining experience.\\n\\n---\\n\\nDoes this itinerary look good to you, or would you like to make any changes?\", 'name': 'planner_agent', 'role': 'user'}\n", - "{'content': 'Change out Il Pagliaccio please', 'role': 'assistant', 'name': 'customer'}\n", - "{'content': 'None', 'tool_calls': [{'id': 'call_kK43xij89ce8xnIyFP4S33zn', 'function': {'arguments': '{}', 'name': 'transfer_to_graphrag_agent'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", - "{'content': 'SwarmAgent --> graphrag_agent', 'tool_responses': [{'tool_call_id': 'call_kK43xij89ce8xnIyFP4S33zn', 'role': 'tool', 'content': 'SwarmAgent --> graphrag_agent'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", - "{'content': \"Restaurants in Rome:\\n1. Trattoria da Enzo - Known for its traditional Roman dishes and welcoming atmosphere with a rating of 4.5.\\n2. Tonnarello - Casual stop for pasta and other simple Roman dishes with a rating of 4.7.\\n3. Osteria delle Commari - Local home-style Roman restaurant near Vatican Museums with a rating of 4.3.\\n4. Armando al Pantheon - Traditional Roman cuisine near the Pantheon with a rating of 4.8.\\n5. Salumeria Roscioli Ristorante - Known for Pasta alla gricia and an impressive wine cellar with a rating of 4.5.\\n6. L'Arcangelo - Supplì are considered among the best in the city with a rating of 4.8.\\n\\nAttractions in Rome:\\n1. Colosseum - An ancient amphitheater known for gladiatorial contests.\\n2. Vatican Museums - A complex of museums and galleries showcasing art collected by Popes.\\n3. Trevi Fountain - A Baroque fountain famous for its stunning sculptures.\\n4. Basilica di Santa Maria Maggiore - A major basilica known for its history and architecture.\", 'name': 'graphrag_agent', 'role': 'user'}\n", - "{'content': 'Thank you for your response! Since you want to change out Il Pagliaccio, here’s an updated itinerary for your second evening in Rome:\\n\\n---\\n\\n### Day 2:\\n- **Morning Attraction:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\\n\\n- **Afternoon Attraction:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\\n\\n---\\n\\nPlease review this updated itinerary. Are you happy with it, or would you like to make any other changes?', 'name': 'planner_agent', 'role': 'user'}\n", - "{'content': \"Perfect, let's go!\", 'role': 'assistant', 'name': 'customer'}\n", - "{'content': 'None', 'tool_calls': [{'id': 'call_AQmHaXoGospsVPDE0hMiHcKm', 'function': {'arguments': '{\"final_itinerary\":\"### Day 1:\\\\n- **Morning Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Colosseum \\\\n - **City:** Rome \\\\n - **Description:** An ancient amphitheater known for gladiatorial contests and a symbol of the city\\'s rich history. \\\\n\\\\n- **Lunch:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Trattoria da Enzo \\\\n - **City:** Rome \\\\n - **Description:** Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\\\\n\\\\n- **Afternoon Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Trevi Fountain \\\\n - **City:** Rome \\\\n - **Description:** A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\\\\n\\\\n- **Dinner:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Armando al Pantheon \\\\n - **City:** Rome \\\\n - **Description:** Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\\\\n\\\\n---\\\\n\\\\n### Day 2:\\\\n- **Morning Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Vatican Museums \\\\n - **City:** Rome \\\\n - **Description:** A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\\\\n\\\\n- **Lunch:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Osteria delle Commari \\\\n - **City:** Rome \\\\n - **Description:** A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\\\\n\\\\n- **Afternoon Attraction:** \\\\n - **Type:** Attraction \\\\n - **Location:** Basilica di Santa Maria Maggiore \\\\n - **City:** Rome \\\\n - **Description:** A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\\\\n\\\\n- **Dinner:** \\\\n - **Type:** Restaurant \\\\n - **Location:** Tonnarello \\\\n - **City:** Rome \\\\n - **Description:** A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}', 'name': 'mark_itinerary_as_complete'}, 'type': 'function'}], 'name': 'planner_agent', 'role': 'assistant'}\n", - "{'content': 'Itinerary recorded and confirmed.', 'tool_responses': [{'tool_call_id': 'call_AQmHaXoGospsVPDE0hMiHcKm', 'role': 'tool', 'content': 'Itinerary recorded and confirmed.'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", - "{'content': '{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and a symbol of the city\\'s rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}]}]}', 'name': 'structured_output_agent', 'role': 'user'}\n", - "{'content': 'None', 'tool_calls': [{'id': 'call_YbfQMAB7sauRv0038iGdBYCG', 'function': {'arguments': '{}', 'name': 'update_itinerary_with_travel_times'}, 'type': 'function'}], 'name': 'route_timing_agent', 'role': 'assistant'}\n", - "{'content': 'Structured itinerary not found, please create the structured output, structured_output_agent.', 'tool_responses': [{'tool_call_id': 'call_YbfQMAB7sauRv0038iGdBYCG', 'role': 'tool', 'content': 'Structured itinerary not found, please create the structured output, structured_output_agent.'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", - "{'content': 'None', 'tool_calls': [{'id': 'call_ZXP5Ibumjwi4fQ3i2BxmIwmf', 'function': {'arguments': '{\"structured_itinerary\":{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"An ancient amphitheater known for gladiatorial contests and a symbol of the city\\'s rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Known for its traditional Roman dishes and a welcoming atmosphere, perfect for a hearty lunch.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"A Baroque fountain famous for its stunning sculptures and a popular spot for tourists to toss in a coin for good luck.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Serves traditional Roman cuisine near the Pantheon, offering an authentic dining experience.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"A complex of museums and galleries showcasing art collected by Popes, including the Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"A local home-style Roman restaurant near the Vatican Museums for a delightful lunch.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"A major basilica known for its rich history and impressive architecture, a serene spot to visit after lunch.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"A casual stop for pasta and other simple Roman dishes, perfect for a relaxed dinner to cap off your trip.\"}]}]}}', 'name': 'create_structured_itinerary'}, 'type': 'function'}], 'name': 'structured_output_agent', 'role': 'assistant'}\n", - "{'content': 'Structured itinerary stored.', 'tool_responses': [{'tool_call_id': 'call_ZXP5Ibumjwi4fQ3i2BxmIwmf', 'role': 'tool', 'content': 'Structured itinerary stored.'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", - "{'content': 'None', 'tool_calls': [{'id': 'call_JWlxdrbVQMuItq9NAMMmT2DC', 'function': {'arguments': '{}', 'name': 'update_itinerary_with_travel_times'}, 'type': 'function'}], 'name': 'route_timing_agent', 'role': 'assistant'}\n", - "{'content': 'Timed itinerary added to context with travel times', 'tool_responses': [{'tool_call_id': 'call_JWlxdrbVQMuItq9NAMMmT2DC', 'role': 'tool', 'content': 'Timed itinerary added to context with travel times'}], 'name': 'Tool_Execution', 'role': 'tool'}\n", - "{'content': 'Your itinerary is ready! Enjoy your trip to Rome!', 'name': 'route_timing_agent', 'role': 'user'}\n" - ] - } - ], - "source": [ - "for message in chat_result.chat_history:\n", - " print(message)" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -1137,93 +702,9 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " █ █ \n", - " █ █ \n", - " █ █████ █ \n", - " ██ ██ \n", - " █ █ \n", - " █ ███████ █ \n", - " █ ██ ███ ██ █ \n", - " █████████ \n", - " \n", - " ██ ███ ███ \n", - " █ █ █ █ \n", - " ████ █ ██ ██ \n", - " █ █ █ █ █ \n", - " █ █ ██ ████ \n", - " \n", - " Itinerary for Rome \n", - "================================================================================\n", - " \n", - "Day 1 \n", - "--------------------------------------------------------------------------------\n", - "\n", - " 🏛️ Colosseum\n", - " An ancient amphitheater known for gladiatorial contests and a symbol of \n", - " the city's rich history. \n", - "\n", - " 🚶 walking from Colosseum to Trattoria da Enzo\n", - " 24 mins, (1.8 km)\n", - "\n", - " 🍽️ Trattoria da Enzo\n", - " Known for its traditional Roman dishes and a welcoming atmosphere, \n", - " perfect for a hearty lunch. \n", - "\n", - " 🚶 walking from Trattoria da Enzo to Trevi Fountain\n", - " 28 mins, (2.0 km)\n", - "\n", - " 🏛️ Trevi Fountain\n", - " A Baroque fountain famous for its stunning sculptures and a popular \n", - " spot for tourists to toss in a coin for good luck. \n", - "\n", - " 🚶 walking from Trevi Fountain to Armando al Pantheon\n", - " 9 mins, (0.7 km)\n", - "\n", - " 🍽️ Armando al Pantheon\n", - " Serves traditional Roman cuisine near the Pantheon, offering an \n", - " authentic dining experience. \n", - "\n", - "--------------------------------------------------------------------------------\n", - " \n", - "Day 2 \n", - "--------------------------------------------------------------------------------\n", - "\n", - " 🏛️ Vatican Museums\n", - " A complex of museums and galleries showcasing art collected by Popes, \n", - " including the Sistine Chapel. \n", - "\n", - " 🚶 walking from Vatican Museums to Osteria delle Commari\n", - " 2 mins, (0.2 km)\n", - "\n", - " 🍽️ Osteria delle Commari\n", - " A local home-style Roman restaurant near the Vatican Museums for a \n", - " delightful lunch. \n", - "\n", - " 🚶 walking from Osteria delle Commari to Basilica di Santa Maria Maggiore\n", - " 1 hour 5 mins, (4.6 km)\n", - "\n", - " 🏛️ Basilica di Santa Maria Maggiore\n", - " A major basilica known for its rich history and impressive \n", - " architecture, a serene spot to visit after lunch. \n", - "\n", - " 🚶 walking from Basilica di Santa Maria Maggiore to Tonnarello\n", - " 44 mins, (3.2 km)\n", - "\n", - " 🍽️ Tonnarello\n", - " A casual stop for pasta and other simple Roman dishes, perfect for a \n", - " relaxed dinner to cap off your trip. \n", - "\n", - "--------------------------------------------------------------------------------\n" - ] - } - ], + "outputs": [], "source": [ "def print_itinerary(itinerary_data):\n", " header = \"█ █\\n █ █ \\n █ █████ █ \\n ██ ██ \\n █ █ \\n █ ███████ █ \\n █ ██ ███ ██ █ \\n █████████ \\n\\n ██ ███ ███ \\n█ █ █ █ \\n████ █ ██ ██ \\n█ █ █ █ █ \\n█ █ ██ ████ \\n\"\n", From 83650b345b937baa1fc01f3c29695d510a303b25 Mon Sep 17 00:00:00 2001 From: AgentGenie Date: Wed, 4 Dec 2024 17:35:43 -0800 Subject: [PATCH 14/20] Add TODO for FalkorDB LLM API cost calculation --- .../agentchat/contrib/graph_rag/falkor_graph_query_engine.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py index 58e6fcb889..ef984279d9 100644 --- a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +++ b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py @@ -36,6 +36,8 @@ def __init__( Initialize a FalkorDB knowledge graph. Please also refer to https://github.com/FalkorDB/GraphRAG-SDK/blob/main/graphrag_sdk/kg.py + TODO: Fix LLM API cost calculation for FalkorDB useages. + Args: name (str): Knowledge graph name. host (str): FalkorDB hostname. From 6e85696f0eaf54b2c3d47ad7671885ec65e77fea Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Thu, 5 Dec 2024 02:03:45 +0000 Subject: [PATCH 15/20] Notebook with execution Signed-off-by: Mark Sze --- ...gentchat_swarm_graphrag_trip_planner.ipynb | 463 +++++++++++++++++- 1 file changed, 446 insertions(+), 17 deletions(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 40a52018c9..5364d640ba 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -83,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -91,7 +91,7 @@ "\n", "import autogen\n", "\n", - "config_list = autogen.config_list_from_json(env_or_file=\"../OAI_CONFIG_LIST\", filter_dict={\"model\": [\"gpt-4o-mini\"]})\n", + "config_list = autogen.config_list_from_json(env_or_file=\"OAI_CONFIG_LIST\", filter_dict={\"model\": [\"gpt-4o-mini\"]})\n", "llm_config = {\"config_list\": config_list, \"timeout\": 120}\n", "\n", "# Put the OpenAI API key into the environment\n", @@ -111,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -139,7 +139,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -341,15 +341,15 @@ ")\n", "\n", "# Ingest data and initialize the database\n", - "# query_engine.init_db(input_doc=input_documents)\n", + "query_engine.init_db(input_doc=input_documents)\n", "\n", "# If you have already ingested and created the database, you can use this connect_db instead of init_db\n", - "query_engine.connect_db()" + "# query_engine.connect_db()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -385,7 +385,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -415,7 +415,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -505,7 +505,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -531,7 +531,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -575,7 +575,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -636,7 +636,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -676,9 +676,355 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "I want to go to Rome for a couple of days. Can you help me plan my trip?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "Of course! I'd love to help you plan your trip to Rome. \n", + "\n", + "To get started, could you please provide me with the following information:\n", + "1. How many days will you be staying in Rome?\n", + "2. What activities or attractions are you interested in? (e.g., historical sites, museums, shopping, dining, etc.)\n", + "3. Do you have any specific preferences for meals or restaurants? \n", + "\n", + "Once I have this information, I can start creating an itinerary for you!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "2 days please, I want lunch and dinner, with an attraction to see in the morning and after lunch.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_2dmMbckU5YjaCsL6Y8pWbrdK): transfer_to_graphrag_agent *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m*******************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION transfer_to_graphrag_agent...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_2dmMbckU5YjaCsL6Y8pWbrdK) *****\u001b[0m\n", + "SwarmAgent --> graphrag_agent\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: graphrag_agent\n", + "\u001b[0m\n", + "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", + "\n", + "Restaurants in Rome:\n", + "1. Trattoria da Enzo - Italian, traditional Roman dishes, rating: 4.5\n", + "2. Il Pagliaccio - Italian, Michelin-starred, rating: 4.8\n", + "3. Tonnarello - Italian, traditional dishes, rating: 4.7\n", + "4. Osteria delle Commari - Italian, home-style Roman cuisine, rating: 4.3\n", + "5. Armando al Pantheon - Italian, traditional Roman cuisine, rating: 4.8\n", + "6. Salumeria Roscioli Ristorante - Italian, pasta and wine cellar, rating: 4.5\n", + "7. L'Arcangelo - Italian, known for supplì and gnocchi, rating: 4.8\n", + "\n", + "Attractions in Rome:\n", + "1. Colosseum - Historical site\n", + "2. Vatican Museums - Art museum\n", + "3. Trevi Fountain - Landmark\n", + "4. Basilica di Santa Maria Maggiore - Religious site\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "Great! Here’s a proposed 2-day itinerary for your trip to Rome:\n", + "\n", + "### Day 1:\n", + "- **Morning:**\n", + " - **Type:** Attraction \n", + " - **Location:** Colosseum \n", + " - **City:** Rome \n", + " - **Description:** Explore the iconic symbol of Rome, a magnificent ancient amphitheater where gladiators once battled.\n", + "\n", + "- **Lunch:**\n", + " - **Type:** Restaurant \n", + " - **Location:** Trattoria da Enzo \n", + " - **City:** Rome \n", + " - **Description:** Enjoy traditional Roman dishes in a charming setting with great ratings.\n", + "\n", + "- **Afternoon:**\n", + " - **Type:** Attraction \n", + " - **Location:** Trevi Fountain \n", + " - **City:** Rome \n", + " - **Description:** Visit the stunning baroque fountain and toss a coin to ensure your return to Rome.\n", + "\n", + "- **Dinner:**\n", + " - **Type:** Restaurant \n", + " - **Location:** Armando al Pantheon \n", + " - **City:** Rome \n", + " - **Description:** Savor authentic Roman cuisine in a restaurant that boasts a great atmosphere and top-notch dishes.\n", + "\n", + "### Day 2:\n", + "- **Morning:**\n", + " - **Type:** Attraction \n", + " - **Location:** Vatican Museums \n", + " - **City:** Rome \n", + " - **Description:** Discover a vast collection of art and historical artifacts, including the famous Sistine Chapel.\n", + "\n", + "- **Lunch:**\n", + " - **Type:** Restaurant \n", + " - **Location:** Osteria delle Commari \n", + " - **City:** Rome \n", + " - **Description:** Enjoy home-style Roman cuisine in a cozy, welcoming environment.\n", + "\n", + "- **Afternoon:**\n", + " - **Type:** Attraction \n", + " - **Location:** Basilica di Santa Maria Maggiore \n", + " - **City:** Rome \n", + " - **Description:** Explore one of the largest churches in Rome, known for its beautiful mosaics and rich history.\n", + "\n", + "- **Dinner:**\n", + " - **Type:** Restaurant \n", + " - **Location:** Il Pagliaccio \n", + " - **City:** Rome \n", + " - **Description:** Experience a Michelin-starred dining option with a unique menu and exquisite taste.\n", + "\n", + "Does this itinerary look good to you? Let me know if you would like any changes or adjustments!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "I'm not a fan of Il Pagliaccio, please select another restaurant.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_7aUs54WvG0A31PNTJnNyKUWE): transfer_to_graphrag_agent *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m*******************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION transfer_to_graphrag_agent...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_7aUs54WvG0A31PNTJnNyKUWE) *****\u001b[0m\n", + "SwarmAgent --> graphrag_agent\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: graphrag_agent\n", + "\u001b[0m\n", + "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", + "\n", + "Restaurants in Rome:\n", + "1. Trattoria da Enzo - Italian, traditional Roman dishes, rating: 4.5\n", + "2. Il Pagliaccio - Italian, Michelin-starred, rating: 4.8\n", + "3. Tonnarello - Italian, traditional dishes, rating: 4.7\n", + "4. Osteria delle Commari - Italian, home-style Roman cuisine, rating: 4.3\n", + "5. Armando al Pantheon - Italian, traditional Roman cuisine, rating: 4.8\n", + "6. Salumeria Roscioli Ristorante - Italian, pasta and wine cellar, rating: 4.5\n", + "7. L'Arcangelo - Italian, known for supplì and gnocchi, rating: 4.8\n", + "\n", + "Attractions in Rome:\n", + "1. Colosseum - Historical site\n", + "2. Vatican Museums - Art museum\n", + "3. Trevi Fountain - Landmark\n", + "4. Basilica di Santa Maria Maggiore - Religious site\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "No problem! Let's replace Il Pagliaccio with another restaurant.\n", + "\n", + "### Updated Day 2 Itinerary:\n", + "- **Dinner:**\n", + " - **Type:** Restaurant \n", + " - **Location:** Tonnarello \n", + " - **City:** Rome \n", + " - **Description:** Enjoy traditional Italian dishes in a vibrant atmosphere, known for its great flavors and local feel.\n", + "\n", + "Here's the complete itinerary:\n", + "\n", + "### Day 1:\n", + "- **Morning:** \n", + " - **Type:** Attraction \n", + " - **Location:** Colosseum \n", + " - **City:** Rome \n", + " - **Description:** Explore the iconic symbol of Rome, a magnificent ancient amphitheater where gladiators once battled.\n", + "\n", + "- **Lunch:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Trattoria da Enzo \n", + " - **City:** Rome \n", + " - **Description:** Enjoy traditional Roman dishes in a charming setting with great ratings.\n", + "\n", + "- **Afternoon:** \n", + " - **Type:** Attraction \n", + " - **Location:** Trevi Fountain \n", + " - **City:** Rome \n", + " - **Description:** Visit the stunning baroque fountain and toss a coin to ensure your return to Rome.\n", + "\n", + "- **Dinner:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Armando al Pantheon \n", + " - **City:** Rome \n", + " - **Description:** Savor authentic Roman cuisine in a restaurant that boasts a great atmosphere and top-notch dishes.\n", + "\n", + "### Day 2:\n", + "- **Morning:** \n", + " - **Type:** Attraction \n", + " - **Location:** Vatican Museums \n", + " - **City:** Rome \n", + " - **Description:** Discover a vast collection of art and historical artifacts, including the famous Sistine Chapel.\n", + "\n", + "- **Lunch:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Osteria delle Commari \n", + " - **City:** Rome \n", + " - **Description:** Enjoy home-style Roman cuisine in a cozy, welcoming environment.\n", + "\n", + "- **Afternoon:** \n", + " - **Type:** Attraction \n", + " - **Location:** Basilica di Santa Maria Maggiore \n", + " - **City:** Rome \n", + " - **Description:** Explore one of the largest churches in Rome, known for its beautiful mosaics and rich history.\n", + "\n", + "- **Dinner:** \n", + " - **Type:** Restaurant \n", + " - **Location:** Tonnarello \n", + " - **City:** Rome \n", + " - **Description:** Enjoy traditional Italian dishes in a vibrant atmosphere, known for its great flavors and local feel.\n", + "\n", + "Are you happy with this updated itinerary? Let me know if you want any more changes!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "Great, thank you, let's go!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_RibOtG2YA85QXVBaUzoSS2El): mark_itinerary_as_complete *****\u001b[0m\n", + "Arguments: \n", + "{\"final_itinerary\":\"### Day 1:\\n- **Morning:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** Explore the iconic symbol of Rome, a magnificent ancient amphitheater where gladiators once battled.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** Enjoy traditional Roman dishes in a charming setting with great ratings.\\n\\n- **Afternoon:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** Visit the stunning baroque fountain and toss a coin to ensure your return to Rome.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Savor authentic Roman cuisine in a restaurant that boasts a great atmosphere and top-notch dishes.\\n\\n### Day 2:\\n- **Morning:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** Discover a vast collection of art and historical artifacts, including the famous Sistine Chapel.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** Enjoy home-style Roman cuisine in a cozy, welcoming environment.\\n\\n- **Afternoon:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** Explore one of the largest churches in Rome, known for its beautiful mosaics and rich history.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** Enjoy traditional Italian dishes in a vibrant atmosphere, known for its great flavors and local feel.\"}\n", + "\u001b[32m*******************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION mark_itinerary_as_complete...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_RibOtG2YA85QXVBaUzoSS2El) *****\u001b[0m\n", + "Itinerary recorded and confirmed.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: structured_output_agent\n", + "\u001b[0m\n", + "\u001b[33mstructured_output_agent\u001b[0m (to chat_manager):\n", + "\n", + "{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"Explore the iconic symbol of Rome, a magnificent ancient amphitheater where gladiators once battled.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Roman dishes in a charming setting with great ratings.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"Visit the stunning baroque fountain and toss a coin to ensure your return to Rome.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Savor authentic Roman cuisine in a restaurant that boasts a great atmosphere and top-notch dishes.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"Discover a vast collection of art and historical artifacts, including the famous Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"Enjoy home-style Roman cuisine in a cozy, welcoming environment.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"Explore one of the largest churches in Rome, known for its beautiful mosaics and rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Italian dishes in a vibrant atmosphere, known for its great flavors and local feel.\"}]}]}\n", + "\u001b[32m***** Suggested tool call (call_ZZuv1U9iUcZZaDsa7hOGtaFY): create_structured_itinerary *****\u001b[0m\n", + "Arguments: \n", + "{\"structured_itinerary\":{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"Explore the iconic symbol of Rome, a magnificent ancient amphitheater where gladiators once battled.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Roman dishes in a charming setting with great ratings.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"Visit the stunning baroque fountain and toss a coin to ensure your return to Rome.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Savor authentic Roman cuisine in a restaurant that boasts a great atmosphere and top-notch dishes.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"Discover a vast collection of art and historical artifacts, including the famous Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"Enjoy home-style Roman cuisine in a cozy, welcoming environment.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"Explore one of the largest churches in Rome, known for its beautiful mosaics and rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Italian dishes in a vibrant atmosphere, known for its great flavors and local feel.\"}]}]}}\n", + "\u001b[32m********************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION create_structured_itinerary...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_ZZuv1U9iUcZZaDsa7hOGtaFY) *****\u001b[0m\n", + "Structured itinerary stored.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: route_timing_agent\n", + "\u001b[0m\n", + "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_H8U9HTdJTnY8kxU2QFiq1aCn): update_itinerary_with_travel_times *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m***************************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION update_itinerary_with_travel_times...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_H8U9HTdJTnY8kxU2QFiq1aCn) *****\u001b[0m\n", + "Timed itinerary added to context with travel times\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: route_timing_agent\n", + "\u001b[0m\n", + "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", + "\n", + "Your itinerary is ready! Enjoy your trip to Rome, exploring the Colosseum, Vatican Museums, and delicious dining experiences at the recommended restaurants. If you have any further questions or need assistance while you're there, feel free to reach out! Safe travels!\n", + "\n", + "--------------------------------------------------------------------------------\n" + ] + } + ], "source": [ "# Start the conversation\n", "\n", @@ -702,9 +1048,92 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " █ █ \n", + " █ █ \n", + " █ █████ █ \n", + " ██ ██ \n", + " █ █ \n", + " █ ███████ █ \n", + " █ ██ ███ ██ █ \n", + " █████████ \n", + " \n", + " ██ ███ ███ \n", + " █ █ █ █ \n", + " ████ █ ██ ██ \n", + " █ █ █ █ █ \n", + " █ █ ██ ████ \n", + " \n", + " Itinerary for Rome \n", + "================================================================================\n", + " \n", + "Day 1 \n", + "--------------------------------------------------------------------------------\n", + "\n", + " 🏛️ Colosseum\n", + " Explore the iconic symbol of Rome, a magnificent ancient amphitheater \n", + " where gladiators once battled. \n", + "\n", + " 🚶 walking from Colosseum to Trattoria da Enzo\n", + " 24 mins, (1.8 km)\n", + "\n", + " 🍽️ Trattoria da Enzo\n", + " Enjoy traditional Roman dishes in a charming setting with great \n", + " ratings. \n", + "\n", + " 🚶 walking from Trattoria da Enzo to Trevi Fountain\n", + " 28 mins, (2.0 km)\n", + "\n", + " 🏛️ Trevi Fountain\n", + " Visit the stunning baroque fountain and toss a coin to ensure your \n", + " return to Rome. \n", + "\n", + " 🚶 walking from Trevi Fountain to Armando al Pantheon\n", + " 9 mins, (0.7 km)\n", + "\n", + " 🍽️ Armando al Pantheon\n", + " Savor authentic Roman cuisine in a restaurant that boasts a great \n", + " atmosphere and top-notch dishes. \n", + "\n", + "--------------------------------------------------------------------------------\n", + " \n", + "Day 2 \n", + "--------------------------------------------------------------------------------\n", + "\n", + " 🏛️ Vatican Museums\n", + " Discover a vast collection of art and historical artifacts, including \n", + " the famous Sistine Chapel. \n", + "\n", + " 🚶 walking from Vatican Museums to Osteria delle Commari\n", + " 2 mins, (0.2 km)\n", + "\n", + " 🍽️ Osteria delle Commari\n", + " Enjoy home-style Roman cuisine in a cozy, welcoming environment. \n", + "\n", + " 🚶 walking from Osteria delle Commari to Basilica di Santa Maria Maggiore\n", + " 1 hour 5 mins, (4.6 km)\n", + "\n", + " 🏛️ Basilica di Santa Maria Maggiore\n", + " Explore one of the largest churches in Rome, known for its beautiful \n", + " mosaics and rich history. \n", + "\n", + " 🚶 walking from Basilica di Santa Maria Maggiore to Tonnarello\n", + " 44 mins, (3.2 km)\n", + "\n", + " 🍽️ Tonnarello\n", + " Enjoy traditional Italian dishes in a vibrant atmosphere, known for its \n", + " great flavors and local feel. \n", + "\n", + "--------------------------------------------------------------------------------\n" + ] + } + ], "source": [ "def print_itinerary(itinerary_data):\n", " header = \"█ █\\n █ █ \\n █ █████ █ \\n ██ ██ \\n █ █ \\n █ ███████ █ \\n █ ██ ███ ██ █ \\n █████████ \\n\\n ██ ███ ███ \\n█ █ █ █ \\n████ █ ██ ██ \\n█ █ █ █ █ \\n█ █ ██ ████ \\n\"\n", From 9e3a95ce5018157ba794883dcf064d3a4e5f2c56 Mon Sep 17 00:00:00 2001 From: Mark Sze <66362098+marklysze@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:26:38 +1100 Subject: [PATCH 16/20] Remove unnecessary comment from notebook --- notebook/agentchat_swarm_graphrag_trip_planner.ipynb | 1 - 1 file changed, 1 deletion(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 5364d640ba..f8ed0aa426 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -642,7 +642,6 @@ "source": [ "planner_agent.register_hand_off(\n", " hand_to=[\n", - " # Update to 'target' rather than 'agent'\n", " ON_CONDITION(\n", " graphrag_agent,\n", " \"Need information on the restaurants and attractions for a location. DO NOT call more than once at a time.\",\n", From 8067e64f3c6693ce14c0d940aaa6421c836646b5 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Thu, 5 Dec 2024 21:14:23 +0000 Subject: [PATCH 17/20] Notebook demo update Signed-off-by: Mark Sze --- ...gentchat_swarm_graphrag_trip_planner.ipynb | 528 +----------------- 1 file changed, 26 insertions(+), 502 deletions(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index f8ed0aa426..443cfbbd5b 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -83,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -111,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -139,7 +139,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -217,59 +217,6 @@ " ],\n", " )\n", ")\n", - "trip_data_ontology.add_relation(\n", - " Relation(\n", - " label=\"IN_COUNTRY\",\n", - " source=\"City\",\n", - " target=\"Country\",\n", - " )\n", - ")\n", - "trip_data_ontology.add_relation(\n", - " Relation(\n", - " label=\"IN_CITY\",\n", - " source=\"Restaurant\",\n", - " target=\"City\",\n", - " )\n", - ")\n", - "\n", - "trip_data_ontology.add_entity(\n", - " Entity(\n", - " label=\"Country\",\n", - " attributes=[\n", - " Attribute(\n", - " name=\"name\",\n", - " attr_type=AttributeType.STRING,\n", - " required=True,\n", - " unique=True,\n", - " ),\n", - " ],\n", - " )\n", - ")\n", - "trip_data_ontology.add_entity(\n", - " Entity(\n", - " label=\"City\",\n", - " attributes=[\n", - " Attribute(\n", - " name=\"name\",\n", - " attr_type=AttributeType.STRING,\n", - " required=True,\n", - " unique=True,\n", - " ),\n", - " Attribute(\n", - " name=\"weather\",\n", - " attr_type=AttributeType.STRING,\n", - " required=False,\n", - " unique=False,\n", - " ),\n", - " Attribute(\n", - " name=\"population\",\n", - " attr_type=AttributeType.NUMBER,\n", - " required=False,\n", - " unique=False,\n", - " ),\n", - " ],\n", - " )\n", - ")\n", "trip_data_ontology.add_entity(\n", " Entity(\n", " label=\"Attraction\",\n", @@ -305,6 +252,13 @@ "trip_data_ontology.add_relation(\n", " Relation(\n", " label=\"IN_CITY\",\n", + " source=\"Restaurant\",\n", + " target=\"City\",\n", + " )\n", + ")\n", + "trip_data_ontology.add_relation(\n", + " Relation(\n", + " label=\"IN_CITY\",\n", " source=\"Attraction\",\n", " target=\"City\",\n", " )\n", @@ -341,15 +295,15 @@ ")\n", "\n", "# Ingest data and initialize the database\n", - "query_engine.init_db(input_doc=input_documents)\n", + "# query_engine.init_db(input_doc=input_documents)\n", "\n", "# If you have already ingested and created the database, you can use this connect_db instead of init_db\n", - "# query_engine.connect_db()" + "query_engine.connect_db()" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -385,7 +339,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -415,7 +369,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -505,7 +459,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -531,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -546,7 +500,7 @@ " )\n", "\n", "\n", - "def create_structured_itinerary(context_variables: Dict[str, Any], structured_itinerary: Itinerary) -> SwarmResult:\n", + "def create_structured_itinerary(context_variables: Dict[str, Any], structured_itinerary: str) -> SwarmResult:\n", " \"\"\"Once a structured itinerary is created, store it and pass on to the Route Timing agent.\"\"\"\n", "\n", " # Ensure the itinerary is confirmed, if not, back to the Planner agent to confirm it with the customer\n", @@ -575,7 +529,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -602,13 +556,12 @@ "graph_rag_capability = FalkorGraphRagCapability(query_engine)\n", "graph_rag_capability.add_to_agent(graphrag_agent)\n", "\n", - "# Structured Output agent, formatting the itinerary into a structured format through the response_format parameter\n", + "# Structured Output agent, formatting the itinerary into a structured format through the response_format on the LLM Configuration\n", "structured_output_agent = SwarmAgent(\n", " name=\"structured_output_agent\",\n", " system_message=\"You are a data formatting agent, format the provided itinerary in the context below into the provided format.\",\n", - " llm_config=llm_config,\n", + " llm_config={**llm_config, \"response_format\": Itinerary},\n", " functions=[create_structured_itinerary],\n", - " response_format=Itinerary,\n", ")\n", "\n", "# Route Timing agent, adding estimated travel times to the itinerary by utilising the Google Maps Platform\n", @@ -636,7 +589,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -675,355 +628,9 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", - "\n", - "I want to go to Rome for a couple of days. Can you help me plan my trip?\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "Of course! I'd love to help you plan your trip to Rome. \n", - "\n", - "To get started, could you please provide me with the following information:\n", - "1. How many days will you be staying in Rome?\n", - "2. What activities or attractions are you interested in? (e.g., historical sites, museums, shopping, dining, etc.)\n", - "3. Do you have any specific preferences for meals or restaurants? \n", - "\n", - "Once I have this information, I can start creating an itinerary for you!\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: customer\n", - "\u001b[0m\n", - "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", - "\n", - "2 days please, I want lunch and dinner, with an attraction to see in the morning and after lunch.\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Suggested tool call (call_2dmMbckU5YjaCsL6Y8pWbrdK): transfer_to_graphrag_agent *****\u001b[0m\n", - "Arguments: \n", - "{}\n", - "\u001b[32m*******************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION transfer_to_graphrag_agent...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_2dmMbckU5YjaCsL6Y8pWbrdK) *****\u001b[0m\n", - "SwarmAgent --> graphrag_agent\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: graphrag_agent\n", - "\u001b[0m\n", - "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", - "\n", - "Restaurants in Rome:\n", - "1. Trattoria da Enzo - Italian, traditional Roman dishes, rating: 4.5\n", - "2. Il Pagliaccio - Italian, Michelin-starred, rating: 4.8\n", - "3. Tonnarello - Italian, traditional dishes, rating: 4.7\n", - "4. Osteria delle Commari - Italian, home-style Roman cuisine, rating: 4.3\n", - "5. Armando al Pantheon - Italian, traditional Roman cuisine, rating: 4.8\n", - "6. Salumeria Roscioli Ristorante - Italian, pasta and wine cellar, rating: 4.5\n", - "7. L'Arcangelo - Italian, known for supplì and gnocchi, rating: 4.8\n", - "\n", - "Attractions in Rome:\n", - "1. Colosseum - Historical site\n", - "2. Vatican Museums - Art museum\n", - "3. Trevi Fountain - Landmark\n", - "4. Basilica di Santa Maria Maggiore - Religious site\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "Great! Here’s a proposed 2-day itinerary for your trip to Rome:\n", - "\n", - "### Day 1:\n", - "- **Morning:**\n", - " - **Type:** Attraction \n", - " - **Location:** Colosseum \n", - " - **City:** Rome \n", - " - **Description:** Explore the iconic symbol of Rome, a magnificent ancient amphitheater where gladiators once battled.\n", - "\n", - "- **Lunch:**\n", - " - **Type:** Restaurant \n", - " - **Location:** Trattoria da Enzo \n", - " - **City:** Rome \n", - " - **Description:** Enjoy traditional Roman dishes in a charming setting with great ratings.\n", - "\n", - "- **Afternoon:**\n", - " - **Type:** Attraction \n", - " - **Location:** Trevi Fountain \n", - " - **City:** Rome \n", - " - **Description:** Visit the stunning baroque fountain and toss a coin to ensure your return to Rome.\n", - "\n", - "- **Dinner:**\n", - " - **Type:** Restaurant \n", - " - **Location:** Armando al Pantheon \n", - " - **City:** Rome \n", - " - **Description:** Savor authentic Roman cuisine in a restaurant that boasts a great atmosphere and top-notch dishes.\n", - "\n", - "### Day 2:\n", - "- **Morning:**\n", - " - **Type:** Attraction \n", - " - **Location:** Vatican Museums \n", - " - **City:** Rome \n", - " - **Description:** Discover a vast collection of art and historical artifacts, including the famous Sistine Chapel.\n", - "\n", - "- **Lunch:**\n", - " - **Type:** Restaurant \n", - " - **Location:** Osteria delle Commari \n", - " - **City:** Rome \n", - " - **Description:** Enjoy home-style Roman cuisine in a cozy, welcoming environment.\n", - "\n", - "- **Afternoon:**\n", - " - **Type:** Attraction \n", - " - **Location:** Basilica di Santa Maria Maggiore \n", - " - **City:** Rome \n", - " - **Description:** Explore one of the largest churches in Rome, known for its beautiful mosaics and rich history.\n", - "\n", - "- **Dinner:**\n", - " - **Type:** Restaurant \n", - " - **Location:** Il Pagliaccio \n", - " - **City:** Rome \n", - " - **Description:** Experience a Michelin-starred dining option with a unique menu and exquisite taste.\n", - "\n", - "Does this itinerary look good to you? Let me know if you would like any changes or adjustments!\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: customer\n", - "\u001b[0m\n", - "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", - "\n", - "I'm not a fan of Il Pagliaccio, please select another restaurant.\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Suggested tool call (call_7aUs54WvG0A31PNTJnNyKUWE): transfer_to_graphrag_agent *****\u001b[0m\n", - "Arguments: \n", - "{}\n", - "\u001b[32m*******************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION transfer_to_graphrag_agent...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_7aUs54WvG0A31PNTJnNyKUWE) *****\u001b[0m\n", - "SwarmAgent --> graphrag_agent\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: graphrag_agent\n", - "\u001b[0m\n", - "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", - "\n", - "Restaurants in Rome:\n", - "1. Trattoria da Enzo - Italian, traditional Roman dishes, rating: 4.5\n", - "2. Il Pagliaccio - Italian, Michelin-starred, rating: 4.8\n", - "3. Tonnarello - Italian, traditional dishes, rating: 4.7\n", - "4. Osteria delle Commari - Italian, home-style Roman cuisine, rating: 4.3\n", - "5. Armando al Pantheon - Italian, traditional Roman cuisine, rating: 4.8\n", - "6. Salumeria Roscioli Ristorante - Italian, pasta and wine cellar, rating: 4.5\n", - "7. L'Arcangelo - Italian, known for supplì and gnocchi, rating: 4.8\n", - "\n", - "Attractions in Rome:\n", - "1. Colosseum - Historical site\n", - "2. Vatican Museums - Art museum\n", - "3. Trevi Fountain - Landmark\n", - "4. Basilica di Santa Maria Maggiore - Religious site\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "No problem! Let's replace Il Pagliaccio with another restaurant.\n", - "\n", - "### Updated Day 2 Itinerary:\n", - "- **Dinner:**\n", - " - **Type:** Restaurant \n", - " - **Location:** Tonnarello \n", - " - **City:** Rome \n", - " - **Description:** Enjoy traditional Italian dishes in a vibrant atmosphere, known for its great flavors and local feel.\n", - "\n", - "Here's the complete itinerary:\n", - "\n", - "### Day 1:\n", - "- **Morning:** \n", - " - **Type:** Attraction \n", - " - **Location:** Colosseum \n", - " - **City:** Rome \n", - " - **Description:** Explore the iconic symbol of Rome, a magnificent ancient amphitheater where gladiators once battled.\n", - "\n", - "- **Lunch:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Trattoria da Enzo \n", - " - **City:** Rome \n", - " - **Description:** Enjoy traditional Roman dishes in a charming setting with great ratings.\n", - "\n", - "- **Afternoon:** \n", - " - **Type:** Attraction \n", - " - **Location:** Trevi Fountain \n", - " - **City:** Rome \n", - " - **Description:** Visit the stunning baroque fountain and toss a coin to ensure your return to Rome.\n", - "\n", - "- **Dinner:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Armando al Pantheon \n", - " - **City:** Rome \n", - " - **Description:** Savor authentic Roman cuisine in a restaurant that boasts a great atmosphere and top-notch dishes.\n", - "\n", - "### Day 2:\n", - "- **Morning:** \n", - " - **Type:** Attraction \n", - " - **Location:** Vatican Museums \n", - " - **City:** Rome \n", - " - **Description:** Discover a vast collection of art and historical artifacts, including the famous Sistine Chapel.\n", - "\n", - "- **Lunch:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Osteria delle Commari \n", - " - **City:** Rome \n", - " - **Description:** Enjoy home-style Roman cuisine in a cozy, welcoming environment.\n", - "\n", - "- **Afternoon:** \n", - " - **Type:** Attraction \n", - " - **Location:** Basilica di Santa Maria Maggiore \n", - " - **City:** Rome \n", - " - **Description:** Explore one of the largest churches in Rome, known for its beautiful mosaics and rich history.\n", - "\n", - "- **Dinner:** \n", - " - **Type:** Restaurant \n", - " - **Location:** Tonnarello \n", - " - **City:** Rome \n", - " - **Description:** Enjoy traditional Italian dishes in a vibrant atmosphere, known for its great flavors and local feel.\n", - "\n", - "Are you happy with this updated itinerary? Let me know if you want any more changes!\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: customer\n", - "\u001b[0m\n", - "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", - "\n", - "Great, thank you, let's go!\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: planner_agent\n", - "\u001b[0m\n", - "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Suggested tool call (call_RibOtG2YA85QXVBaUzoSS2El): mark_itinerary_as_complete *****\u001b[0m\n", - "Arguments: \n", - "{\"final_itinerary\":\"### Day 1:\\n- **Morning:** \\n - **Type:** Attraction \\n - **Location:** Colosseum \\n - **City:** Rome \\n - **Description:** Explore the iconic symbol of Rome, a magnificent ancient amphitheater where gladiators once battled.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Trattoria da Enzo \\n - **City:** Rome \\n - **Description:** Enjoy traditional Roman dishes in a charming setting with great ratings.\\n\\n- **Afternoon:** \\n - **Type:** Attraction \\n - **Location:** Trevi Fountain \\n - **City:** Rome \\n - **Description:** Visit the stunning baroque fountain and toss a coin to ensure your return to Rome.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Armando al Pantheon \\n - **City:** Rome \\n - **Description:** Savor authentic Roman cuisine in a restaurant that boasts a great atmosphere and top-notch dishes.\\n\\n### Day 2:\\n- **Morning:** \\n - **Type:** Attraction \\n - **Location:** Vatican Museums \\n - **City:** Rome \\n - **Description:** Discover a vast collection of art and historical artifacts, including the famous Sistine Chapel.\\n\\n- **Lunch:** \\n - **Type:** Restaurant \\n - **Location:** Osteria delle Commari \\n - **City:** Rome \\n - **Description:** Enjoy home-style Roman cuisine in a cozy, welcoming environment.\\n\\n- **Afternoon:** \\n - **Type:** Attraction \\n - **Location:** Basilica di Santa Maria Maggiore \\n - **City:** Rome \\n - **Description:** Explore one of the largest churches in Rome, known for its beautiful mosaics and rich history.\\n\\n- **Dinner:** \\n - **Type:** Restaurant \\n - **Location:** Tonnarello \\n - **City:** Rome \\n - **Description:** Enjoy traditional Italian dishes in a vibrant atmosphere, known for its great flavors and local feel.\"}\n", - "\u001b[32m*******************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION mark_itinerary_as_complete...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_RibOtG2YA85QXVBaUzoSS2El) *****\u001b[0m\n", - "Itinerary recorded and confirmed.\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: structured_output_agent\n", - "\u001b[0m\n", - "\u001b[33mstructured_output_agent\u001b[0m (to chat_manager):\n", - "\n", - "{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"Explore the iconic symbol of Rome, a magnificent ancient amphitheater where gladiators once battled.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Roman dishes in a charming setting with great ratings.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"Visit the stunning baroque fountain and toss a coin to ensure your return to Rome.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Savor authentic Roman cuisine in a restaurant that boasts a great atmosphere and top-notch dishes.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"Discover a vast collection of art and historical artifacts, including the famous Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"Enjoy home-style Roman cuisine in a cozy, welcoming environment.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"Explore one of the largest churches in Rome, known for its beautiful mosaics and rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Italian dishes in a vibrant atmosphere, known for its great flavors and local feel.\"}]}]}\n", - "\u001b[32m***** Suggested tool call (call_ZZuv1U9iUcZZaDsa7hOGtaFY): create_structured_itinerary *****\u001b[0m\n", - "Arguments: \n", - "{\"structured_itinerary\":{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"Explore the iconic symbol of Rome, a magnificent ancient amphitheater where gladiators once battled.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Roman dishes in a charming setting with great ratings.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"Visit the stunning baroque fountain and toss a coin to ensure your return to Rome.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Savor authentic Roman cuisine in a restaurant that boasts a great atmosphere and top-notch dishes.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"Discover a vast collection of art and historical artifacts, including the famous Sistine Chapel.\"},{\"type\":\"Restaurant\",\"location\":\"Osteria delle Commari\",\"city\":\"Rome\",\"description\":\"Enjoy home-style Roman cuisine in a cozy, welcoming environment.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"Explore one of the largest churches in Rome, known for its beautiful mosaics and rich history.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Italian dishes in a vibrant atmosphere, known for its great flavors and local feel.\"}]}]}}\n", - "\u001b[32m********************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION create_structured_itinerary...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_ZZuv1U9iUcZZaDsa7hOGtaFY) *****\u001b[0m\n", - "Structured itinerary stored.\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: route_timing_agent\n", - "\u001b[0m\n", - "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Suggested tool call (call_H8U9HTdJTnY8kxU2QFiq1aCn): update_itinerary_with_travel_times *****\u001b[0m\n", - "Arguments: \n", - "{}\n", - "\u001b[32m***************************************************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: Tool_Execution\n", - "\u001b[0m\n", - "\u001b[35m\n", - ">>>>>>>> EXECUTING FUNCTION update_itinerary_with_travel_times...\u001b[0m\n", - "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", - "\n", - "\u001b[32m***** Response from calling tool (call_H8U9HTdJTnY8kxU2QFiq1aCn) *****\u001b[0m\n", - "Timed itinerary added to context with travel times\n", - "\u001b[32m**********************************************************************\u001b[0m\n", - "\n", - "--------------------------------------------------------------------------------\n", - "\u001b[32m\n", - "Next speaker: route_timing_agent\n", - "\u001b[0m\n", - "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", - "\n", - "Your itinerary is ready! Enjoy your trip to Rome, exploring the Colosseum, Vatican Museums, and delicious dining experiences at the recommended restaurants. If you have any further questions or need assistance while you're there, feel free to reach out! Safe travels!\n", - "\n", - "--------------------------------------------------------------------------------\n" - ] - } - ], + "outputs": [], "source": [ "# Start the conversation\n", "\n", @@ -1047,92 +654,9 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " █ █ \n", - " █ █ \n", - " █ █████ █ \n", - " ██ ██ \n", - " █ █ \n", - " █ ███████ █ \n", - " █ ██ ███ ██ █ \n", - " █████████ \n", - " \n", - " ██ ███ ███ \n", - " █ █ █ █ \n", - " ████ █ ██ ██ \n", - " █ █ █ █ █ \n", - " █ █ ██ ████ \n", - " \n", - " Itinerary for Rome \n", - "================================================================================\n", - " \n", - "Day 1 \n", - "--------------------------------------------------------------------------------\n", - "\n", - " 🏛️ Colosseum\n", - " Explore the iconic symbol of Rome, a magnificent ancient amphitheater \n", - " where gladiators once battled. \n", - "\n", - " 🚶 walking from Colosseum to Trattoria da Enzo\n", - " 24 mins, (1.8 km)\n", - "\n", - " 🍽️ Trattoria da Enzo\n", - " Enjoy traditional Roman dishes in a charming setting with great \n", - " ratings. \n", - "\n", - " 🚶 walking from Trattoria da Enzo to Trevi Fountain\n", - " 28 mins, (2.0 km)\n", - "\n", - " 🏛️ Trevi Fountain\n", - " Visit the stunning baroque fountain and toss a coin to ensure your \n", - " return to Rome. \n", - "\n", - " 🚶 walking from Trevi Fountain to Armando al Pantheon\n", - " 9 mins, (0.7 km)\n", - "\n", - " 🍽️ Armando al Pantheon\n", - " Savor authentic Roman cuisine in a restaurant that boasts a great \n", - " atmosphere and top-notch dishes. \n", - "\n", - "--------------------------------------------------------------------------------\n", - " \n", - "Day 2 \n", - "--------------------------------------------------------------------------------\n", - "\n", - " 🏛️ Vatican Museums\n", - " Discover a vast collection of art and historical artifacts, including \n", - " the famous Sistine Chapel. \n", - "\n", - " 🚶 walking from Vatican Museums to Osteria delle Commari\n", - " 2 mins, (0.2 km)\n", - "\n", - " 🍽️ Osteria delle Commari\n", - " Enjoy home-style Roman cuisine in a cozy, welcoming environment. \n", - "\n", - " 🚶 walking from Osteria delle Commari to Basilica di Santa Maria Maggiore\n", - " 1 hour 5 mins, (4.6 km)\n", - "\n", - " 🏛️ Basilica di Santa Maria Maggiore\n", - " Explore one of the largest churches in Rome, known for its beautiful \n", - " mosaics and rich history. \n", - "\n", - " 🚶 walking from Basilica di Santa Maria Maggiore to Tonnarello\n", - " 44 mins, (3.2 km)\n", - "\n", - " 🍽️ Tonnarello\n", - " Enjoy traditional Italian dishes in a vibrant atmosphere, known for its \n", - " great flavors and local feel. \n", - "\n", - "--------------------------------------------------------------------------------\n" - ] - } - ], + "outputs": [], "source": [ "def print_itinerary(itinerary_data):\n", " header = \"█ █\\n █ █ \\n █ █████ █ \\n ██ ██ \\n █ █ \\n █ ███████ █ \\n █ ██ ███ ██ █ \\n █████████ \\n\\n ██ ███ ███ \\n█ █ █ █ \\n████ █ ██ ██ \\n█ █ █ █ █ \\n█ █ ██ ████ \\n\"\n", From 4484772bf8796d2692df7d944ed57ff8af65e9a1 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Thu, 5 Dec 2024 22:06:10 +0000 Subject: [PATCH 18/20] Final demo notebook Signed-off-by: Mark Sze --- ...gentchat_swarm_graphrag_trip_planner.ipynb | 284 ++++++++++++++++-- 1 file changed, 265 insertions(+), 19 deletions(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 443cfbbd5b..106bcbe617 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -83,15 +83,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n" + ] + } + ], "source": [ "import os\n", "\n", "import autogen\n", "\n", - "config_list = autogen.config_list_from_json(env_or_file=\"OAI_CONFIG_LIST\", filter_dict={\"model\": [\"gpt-4o-mini\"]})\n", + "config_list = autogen.config_list_from_json(env_or_file=\"OAI_CONFIG_LIST\", filter_dict={\"model\": [\"gpt-4o\"]})\n", "llm_config = {\"config_list\": config_list, \"timeout\": 120}\n", "\n", "# Put the OpenAI API key into the environment\n", @@ -111,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -139,7 +148,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -276,7 +285,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -303,11 +312,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# IMPORTS\n", + "import copy\n", + "import json\n", "import os\n", "from typing import Any, Dict\n", "\n", @@ -339,7 +350,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -369,7 +380,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -407,9 +418,11 @@ " agent=\"structured_output_agent\",\n", " values=\"Structured itinerary not found, please create the structured output, structured_output_agent.\",\n", " )\n", + " elif \"timed_itinerary\" in context_variables:\n", + " return SwarmResult(values=\"Timed itinerary already done, inform the customer that their itinerary is ready!\")\n", "\n", " # Process the itinerary, converting it back to an object and working through each event to work out travel time and distance\n", - " itinerary_object = Itinerary.model_validate(context_variables[\"structured_itinerary\"])\n", + " itinerary_object = Itinerary.model_validate(json.loads(context_variables[\"structured_itinerary\"]))\n", " for day in itinerary_object.days:\n", " events = day.events\n", " new_events = []\n", @@ -459,7 +472,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -485,7 +498,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -557,17 +570,21 @@ "graph_rag_capability.add_to_agent(graphrag_agent)\n", "\n", "# Structured Output agent, formatting the itinerary into a structured format through the response_format on the LLM Configuration\n", + "structured_config_list = copy.deepcopy(config_list)\n", + "for config in structured_config_list:\n", + " config[\"response_format\"] = Itinerary\n", + "\n", "structured_output_agent = SwarmAgent(\n", " name=\"structured_output_agent\",\n", " system_message=\"You are a data formatting agent, format the provided itinerary in the context below into the provided format.\",\n", - " llm_config={**llm_config, \"response_format\": Itinerary},\n", + " llm_config={\"config_list\": structured_config_list, \"timeout\": 120},\n", " functions=[create_structured_itinerary],\n", ")\n", "\n", "# Route Timing agent, adding estimated travel times to the itinerary by utilising the Google Maps Platform\n", "route_timing_agent = SwarmAgent(\n", " name=\"route_timing_agent\",\n", - " system_message=\"You are a route timing agent. IMPORTANT - you must call the update_itinerary_with_travel_times function until 'Timed itinerary added to context with travel times' is seen in this conversation. After that, you can tell the customer 'Your itinerary is ready!'.\",\n", + " system_message=\"You are a route timing agent. YOU MUST call the update_itinerary_with_travel_times tool if you do not see the exact phrase 'Timed itinerary added to context with travel times' is seen in this conversation. Only after this please tell the customer 'Your itinerary is ready!'.\",\n", " llm_config=llm_config,\n", " functions=[update_itinerary_with_travel_times],\n", ")\n", @@ -589,7 +606,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -628,9 +645,230 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "I want to go to Rome for a couple of days. Can you help me plan my trip?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "Sure! How many days will you be staying in Rome? Additionally, what type of activities are you interested in doing, and do you have any specific preferences for meals (e.g., certain type of cuisine or dining experience)?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "2 days please, I want lunch and dinner, with an attraction to see in the morning and after lunch.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_vQMpso8aOomdfq8S2uCRlnzj): transfer_to_graphrag_agent *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m*******************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION transfer_to_graphrag_agent...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_vQMpso8aOomdfq8S2uCRlnzj) *****\u001b[0m\n", + "SwarmAgent --> graphrag_agent\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: graphrag_agent\n", + "\u001b[0m\n", + "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", + "\n", + "Restaurants in Rome:\n", + "1. Trattoria da Enzo - A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere. Rating: 4.5\n", + "2. Il Pagliaccio - An elegant Michelin-starred restaurant offering contemporary Italian cuisine. Rating: 4.8\n", + "3. Tonnarello - Casual stop for pasta, meatballs & other simple Roman dishes, with patio seating & acoustic guitar. Rating: 4.7\n", + "4. Osteria delle Commari - Local home-style Roman restaurant near Vatican Museums. Rating: 4.3\n", + "5. Armando al Pantheon - Traditional Roman cuisine since 1961 near the Pantheon. Rating: 4.8\n", + "6. Salumeria Roscioli Ristorante - Known for Pasta alla gricia and amatriciana, with an impressive wine cellar. Rating: 4.5\n", + "7. L'Arcangelo - Famous for supplì (Roman rice balls) and gnocchi on Thursdays. Rating: 4.8\n", + "\n", + "Attractions in Rome:\n", + "1. Colosseum - An ancient amphitheater known for gladiatorial contests and public spectacles.\n", + "2. Vatican Museums - A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + "3. Trevi Fountain - A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", + "4. Basilica di Santa Maria Maggiore - A major basilica in Rome, known for its rich history and impressive architecture.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "Great! Here's a suggested itinerary for your 2-day trip to Rome:\n", + "\n", + "### Day 1\n", + "- **Morning Attraction**\n", + " - **Type**: Attraction\n", + " - **Location**: Colosseum\n", + " - **City**: Rome\n", + " - **Description**: Explore the iconic ancient amphitheater known for gladiatorial contests and public spectacles.\n", + "\n", + "- **Lunch**\n", + " - **Type**: Restaurant\n", + " - **Location**: Trattoria da Enzo\n", + " - **City**: Rome\n", + " - **Description**: Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\n", + "\n", + "- **Afternoon Attraction**\n", + " - **Type**: Attraction\n", + " - **Location**: Trevi Fountain\n", + " - **City**: Rome\n", + " - **Description**: Visit the stunning Baroque fountain and participate in the tradition of tossing coins.\n", + "\n", + "- **Dinner**\n", + " - **Type**: Restaurant\n", + " - **Location**: Armando al Pantheon\n", + " - **City**: Rome\n", + " - **Description**: Savor traditional Roman cuisine at a historic restaurant near the Pantheon.\n", + "\n", + "### Day 2\n", + "- **Morning Attraction**\n", + " - **Type**: Attraction\n", + " - **Location**: Vatican Museums\n", + " - **City**: Rome\n", + " - **Description**: Discover a complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + "\n", + "- **Lunch**\n", + " - **Type**: Restaurant\n", + " - **Location**: Tonnarello\n", + " - **City**: Rome\n", + " - **Description**: Enjoy casual dining with pasta, meatballs, and other simple Roman dishes.\n", + "\n", + "- **Afternoon Attraction**\n", + " - **Type**: Attraction\n", + " - **Location**: Basilica di Santa Maria Maggiore\n", + " - **City**: Rome\n", + " - **Description**: Visit a major basilica known for its rich history and impressive architecture.\n", + "\n", + "- **Dinner**\n", + " - **Type**: Restaurant\n", + " - **Location**: Il Pagliaccio\n", + " - **City**: Rome\n", + " - **Description**: Experience elegant contemporary Italian cuisine at a Michelin-starred restaurant.\n", + "\n", + "Does this itinerary meet your expectations, or is there anything you'd like to change?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "I don't feel like eating at Il Pagliaccio.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "No problem! Let's choose a different restaurant for dinner on Day 2.\n", + "\n", + "### Updated Itinerary for Day 2\n", + "\n", + "- **Dinner**\n", + " - **Type**: Restaurant\n", + " - **Location**: Salumeria Roscioli Ristorante\n", + " - **City**: Rome\n", + " - **Description**: Enjoy a selection of traditional pasta dishes like Pasta alla gricia and amatriciana, paired with an impressive wine cellar.\n", + "\n", + "Is this revised itinerary more to your liking?\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "Yes, thanks\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_C93kDFyT4DiYuUYVzcWtum84): mark_itinerary_as_complete *****\u001b[0m\n", + "Arguments: \n", + "{\"final_itinerary\":\"### Day 1\\n- **Morning Attraction**\\n - **Type**: Attraction\\n - **Location**: Colosseum\\n - **City**: Rome\\n - **Description**: Explore the iconic ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch**\\n - **Type**: Restaurant\\n - **Location**: Trattoria da Enzo\\n - **City**: Rome\\n - **Description**: Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\\n\\n- **Afternoon Attraction**\\n - **Type**: Attraction\\n - **Location**: Trevi Fountain\\n - **City**: Rome\\n - **Description**: Visit the stunning Baroque fountain and participate in the tradition of tossing coins.\\n\\n- **Dinner**\\n - **Type**: Restaurant\\n - **Location**: Armando al Pantheon\\n - **City**: Rome\\n - **Description**: Savor traditional Roman cuisine at a historic restaurant near the Pantheon.\\n\\n### Day 2\\n- **Morning Attraction**\\n - **Type**: Attraction\\n - **Location**: Vatican Museums\\n - **City**: Rome\\n - **Description**: Discover a complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch**\\n - **Type**: Restaurant\\n - **Location**: Tonnarello\\n - **City**: Rome\\n - **Description**: Enjoy casual dining with pasta, meatballs, and other simple Roman dishes.\\n\\n- **Afternoon Attraction**\\n - **Type**: Attraction\\n - **Location**: Basilica di Santa Maria Maggiore\\n - **City**: Rome\\n - **Description**: Visit a major basilica known for its rich history and impressive architecture.\\n\\n- **Dinner**\\n - **Type**: Restaurant\\n - **Location**: Salumeria Roscioli Ristorante\\n - **City**: Rome\\n - **Description**: Enjoy a selection of traditional pasta dishes like Pasta alla gricia and amatriciana, paired with an impressive wine cellar.\"}\n", + "\u001b[32m*******************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION mark_itinerary_as_complete...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_C93kDFyT4DiYuUYVzcWtum84) *****\u001b[0m\n", + "Itinerary recorded and confirmed.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: structured_output_agent\n", + "\u001b[0m\n", + "\u001b[33mstructured_output_agent\u001b[0m (to chat_manager):\n", + "\n", + "{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"Explore the iconic ancient amphitheater known for gladiatorial contests and public spectacles.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"Visit the stunning Baroque fountain and participate in the tradition of tossing coins.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Savor traditional Roman cuisine at a historic restaurant near the Pantheon.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"Discover a complex of museums and galleries showcasing works of art collected by Popes over centuries.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Enjoy casual dining with pasta, meatballs, and other simple Roman dishes.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"Visit a major basilica known for its rich history and impressive architecture.\"},{\"type\":\"Restaurant\",\"location\":\"Salumeria Roscioli Ristorante\",\"city\":\"Rome\",\"description\":\"Enjoy a selection of traditional pasta dishes like Pasta alla gricia and amatriciana, paired with an impressive wine cellar.\"}]}]}\n", + "\u001b[32m***** Suggested tool call (call_j2q6rADCfMqK4FfIjMA91YR4): create_structured_itinerary *****\u001b[0m\n", + "Arguments: \n", + "{\"structured_itinerary\":\"{\\\"days\\\":[{\\\"events\\\":[{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Colosseum\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Explore the iconic ancient amphitheater known for gladiatorial contests and public spectacles.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Trattoria da Enzo\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\\\"},{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Trevi Fountain\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Visit the stunning Baroque fountain and participate in the tradition of tossing coins.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Armando al Pantheon\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Savor traditional Roman cuisine at a historic restaurant near the Pantheon.\\\"}]},{\\\"events\\\":[{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Vatican Museums\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Discover a complex of museums and galleries showcasing works of art collected by Popes over centuries.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Tonnarello\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Enjoy casual dining with pasta, meatballs, and other simple Roman dishes.\\\"},{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Basilica di Santa Maria Maggiore\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Visit a major basilica known for its rich history and impressive architecture.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Salumeria Roscioli Ristorante\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Enjoy a selection of traditional pasta dishes like Pasta alla gricia and amatriciana, paired with an impressive wine cellar.\\\"}]}]}\"}\n", + "\u001b[32m********************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION create_structured_itinerary...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_j2q6rADCfMqK4FfIjMA91YR4) *****\u001b[0m\n", + "Structured itinerary stored.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: route_timing_agent\n", + "\u001b[0m\n", + "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", + "\n", + "Your itinerary is ready! Enjoy your trip to Rome!\n", + "\n", + "--------------------------------------------------------------------------------\n" + ] + } + ], "source": [ "# Start the conversation\n", "\n", @@ -654,9 +892,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No itinerary available to print.\n" + ] + } + ], "source": [ "def print_itinerary(itinerary_data):\n", " header = \"█ █\\n █ █ \\n █ █████ █ \\n ██ ██ \\n █ █ \\n █ ███████ █ \\n █ ██ ███ ██ █ \\n █████████ \\n\\n ██ ███ ███ \\n█ █ █ █ \\n████ █ ██ ██ \\n█ █ █ █ █ \\n█ █ ██ ████ \\n\"\n", From 7de04084c3c9b093c7f6869e7142587a1ce079bc Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Thu, 5 Dec 2024 22:08:28 +0000 Subject: [PATCH 19/20] Added itinerary output in notebook Signed-off-by: Mark Sze --- ...gentchat_swarm_graphrag_trip_planner.ipynb | 365 ++++++++++++++---- 1 file changed, 286 insertions(+), 79 deletions(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 106bcbe617..5fb0212ef3 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -542,7 +542,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -702,19 +702,19 @@ "\u001b[33mgraphrag_agent\u001b[0m (to chat_manager):\n", "\n", "Restaurants in Rome:\n", - "1. Trattoria da Enzo - A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere. Rating: 4.5\n", - "2. Il Pagliaccio - An elegant Michelin-starred restaurant offering contemporary Italian cuisine. Rating: 4.8\n", - "3. Tonnarello - Casual stop for pasta, meatballs & other simple Roman dishes, with patio seating & acoustic guitar. Rating: 4.7\n", - "4. Osteria delle Commari - Local home-style Roman restaurant near Vatican Museums. Rating: 4.3\n", - "5. Armando al Pantheon - Traditional Roman cuisine since 1961 near the Pantheon. Rating: 4.8\n", - "6. Salumeria Roscioli Ristorante - Known for Pasta alla gricia and amatriciana, with an impressive wine cellar. Rating: 4.5\n", - "7. L'Arcangelo - Famous for supplì (Roman rice balls) and gnocchi on Thursdays. Rating: 4.8\n", + "1. Trattoria da Enzo - A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere (Rating: 4.5).\n", + "2. Il Pagliaccio - An elegant Michelin-starred restaurant offering contemporary Italian cuisine (Rating: 4.8).\n", + "3. Tonnarello - Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar (Rating: 4.7).\n", + "4. Osteria delle Commari - Local home style Roman restaurant near Vatican Museums (Rating: 4.3).\n", + "5. Armando al Pantheon - Traditional Roman cuisine since 1961 near the Pantheon (Rating: 4.8).\n", + "6. Salumeria Roscioli Ristorante - Known for pasta alla gricia, amatriciana, and an impressive wine cellar (Rating: 4.5).\n", + "7. L'Arcangelo - Known for some of the best supplì in the city and Thursday gnocchi (Rating: 4.8).\n", "\n", "Attractions in Rome:\n", "1. Colosseum - An ancient amphitheater known for gladiatorial contests and public spectacles.\n", "2. Vatican Museums - A complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", "3. Trevi Fountain - A Baroque fountain known for its stunning sculptures and tradition of tossing coins.\n", - "4. Basilica di Santa Maria Maggiore - A major basilica in Rome, known for its rich history and impressive architecture.\n", + "4. Basilica di Santa Maria Maggiore - A major basilica known for its rich history and impressive architecture.\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -724,57 +724,60 @@ "\n", "Great! Here's a suggested itinerary for your 2-day trip to Rome:\n", "\n", - "### Day 1\n", - "- **Morning Attraction**\n", - " - **Type**: Attraction\n", - " - **Location**: Colosseum\n", - " - **City**: Rome\n", - " - **Description**: Explore the iconic ancient amphitheater known for gladiatorial contests and public spectacles.\n", - "\n", - "- **Lunch**\n", - " - **Type**: Restaurant\n", - " - **Location**: Trattoria da Enzo\n", - " - **City**: Rome\n", - " - **Description**: Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\n", - "\n", - "- **Afternoon Attraction**\n", - " - **Type**: Attraction\n", - " - **Location**: Trevi Fountain\n", - " - **City**: Rome\n", - " - **Description**: Visit the stunning Baroque fountain and participate in the tradition of tossing coins.\n", - "\n", - "- **Dinner**\n", - " - **Type**: Restaurant\n", - " - **Location**: Armando al Pantheon\n", - " - **City**: Rome\n", - " - **Description**: Savor traditional Roman cuisine at a historic restaurant near the Pantheon.\n", - "\n", - "### Day 2\n", - "- **Morning Attraction**\n", - " - **Type**: Attraction\n", - " - **Location**: Vatican Museums\n", - " - **City**: Rome\n", - " - **Description**: Discover a complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", - "\n", - "- **Lunch**\n", - " - **Type**: Restaurant\n", - " - **Location**: Tonnarello\n", - " - **City**: Rome\n", - " - **Description**: Enjoy casual dining with pasta, meatballs, and other simple Roman dishes.\n", - "\n", - "- **Afternoon Attraction**\n", - " - **Type**: Attraction\n", - " - **Location**: Basilica di Santa Maria Maggiore\n", - " - **City**: Rome\n", - " - **Description**: Visit a major basilica known for its rich history and impressive architecture.\n", - "\n", - "- **Dinner**\n", - " - **Type**: Restaurant\n", - " - **Location**: Il Pagliaccio\n", - " - **City**: Rome\n", - " - **Description**: Experience elegant contemporary Italian cuisine at a Michelin-starred restaurant.\n", - "\n", - "Does this itinerary meet your expectations, or is there anything you'd like to change?\n", + "### Day 1:\n", + "\n", + "- **Morning Attraction:**\n", + " - **Type:** Attraction\n", + " - **Location:** Colosseum\n", + " - **City:** Rome\n", + " - **Description:** Explore the ancient amphitheater known for gladiatorial contests and public spectacles.\n", + "\n", + "- **Lunch:**\n", + " - **Type:** Restaurant\n", + " - **Location:** Trattoria da Enzo\n", + " - **City:** Rome\n", + " - **Description:** Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\n", + "\n", + "- **Afternoon Attraction:**\n", + " - **Type:** Attraction\n", + " - **Location:** Vatican Museums\n", + " - **City:** Rome\n", + " - **Description:** Visit a complex of museums and galleries showcasing works of art collected by Popes over centuries.\n", + "\n", + "- **Dinner:**\n", + " - **Type:** Restaurant\n", + " - **Location:** Armando al Pantheon\n", + " - **City:** Rome\n", + " - **Description:** Experience traditional Roman cuisine since 1961, located near the Pantheon.\n", + "\n", + "\n", + "### Day 2:\n", + "\n", + "- **Morning Attraction:**\n", + " - **Type:** Attraction\n", + " - **Location:** Trevi Fountain\n", + " - **City:** Rome\n", + " - **Description:** Marvel at the stunning sculptures of the Baroque fountain and join the tradition of tossing coins.\n", + "\n", + "- **Lunch:**\n", + " - **Type:** Restaurant\n", + " - **Location:** Tonnarello\n", + " - **City:** Rome\n", + " - **Description:** Relish in simple Roman dishes such as pasta and meatballs in a casual setting with patio seating.\n", + "\n", + "- **Afternoon Attraction:**\n", + " - **Type:** Attraction\n", + " - **Location:** Basilica di Santa Maria Maggiore\n", + " - **City:** Rome\n", + " - **Description:** Visit a major basilica known for its rich history and impressive architecture.\n", + "\n", + "- **Dinner:**\n", + " - **Type:** Restaurant\n", + " - **Location:** L'Arcangelo\n", + " - **City:** Rome\n", + " - **Description:** Savor some of the best supplì in the city and enjoy traditional gnocchi on Thursdays.\n", + "\n", + "Let me know if you are happy with this itinerary or if there are any changes you would like to make!\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -782,7 +785,7 @@ "\u001b[0m\n", "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", "\n", - "I don't feel like eating at Il Pagliaccio.\n", + "I don't feel like eating at L'Arcangelo, please change that for another option.\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -790,17 +793,35 @@ "\u001b[0m\n", "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", "\n", - "No problem! Let's choose a different restaurant for dinner on Day 2.\n", + "Certainly! Here's the updated itinerary for Day 2:\n", + "\n", + "### Day 2:\n", + "\n", + "- **Morning Attraction:**\n", + " - **Type:** Attraction\n", + " - **Location:** Trevi Fountain\n", + " - **City:** Rome\n", + " - **Description:** Marvel at the stunning sculptures of the Baroque fountain and join the tradition of tossing coins.\n", + "\n", + "- **Lunch:**\n", + " - **Type:** Restaurant\n", + " - **Location:** Tonnarello\n", + " - **City:** Rome\n", + " - **Description:** Relish in simple Roman dishes such as pasta and meatballs in a casual setting with patio seating.\n", "\n", - "### Updated Itinerary for Day 2\n", + "- **Afternoon Attraction:**\n", + " - **Type:** Attraction\n", + " - **Location:** Basilica di Santa Maria Maggiore\n", + " - **City:** Rome\n", + " - **Description:** Visit a major basilica known for its rich history and impressive architecture.\n", "\n", - "- **Dinner**\n", - " - **Type**: Restaurant\n", - " - **Location**: Salumeria Roscioli Ristorante\n", - " - **City**: Rome\n", - " - **Description**: Enjoy a selection of traditional pasta dishes like Pasta alla gricia and amatriciana, paired with an impressive wine cellar.\n", + "- **Dinner:**\n", + " - **Type:** Restaurant\n", + " - **Location:** Il Pagliaccio\n", + " - **City:** Rome\n", + " - **Description:** Indulge in elegant, contemporary Italian cuisine at a Michelin-starred restaurant.\n", "\n", - "Is this revised itinerary more to your liking?\n", + "Let me know if this itinerary meets your preferences!\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -808,7 +829,7 @@ "\u001b[0m\n", "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", "\n", - "Yes, thanks\n", + "Can you research and show me all the available restaurant options.\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -816,10 +837,60 @@ "\u001b[0m\n", "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", "\n", - "\u001b[32m***** Suggested tool call (call_C93kDFyT4DiYuUYVzcWtum84): mark_itinerary_as_complete *****\u001b[0m\n", + "Here are the available restaurant options for your trip to Rome:\n", + "\n", + "1. **Trattoria da Enzo**\n", + " - **Description:** A cozy trattoria known for its traditional Roman dishes and welcoming atmosphere.\n", + " - **Rating:** 4.5\n", + "\n", + "2. **Il Pagliaccio**\n", + " - **Description:** An elegant Michelin-starred restaurant offering contemporary Italian cuisine.\n", + " - **Rating:** 4.8\n", + "\n", + "3. **Tonnarello**\n", + " - **Description:** Casual stop for pasta, meatballs & other simple Roman dishes, plus patio seating & acoustic guitar.\n", + " - **Rating:** 4.7\n", + "\n", + "4. **Osteria delle Commari**\n", + " - **Description:** Local home style Roman restaurant near Vatican Museums.\n", + " - **Rating:** 4.3\n", + "\n", + "5. **Armando al Pantheon**\n", + " - **Description:** Traditional Roman cuisine since 1961 near the Pantheon.\n", + " - **Rating:** 4.8\n", + "\n", + "6. **Salumeria Roscioli Ristorante**\n", + " - **Description:** Known for pasta alla gricia, amatriciana, and an impressive wine cellar.\n", + " - **Rating:** 4.5\n", + "\n", + "7. **L'Arcangelo**\n", + " - **Description:** Known for some of the best supplì in the city and Thursday gnocchi.\n", + " - **Rating:** 4.8\n", + "\n", + "Please let me know which restaurants you'd like to include in your itinerary or if there are any changes you'd like to make!\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: customer\n", + "\u001b[0m\n", + "\u001b[33mcustomer\u001b[0m (to chat_manager):\n", + "\n", + "Tonnarello's please.\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: planner_agent\n", + "\u001b[0m\n", + "\u001b[33mplanner_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_sROJ1YfU63SDCRfUbRuGqjVa): mark_itinerary_as_complete *****\u001b[0m\n", "Arguments: \n", - "{\"final_itinerary\":\"### Day 1\\n- **Morning Attraction**\\n - **Type**: Attraction\\n - **Location**: Colosseum\\n - **City**: Rome\\n - **Description**: Explore the iconic ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch**\\n - **Type**: Restaurant\\n - **Location**: Trattoria da Enzo\\n - **City**: Rome\\n - **Description**: Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\\n\\n- **Afternoon Attraction**\\n - **Type**: Attraction\\n - **Location**: Trevi Fountain\\n - **City**: Rome\\n - **Description**: Visit the stunning Baroque fountain and participate in the tradition of tossing coins.\\n\\n- **Dinner**\\n - **Type**: Restaurant\\n - **Location**: Armando al Pantheon\\n - **City**: Rome\\n - **Description**: Savor traditional Roman cuisine at a historic restaurant near the Pantheon.\\n\\n### Day 2\\n- **Morning Attraction**\\n - **Type**: Attraction\\n - **Location**: Vatican Museums\\n - **City**: Rome\\n - **Description**: Discover a complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Lunch**\\n - **Type**: Restaurant\\n - **Location**: Tonnarello\\n - **City**: Rome\\n - **Description**: Enjoy casual dining with pasta, meatballs, and other simple Roman dishes.\\n\\n- **Afternoon Attraction**\\n - **Type**: Attraction\\n - **Location**: Basilica di Santa Maria Maggiore\\n - **City**: Rome\\n - **Description**: Visit a major basilica known for its rich history and impressive architecture.\\n\\n- **Dinner**\\n - **Type**: Restaurant\\n - **Location**: Salumeria Roscioli Ristorante\\n - **City**: Rome\\n - **Description**: Enjoy a selection of traditional pasta dishes like Pasta alla gricia and amatriciana, paired with an impressive wine cellar.\"}\n", + "{\"final_itinerary\": \"### Day 1:\\n\\n- **Morning Attraction:**\\n - **Type:** Attraction\\n - **Location:** Colosseum\\n - **City:** Rome\\n - **Description:** Explore the ancient amphitheater known for gladiatorial contests and public spectacles.\\n\\n- **Lunch:**\\n - **Type:** Restaurant\\n - **Location:** Trattoria da Enzo\\n - **City:** Rome\\n - **Description:** Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\\n\\n- **Afternoon Attraction:**\\n - **Type:** Attraction\\n - **Location:** Vatican Museums\\n - **City:** Rome\\n - **Description:** Visit a complex of museums and galleries showcasing works of art collected by Popes over centuries.\\n\\n- **Dinner:**\\n - **Type:** Restaurant\\n - **Location:** Armando al Pantheon\\n - **City:** Rome\\n - **Description:** Experience traditional Roman cuisine since 1961, located near the Pantheon.\\n\\n\\n### Day 2:\\n\\n- **Morning Attraction:**\\n - **Type:** Attraction\\n - **Location:** Trevi Fountain\\n - **City:** Rome\\n - **Description:** Marvel at the stunning sculptures of the Baroque fountain and join the tradition of tossing coins.\\n\\n- **Lunch:**\\n - **Type:** Restaurant\\n - **Location:** Tonnarello\\n - **City:** Rome\\n - **Description:** Relish in simple Roman dishes such as pasta and meatballs in a casual setting with patio seating.\\n\\n- **Afternoon Attraction:**\\n - **Type:** Attraction\\n - **Location:** Basilica di Santa Maria Maggiore\\n - **City:** Rome\\n - **Description:** Visit a major basilica known for its rich history and impressive architecture.\\n\\n- **Dinner:**\\n - **Type:** Restaurant\\n - **Location:** Tonnarello\\n - **City:** Rome\\n - **Description:** Return to Tonnarello for a delightful dining experience with a variety of Roman specialties.\"}\n", "\u001b[32m*******************************************************************************************\u001b[0m\n", + "\u001b[32m***** Suggested tool call (call_NBw71N4pS66h8VLlgu5nvveN): transfer_to_structured_output_agent *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m****************************************************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[32m\n", @@ -827,22 +898,60 @@ "\u001b[0m\n", "\u001b[35m\n", ">>>>>>>> EXECUTING FUNCTION mark_itinerary_as_complete...\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION transfer_to_structured_output_agent...\u001b[0m\n", "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", - "\u001b[32m***** Response from calling tool (call_C93kDFyT4DiYuUYVzcWtum84) *****\u001b[0m\n", + "\u001b[32m***** Response from calling tool (call_sROJ1YfU63SDCRfUbRuGqjVa) *****\u001b[0m\n", "Itinerary recorded and confirmed.\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", + "\u001b[32m***** Response from calling tool (call_NBw71N4pS66h8VLlgu5nvveN) *****\u001b[0m\n", + "SwarmAgent --> structured_output_agent\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", "\u001b[32m\n", "Next speaker: structured_output_agent\n", "\u001b[0m\n", "\u001b[33mstructured_output_agent\u001b[0m (to chat_manager):\n", "\n", - "{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"Explore the iconic ancient amphitheater known for gladiatorial contests and public spectacles.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\"},{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"Visit the stunning Baroque fountain and participate in the tradition of tossing coins.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Savor traditional Roman cuisine at a historic restaurant near the Pantheon.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"Discover a complex of museums and galleries showcasing works of art collected by Popes over centuries.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Enjoy casual dining with pasta, meatballs, and other simple Roman dishes.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"Visit a major basilica known for its rich history and impressive architecture.\"},{\"type\":\"Restaurant\",\"location\":\"Salumeria Roscioli Ristorante\",\"city\":\"Rome\",\"description\":\"Enjoy a selection of traditional pasta dishes like Pasta alla gricia and amatriciana, paired with an impressive wine cellar.\"}]}]}\n", - "\u001b[32m***** Suggested tool call (call_j2q6rADCfMqK4FfIjMA91YR4): create_structured_itinerary *****\u001b[0m\n", + "{\"days\":[{\"events\":[{\"type\":\"Attraction\",\"location\":\"Colosseum\",\"city\":\"Rome\",\"description\":\"Explore the ancient amphitheater known for gladiatorial contests and public spectacles.\"},{\"type\":\"Restaurant\",\"location\":\"Trattoria da Enzo\",\"city\":\"Rome\",\"description\":\"Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\"},{\"type\":\"Attraction\",\"location\":\"Vatican Museums\",\"city\":\"Rome\",\"description\":\"Visit a complex of museums and galleries showcasing works of art collected by Popes over centuries.\"},{\"type\":\"Restaurant\",\"location\":\"Armando al Pantheon\",\"city\":\"Rome\",\"description\":\"Experience traditional Roman cuisine since 1961, located near the Pantheon.\"}]},{\"events\":[{\"type\":\"Attraction\",\"location\":\"Trevi Fountain\",\"city\":\"Rome\",\"description\":\"Marvel at the stunning sculptures of the Baroque fountain and join the tradition of tossing coins.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Relish in simple Roman dishes such as pasta and meatballs in a casual setting with patio seating.\"},{\"type\":\"Attraction\",\"location\":\"Basilica di Santa Maria Maggiore\",\"city\":\"Rome\",\"description\":\"Visit a major basilica known for its rich history and impressive architecture.\"},{\"type\":\"Restaurant\",\"location\":\"Tonnarello\",\"city\":\"Rome\",\"description\":\"Return to Tonnarello for a delightful dining experience with a variety of Roman specialties.\"}]}]}\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: route_timing_agent\n", + "\u001b[0m\n", + "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", + "\n", + "None\n", + "\u001b[32m***** Suggested tool call (call_6nnUKnD3VveszMT8OvkqUTCC): update_itinerary_with_travel_times *****\u001b[0m\n", "Arguments: \n", - "{\"structured_itinerary\":\"{\\\"days\\\":[{\\\"events\\\":[{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Colosseum\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Explore the iconic ancient amphitheater known for gladiatorial contests and public spectacles.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Trattoria da Enzo\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\\\"},{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Trevi Fountain\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Visit the stunning Baroque fountain and participate in the tradition of tossing coins.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Armando al Pantheon\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Savor traditional Roman cuisine at a historic restaurant near the Pantheon.\\\"}]},{\\\"events\\\":[{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Vatican Museums\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Discover a complex of museums and galleries showcasing works of art collected by Popes over centuries.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Tonnarello\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Enjoy casual dining with pasta, meatballs, and other simple Roman dishes.\\\"},{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Basilica di Santa Maria Maggiore\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Visit a major basilica known for its rich history and impressive architecture.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Salumeria Roscioli Ristorante\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Enjoy a selection of traditional pasta dishes like Pasta alla gricia and amatriciana, paired with an impressive wine cellar.\\\"}]}]}\"}\n", + "{}\n", + "\u001b[32m***************************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION update_itinerary_with_travel_times...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_6nnUKnD3VveszMT8OvkqUTCC) *****\u001b[0m\n", + "Structured itinerary not found, please create the structured output, structured_output_agent.\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: structured_output_agent\n", + "\u001b[0m\n", + "\u001b[33mstructured_output_agent\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_uTWKi1KdcsaFK9RxAeFUIWbU): create_structured_itinerary *****\u001b[0m\n", + "Arguments: \n", + "{\"structured_itinerary\":\"{\\\"days\\\":[{\\\"events\\\":[{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Colosseum\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Explore the ancient amphitheater known for gladiatorial contests and public spectacles.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Trattoria da Enzo\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Enjoy traditional Roman dishes in a cozy and welcoming atmosphere.\\\"},{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Vatican Museums\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Visit a complex of museums and galleries showcasing works of art collected by Popes over centuries.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Armando al Pantheon\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Experience traditional Roman cuisine since 1961, located near the Pantheon.\\\"}]},{\\\"events\\\":[{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Trevi Fountain\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Marvel at the stunning sculptures of the Baroque fountain and join the tradition of tossing coins.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Tonnarello\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Relish in simple Roman dishes such as pasta and meatballs in a casual setting with patio seating.\\\"},{\\\"type\\\":\\\"Attraction\\\",\\\"location\\\":\\\"Basilica di Santa Maria Maggiore\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Visit a major basilica known for its rich history and impressive architecture.\\\"},{\\\"type\\\":\\\"Restaurant\\\",\\\"location\\\":\\\"Tonnarello\\\",\\\"city\\\":\\\"Rome\\\",\\\"description\\\":\\\"Return to Tonnarello for a delightful dining experience with a variety of Roman specialties.\\\"}]}]}\"}\n", "\u001b[32m********************************************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", @@ -853,7 +962,7 @@ ">>>>>>>> EXECUTING FUNCTION create_structured_itinerary...\u001b[0m\n", "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", "\n", - "\u001b[32m***** Response from calling tool (call_j2q6rADCfMqK4FfIjMA91YR4) *****\u001b[0m\n", + "\u001b[32m***** Response from calling tool (call_uTWKi1KdcsaFK9RxAeFUIWbU) *****\u001b[0m\n", "Structured itinerary stored.\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", @@ -863,7 +972,30 @@ "\u001b[0m\n", "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", "\n", - "Your itinerary is ready! Enjoy your trip to Rome!\n", + "\u001b[32m***** Suggested tool call (call_7alJoHYs74wsPIz4WhMrj7Zu): update_itinerary_with_travel_times *****\u001b[0m\n", + "Arguments: \n", + "{}\n", + "\u001b[32m***************************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: Tool_Execution\n", + "\u001b[0m\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION update_itinerary_with_travel_times...\u001b[0m\n", + "\u001b[33mTool_Execution\u001b[0m (to chat_manager):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_7alJoHYs74wsPIz4WhMrj7Zu) *****\u001b[0m\n", + "Timed itinerary added to context with travel times\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[32m\n", + "Next speaker: route_timing_agent\n", + "\u001b[0m\n", + "\u001b[33mroute_timing_agent\u001b[0m (to chat_manager):\n", + "\n", + "Your itinerary is ready!\n", "\n", "--------------------------------------------------------------------------------\n" ] @@ -899,7 +1031,82 @@ "name": "stdout", "output_type": "stream", "text": [ - "No itinerary available to print.\n" + " █ █ \n", + " █ █ \n", + " █ █████ █ \n", + " ██ ██ \n", + " █ █ \n", + " █ ███████ █ \n", + " █ ██ ███ ██ █ \n", + " █████████ \n", + " \n", + " ██ ███ ███ \n", + " █ █ █ █ \n", + " ████ █ ██ ██ \n", + " █ █ █ █ █ \n", + " █ █ ██ ████ \n", + " \n", + " Itinerary for Rome \n", + "================================================================================\n", + " \n", + "Day 1 \n", + "--------------------------------------------------------------------------------\n", + "\n", + " 🏛️ Colosseum\n", + " Explore the ancient amphitheater known for gladiatorial contests and \n", + " public spectacles. \n", + "\n", + " 🚶 walking from Colosseum to Trattoria da Enzo\n", + " 24 mins, (1.8 km)\n", + "\n", + " 🍽️ Trattoria da Enzo\n", + " Enjoy traditional Roman dishes in a cozy and welcoming atmosphere. \n", + "\n", + " 🚶 walking from Trattoria da Enzo to Vatican Museums\n", + " 50 mins, (3.5 km)\n", + "\n", + " 🏛️ Vatican Museums\n", + " Visit a complex of museums and galleries showcasing works of art \n", + " collected by Popes over centuries. \n", + "\n", + " 🚶 walking from Vatican Museums to Armando al Pantheon\n", + " 36 mins, (2.6 km)\n", + "\n", + " 🍽️ Armando al Pantheon\n", + " Experience traditional Roman cuisine since 1961, located near the \n", + " Pantheon. \n", + "\n", + "--------------------------------------------------------------------------------\n", + " \n", + "Day 2 \n", + "--------------------------------------------------------------------------------\n", + "\n", + " 🏛️ Trevi Fountain\n", + " Marvel at the stunning sculptures of the Baroque fountain and join the \n", + " tradition of tossing coins. \n", + "\n", + " 🚶 walking from Trevi Fountain to Tonnarello\n", + " 31 mins, (2.2 km)\n", + "\n", + " 🍽️ Tonnarello\n", + " Relish in simple Roman dishes such as pasta and meatballs in a casual \n", + " setting with patio seating. \n", + "\n", + " 🚶 walking from Tonnarello to Basilica di Santa Maria Maggiore\n", + " 46 mins, (3.2 km)\n", + "\n", + " 🏛️ Basilica di Santa Maria Maggiore\n", + " Visit a major basilica known for its rich history and impressive \n", + " architecture. \n", + "\n", + " 🚶 walking from Basilica di Santa Maria Maggiore to Tonnarello\n", + " 44 mins, (3.2 km)\n", + "\n", + " 🍽️ Tonnarello\n", + " Return to Tonnarello for a delightful dining experience with a variety \n", + " of Roman specialties. \n", + "\n", + "--------------------------------------------------------------------------------\n" ] } ], From abcfaa4127dfed2692afb82788068af2fece0dac Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Thu, 5 Dec 2024 22:26:44 +0000 Subject: [PATCH 20/20] Added metadata to notebook Signed-off-by: Mark Sze --- notebook/agentchat_swarm_graphrag_trip_planner.ipynb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb index 5fb0212ef3..13a2763028 100644 --- a/notebook/agentchat_swarm_graphrag_trip_planner.ipynb +++ b/notebook/agentchat_swarm_graphrag_trip_planner.ipynb @@ -1152,7 +1152,15 @@ } ], "metadata": { - "kernelspec": { + "front_matter": { + "description": "FalkorDB GraphRAG utilises a knowledge graph and can be added as a capability to agents. Together with a swarm orchestration of agents is highly effective at providing a RAG capability.", + "tags": [ + "RAG", + "tool/function", + "swarm" + ] + }, + "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3"