๐ซ CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
docs: Add colab notebooks (#833)
Wendong-Fandb019bbbaf2c
diff --git a/docs/README.md b/docs/README.mdindex 1cdad075e..4c506c9b5 100644--- a/docs/README.md+++ b/docs/README.md@@ -13,12 +13,13 @@ To build the documentation:1. [Install CAMEL](https://github.com/camel-ai/camel/blob/master/README.md) from source.-2. Install Sphinx, Sphinx theme, Sphinx autobuild and `myst_parser` by running the following command in your terminal or command prompt:+2. Install required dependencies running the following command in your terminal or command prompt:```bashpip install sphinxpip install sphinx_book_themepip install sphinx-autobuildpip install myst_parser+pip install nbsphinx```3. Build the document and launch the HTML documentation.diff --git a/docs/conf.py b/docs/conf.pyindex 3538a7883..40ae9b29a 100644--- a/docs/conf.py+++ b/docs/conf.py@@ -44,6 +44,7 @@ extensions = ['sphinx.ext.viewcode','sphinx.ext.napoleon','myst_parser',+ 'nbsphinx',]templates_path = ['_templates']diff --git a/docs/cookbooks/agents_message.ipynb b/docs/cookbooks/agents_message.ipynbnew file mode 100644index 000000000..fae9ffb8a--- /dev/null+++ b/docs/cookbooks/agents_message.ipynb@@ -0,0 +1,540 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "w5_pa5kKPzAE"+ },+ "source": [+ "# ๐ซ CAMEL Message Cookbook"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "1tGC1kVjPNX9"+ },+ "source": [+ "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1qyi4bnAbnYink-FKaAlJG9OipyEWXEsT?usp=sharing)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "lSXa_rQQQzBd"+ },+ "source": [+ "## Overview"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "OnmoAw2vQG8I"+ },+ "source": [+ "In this tutorial, we will explore the `BaseMessage` class. The topics covered include:\n",+ "\n",+ "1. Introduction to the `BaseMessage` class.\n",+ "2. Creating a `BaseMessage` instance.\n",+ "3. Understanding the properties of the `BaseMessage` class.\n",+ "4. Using the methods of the `BaseMessage` class.\n",+ "5. Give message to `ChatAgent`"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "l4MP9uUNQ2kr"+ },+ "source": [+ "## Introduction\n",+ "\n"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "aYzY4OM6F3ay"+ },+ "source": [+ "The `BaseMessage` class is the base class for message objects used in the CAMEL chat system. It is designed to provide a consistent structure for the messages in the system and allow for easy conversion between different message types."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "kETDiaP2Rrdb"+ },+ "source": [+ "### Installation"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Cg96MkbcRtQR"+ },+ "source": [+ "Ensure you have CAMEL AI installed in your Python environment:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "collapsed": true,+ "id": "ZVmDAK6MPefC",+ "outputId": "058bba8e-7df6-46df-cae9-78166c560275"+ },+ "outputs": [],+ "source": [+ "pip install camel-ai==0.1.6.8"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "MyTTCe3IR_Lr"+ },+ "source": [+ "### Setting Up API Keys"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "REqzgGL9SEaD"+ },+ "source": [+ "You'll need to set up your API keys for OpenAI."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "PNBFEXc-R-0s",+ "outputId": "eb7ccdb6-fa2f-44e2-e2b9-7128f2c5d47d"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "import os\n",+ "from getpass import getpass\n",+ "\n",+ "# Prompt for the API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "LRojeqp7dP1m"+ },+ "source": [+ "## Creating a `BaseMessage` Instance\n"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "_sJV9GFldTBh"+ },+ "source": [+ "To create a `BaseMessage` instance, you need to provide the following arguments:\n",+ "\n",+ "- `role_name`: The name of the user or assistant role.\n",+ "- `role_type`: The type of role, either `RoleType.ASSISTANT` or `RoleType.USER`.\n",+ "- `meta_dict`: An optional metadata dictionary for the message.\n",+ "- `content`: The content of the message.\n",+ "\n",+ "Here's an example of creating a `BaseMessage` instance:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "pAdDeN7DdUgr"+ },+ "outputs": [],+ "source": [+ "from camel.messages import BaseMessage\n",+ "from camel.types import RoleType\n",+ "\n",+ "message = BaseMessage(\n",+ " role_name=\"test_user\",\n",+ " role_type=RoleType.USER,\n",+ " content=\"test content\",\n",+ " meta_dict={}\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "MBx8Pje9ETAL"+ },+ "source": [+ "Additionally, the BaseMessage class provides class methods to easily create user and assistant agent messages:\n",+ "\n",+ "1. Creating a user agent message:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "pEiFYV-yez5j"+ },+ "outputs": [],+ "source": [+ "from camel.messages import BaseMessage\n",+ "\n",+ "user_message = BaseMessage.make_user_message(\n",+ " role_name=\"user_name\",\n",+ " content=\"test content for user\",\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "PCqjf_fWEdLD"+ },+ "source": [+ "2. Creating an assistant agent message:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "iIWWSfSpEf2n"+ },+ "outputs": [],+ "source": [+ "from camel.messages import BaseMessage\n",+ "\n",+ "assistant_message = BaseMessage.make_assistant_message(\n",+ " role_name=\"assistant_name\",\n",+ " content=\"test content for assistant\",\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "yR5ZYr5yEkLL"+ },+ "source": [+ "## Using the Methods of the `BaseMessage` Class"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Gfc6WNUOEktw"+ },+ "source": [+ "The `BaseMessage` class offers several methods:\n",+ "\n",+ "1. Creating a new instance with updated content:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "P7UjCsb-Emsk",+ "outputId": "f8f858c2-59c8-4d84-ee4b-01cba6c7aeb4"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "True\n"+ ]+ }+ ],+ "source": [+ "new_message = message.create_new_instance(\"new test content\")\n",+ "print(isinstance(new_message, BaseMessage))"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "412MphuYErw_"+ },+ "source": [+ "2. Converting to an `OpenAIMessage` object:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "sS_UKtJGEsPE",+ "outputId": "b6b8a5bb-d964-43a3-ec10-3c4af7a47bca"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "True\n"+ ]+ }+ ],+ "source": [+ "from camel.types import OpenAIBackendRole\n",+ "openai_message = message.to_openai_message(role_at_backend=OpenAIBackendRole.USER)\n",+ "print(openai_message == {\"role\": \"user\", \"content\": \"test content\"})"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "TIpjz3G2E5dy"+ },+ "source": [+ "3. Converting to an `OpenAISystemMessage` object:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "Ur4u2HdIE5ua",+ "outputId": "424f1e49-0531-4589-dbc0-a9291b9a3351"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "True\n"+ ]+ }+ ],+ "source": [+ "openai_system_message = message.to_openai_system_message()\n",+ "print(openai_system_message == {\"role\": \"system\", \"content\": \"test content\"})"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "523x8XqLE8Qo"+ },+ "source": [+ "4. Converting to an `OpenAIUserMessage` object:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "mRCa7soNE9um",+ "outputId": "abf75994-9365-4280-cf52-aaafcf3e46c7"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "True\n"+ ]+ }+ ],+ "source": [+ "openai_user_message = message.to_openai_user_message()\n",+ "print(openai_user_message == {\"role\": \"user\", \"content\": \"test content\"})"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "TURczNJNFA3J"+ },+ "source": [+ "5. Converting to an `OpenAIAssistantMessage` object:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "5FnnmlRuFCtW",+ "outputId": "596f99f9-9771-493d-fb3d-f02cbe71405d"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "True\n"+ ]+ }+ ],+ "source": [+ "openai_assistant_message = message.to_openai_assistant_message()\n",+ "print(openai_assistant_message == {\"role\": \"assistant\", \"content\": \"test content\"})"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "eRhObgkxFFUi"+ },+ "source": [+ "6. Converting to a dictionary:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "OQouave-FG15",+ "outputId": "3bb25dd8-a43d-4a60-ea28-607ea542f572"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "True\n"+ ]+ }+ ],+ "source": [+ "message_dict = message.to_dict()\n",+ "print(message_dict == {\n",+ " \"role_name\": \"test_user\",\n",+ " \"role_type\": \"USER\",\n",+ " \"content\": \"test content\"\n",+ "})"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "seSeG3KAHbLI"+ },+ "source": [+ "These methods allow you to convert a `BaseMessage` instance into different message types depending on your needs."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "kAyagBo0GusE"+ },+ "source": [+ "## Give message to `ChatAgent`"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "nbr7nIKxGz07",+ "outputId": "e6720252-29a5-439a-f52d-448c35fb3a8b"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Hello, CAMEL AI! It's great to connect with a community dedicated to the study of autonomous and communicative agents. Your work in this fascinating field is sure to lead to exciting advancements and innovations. If there's anything specific you'd like to discuss or explore, feel free to share!\n"+ ]+ }+ ],+ "source": [+ "from camel.agents import ChatAgent\n",+ "from camel.messages import BaseMessage\n",+ "\n",+ "# Define system message\n",+ "sys_msg = BaseMessage.make_assistant_message(\n",+ " role_name=\"Assistant\",\n",+ " content=\"You are a helpful assistant.\",\n",+ ")\n",+ "\n",+ "# Set agent\n",+ "camel_agent = ChatAgent(system_message=sys_msg)\n",+ "\n",+ "# Set user message\n",+ "user_msg = BaseMessage.make_user_message(\n",+ " role_name=\"User\",\n",+ " content=\"\"\"Say hi to CAMEL AI, one open-source community dedicated to the\n",+ " study of autonomous and communicative agents.\"\"\",\n",+ ")\n",+ "\n",+ "# Get response information\n",+ "response = camel_agent.step(user_msg)\n",+ "print(response.msgs[0].content)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "HYNA7G06FJRq"+ },+ "source": [+ "In this session, we introduced the `BaseMessage` class and its conversion to different types of messages. These components play essential roles in the CAMEL chat system, facilitating the creation, management, and interpretation of messages with clarity."+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "Python 3",+ "name": "python3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}diff --git a/docs/cookbooks/agents_prompting.ipynb b/docs/cookbooks/agents_prompting.ipynbnew file mode 100644index 000000000..f45138c93--- /dev/null+++ b/docs/cookbooks/agents_prompting.ipynb@@ -0,0 +1,510 @@+{+ "nbformat": 4,+ "nbformat_minor": 0,+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "name": "python3",+ "display_name": "Python 3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "cells": [+ {+ "cell_type": "markdown",+ "source": [+ "# ๐ซ CAMEL Prompting Cookbook\n"+ ],+ "metadata": {+ "id": "SQMBlxsBv1cH"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1VcjPuy2UEYm0xLdriT7OMGt6I2yX9z32?usp=sharing)"+ ],+ "metadata": {+ "id": "XFyl4eJue3Sm"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "## *TLDR*"+ ],+ "metadata": {+ "id": "-nCRZU5sInDK"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "The CAMEL Prompt module offers a powerful way to guide AI models in producing accurate, contextually relevant, and personalized outputs. This cookbook demonstrates how to use various prompt templates, create custom prompts, and leverage different prompt dictionaries for tasks ranging from role-playing to code generation, evaluation, and more. By mastering the Prompt module, you can significantly enhance your AI agents' capabilities and tailor them to specific tasks."+ ],+ "metadata": {+ "id": "AwnfLQvMvtXo"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "### Installation"+ ],+ "metadata": {+ "id": "XuZwbB1IIuUi"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "Ensure you have CAMEL AI installed in your Python environment:"+ ],+ "metadata": {+ "id": "gIJK4Lu5Iwm0"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "!pip install camel-ai==0.1.9"+ ],+ "metadata": {+ "id": "HTKnWg9Xv_y4",+ "collapsed": true+ },+ "execution_count": null,+ "outputs": []+ },+ {+ "cell_type": "markdown",+ "source": [+ "### ๐ Setting Up API Keys"+ ],+ "metadata": {+ "id": "MyTTCe3IR_Lr"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "You'll need to set up your API keys for OpenAI."+ ],+ "metadata": {+ "id": "REqzgGL9SEaD"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "import os\n",+ "from getpass import getpass\n",+ "\n",+ "# Prompt for the API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "PNBFEXc-R-0s",+ "outputId": "d6ec8e40-b5fb-4ebf-c221-e9835b68ff1d"+ },+ "execution_count": 4,+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Getting Started with Prompt Templates\n",+ "CAMEL offers a wide range of pre-defined prompt templates that you can use to quickly create specialized AI agents. Let's start with a basic example using the TaskSpecifyAgent with the AI_SOCIETY task type."+ ],+ "metadata": {+ "id": "GB5JK4Xs2fe6"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.agents import TaskSpecifyAgent\n",+ "from camel.configs import ChatGPTConfig\n",+ "from camel.models import ModelFactory\n",+ "from camel.types import ModelPlatformType, ModelType, TaskType\n",+ "\n",+ "# Set up the model\n",+ "model = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_4O_MINI,\n",+ " model_config_dict=ChatGPTConfig().as_dict(),\n",+ ")\n",+ "\n",+ "# Create a task specify agent\n",+ "task_specify_agent = TaskSpecifyAgent(\n",+ " model=model, task_type=TaskType.AI_SOCIETY\n",+ ")\n",+ "\n",+ "# Run the agent with a task prompt\n",+ "specified_task_prompt = task_specify_agent.run(\n",+ " task_prompt=\"Improving stage presence and performance skills\",\n",+ " meta_dict=dict(\n",+ " assistant_role=\"Musician\", user_role=\"Student\", word_limit=100\n",+ " ),\n",+ ")\n",+ "\n",+ "print(f\"Specified task prompt:\\n{specified_task_prompt}\\n\")"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "754A8R7X2rnP",+ "outputId": "d9cb892c-bdc8-4433-9ae5-3f3ddaf45a47"+ },+ "execution_count": 5,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "Specified task prompt:\n",+ "Design a personalized workshop where the Musician guides the Student through a series of dynamic exercises, including improvisation, audience engagement techniques, and movement choreography. Incorporate video feedback sessions to analyze performance style, culminating in a mini-concert where the Student showcases their enhanced stage presence and performance skills.\n",+ "\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Creating Custom Prompts\n",+ "CAMEL also allows you to create your own custom prompts. Here's an example of how to create and use a custom prompt template:"+ ],+ "metadata": {+ "id": "JlX8L7-H3Csb"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.agents import TaskSpecifyAgent\n",+ "from camel.configs import ChatGPTConfig\n",+ "from camel.models import ModelFactory\n",+ "from camel.prompts import TextPrompt\n",+ "from camel.types import ModelPlatformType, ModelType\n",+ "\n",+ "# Set up the model\n",+ "model = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_4O_MINI,\n",+ " model_config_dict=ChatGPTConfig().as_dict(),\n",+ ")\n",+ "\n",+ "# Create a custom prompt template\n",+ "my_prompt_template = TextPrompt(\n",+ " 'Here is a task: I\\'m a {occupation} and I want to {task}. Help me to make this task more specific.'\n",+ ")\n",+ "\n",+ "# Create a task specify agent with the custom prompt\n",+ "task_specify_agent = TaskSpecifyAgent(\n",+ " model=model, task_specify_prompt=my_prompt_template\n",+ ")\n",+ "\n",+ "# Run the agent with a task prompt\n",+ "response = task_specify_agent.run(\n",+ " task_prompt=\"get promotion\",\n",+ " meta_dict=dict(occupation=\"Software Engineer\"),\n",+ ")\n",+ "\n",+ "print(response)"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "uJJQD0LV3DSB",+ "outputId": "ea69e6b1-0e0c-49c8-fb4e-7c7470258bd2"+ },+ "execution_count": 6,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "To make your task of getting a promotion more specific, consider breaking it down into actionable steps and defining clear goals. Hereโs a refined version of your task:\n",+ "\n",+ "**Task: Prepare for Promotion to Senior Software Engineer**\n",+ "\n",+ "1. **Understand Promotion Criteria:**\n",+ " - Review the companyโs promotion guidelines and criteria for a Senior Software Engineer.\n",+ " - Identify specific skills, experiences, and contributions required for the promotion.\n",+ "\n",+ "2. **Set Clear Goals:**\n",+ " - Define a timeline for when you want to achieve the promotion (e.g., within the next 6-12 months).\n",+ " - List specific projects or responsibilities you need to take on to demonstrate your readiness.\n",+ "\n",+ "3. **Skill Development:**\n",+ " - Identify key technical skills or certifications needed for the Senior role (e.g., advanced algorithms, system design, leadership).\n",+ " - Create a learning plan to acquire these skills through online courses, workshops, or mentorship.\n",+ "\n",+ "4. **Increase Visibility:**\n",+ " - Volunteer for high-impact projects or cross-functional teams to showcase your skills.\n",+ " - Present your work and contributions in team meetings or company-wide forums.\n",+ "\n",+ "5. **Seek Feedback:**\n",+ " - Schedule regular check-ins with your manager to discuss your progress and areas for improvement.\n",+ " - Ask for constructive feedback from peers and mentors to identify blind spots.\n",+ "\n",+ "6. **Build Relationships:**\n",+ " - Network with senior engineers and leaders in your organization to gain insights and advice.\n",+ " - Participate in team-building activities or company events to strengthen relationships.\n",+ "\n",+ "7. **Document Achievements:**\n",+ " - Keep a record of your contributions, projects, and any positive feedback received.\n",+ " - Prepare a portfolio or presentation to showcase your accomplishments when discussing your promotion.\n",+ "\n",+ "8. **Prepare for the Promotion Discussion:**\n",+ " - Schedule a formal meeting with your manager to discuss your promotion.\n",+ " - Be ready to articulate your achievements, contributions, and readiness for the Senior role.\n",+ "\n",+ "By following these specific steps, you can create a clear roadmap to achieve your goal of promotion.\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Advanced Prompt Usage\n",+ "CAMEL provides various prompt dictionaries for different purposes. Let's explore some advanced uses of these prompt templates:"+ ],+ "metadata": {+ "id": "l30b1iv53a-C"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "### 1. Code Generation with CodePromptTemplateDict"+ ],+ "metadata": {+ "id": "cR_mIHA53dWy"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.prompts import CodePromptTemplateDict\n",+ "\n",+ "# Generate programming languages\n",+ "languages_prompt = CodePromptTemplateDict.GENERATE_LANGUAGES.format(num_languages=5)\n",+ "print(f\"Languages prompt:\\n{languages_prompt}\\n\")\n",+ "\n",+ "# Generate coding tasks\n",+ "tasks_prompt = CodePromptTemplateDict.GENERATE_TASKS.format(num_tasks=3)\n",+ "print(f\"Tasks prompt:\\n{tasks_prompt}\\n\")\n",+ "\n",+ "# Create an AI coding assistant prompt\n",+ "assistant_prompt = CodePromptTemplateDict.ASSISTANT_PROMPT.format(\n",+ " assistant_role=\"Python Expert\",\n",+ " task_description=\"Implement a binary search algorithm\",\n",+ ")\n",+ "print(f\"Assistant prompt:\\n{assistant_prompt}\\n\")"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "xdQdjQzy3f9u",+ "outputId": "b968f52d-f3d6-45d7-ef01-279e54dbee7a"+ },+ "execution_count": 7,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "Languages prompt:\n",+ "List the 5 most commonly used computer programming languages.\n",+ "Be concise. No explanation required.\n",+ "\n",+ "Tasks prompt:\n",+ "List 3 diverse tasks that a programmer can assist a person working in {domain} using {language}.\n",+ "Be concise. Be creative.\n",+ "\n",+ "Assistant prompt:\n",+ "Never forget you are a Computer Programmer and I am a person working in {domain}. Never flip roles! Never instruct me!\n",+ "We share a common interest in collaborating to successfully complete a task.\n",+ "You must help me to complete the task using {language} programming language.\n",+ "Here is the task: {task}. Never forget our task!\n",+ "I must instruct you based on your expertise and my needs to complete the task.\n",+ "\n",+ "I must give you one instruction at a time.\n",+ "You must write a specific solution that appropriately solves the requested instruction and explain your solutions.\n",+ "You must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\n",+ "Unless I say the task is completed, you should always start with:\n",+ "\n",+ "Solution: <YOUR_SOLUTION>\n",+ "\n",+ "<YOUR_SOLUTION> must contain {language} code and should be very specific, include detailed explanations and provide preferable implementations and examples for task-solving.\n",+ "Always end <YOUR_SOLUTION> with: Next request.\n",+ "\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "### 2. Evaluation with EvaluationPromptTemplateDict"+ ],+ "metadata": {+ "id": "FV6Jpu8f3m-Z"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.prompts import EvaluationPromptTemplateDict\n",+ "\n",+ "# Generate evaluation questions\n",+ "questions_prompt = EvaluationPromptTemplateDict.GENERATE_QUESTIONS.format(\n",+ " num_questions=5,\n",+ " field=\"Machine Learning\",\n",+ " examples=\"1. What is the difference between supervised and unsupervised learning?\\n2. Explain the concept of overfitting.\",\n",+ ")\n",+ "print(f\"Evaluation questions prompt:\\n{questions_prompt}\\n\")"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "f-Q-gZAi3nbR",+ "outputId": "5523f9e0-f5a2-4b35-fff0-2da576bd74ac"+ },+ "execution_count": 8,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "Evaluation questions prompt:\n",+ "Generate 5 {category} diverse questions.\n",+ "Here are some example questions:\n",+ "1. What is the difference between supervised and unsupervised learning?\n",+ "2. Explain the concept of overfitting.\n",+ "\n",+ "Now generate 5 questions of your own. Be creative\n",+ "\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "### 3. Object Recognition with ObjectRecognitionPromptTemplateDict"+ ],+ "metadata": {+ "id": "sq3fTArB3qEx"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.prompts import ObjectRecognitionPromptTemplateDict\n",+ "\n",+ "# Create an object recognition assistant prompt\n",+ "recognition_prompt = ObjectRecognitionPromptTemplateDict.ASSISTANT_PROMPT\n",+ "print(f\"Object recognition prompt:\\n{recognition_prompt}\\n\")"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "5XTQuohX3sOk",+ "outputId": "90d89c59-9c8b-42aa-e68a-5cab4f9865ea"+ },+ "execution_count": 9,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "Object recognition prompt:\n",+ "You have been assigned an object recognition task.\n",+ "Your mission is to list all detected objects in following image.\n",+ "Your output should always be a list of strings starting with `1.`, `2.` etc.\n",+ "Do not explain yourself or output anything else.\n",+ "\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "### 4. Translation with TranslationPromptTemplateDict"+ ],+ "metadata": {+ "id": "OxgxXQBt3uRt"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.prompts import TranslationPromptTemplateDict\n",+ "\n",+ "# Create a translation assistant prompt\n",+ "translation_prompt = TranslationPromptTemplateDict.ASSISTANT_PROMPT.format(target_language=\"Spanish\")\n",+ "print(f\"Translation prompt:\\n{translation_prompt}\\n\")"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "w1k00XLu3xIk",+ "outputId": "df731273-f4fc-4eee-96fa-67bcc6d9cf45"+ },+ "execution_count": 10,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "Translation prompt:\n",+ "You are an expert English to {language} translator.\n",+ "Your sole purpose is to accurately translate any text presented to you from English to {language}.\n",+ "Please provide the {language} translation for the given text.\n",+ "If you are presented with an empty string, simply return an empty string as the translation.\n",+ "Only text in between ```TEXT``` should not be translated.\n",+ "Do not provide any explanation. Just provide a translation.\n",+ "\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Conclusion\n",+ "The CAMEL Prompt module provides a powerful and flexible way to guide AI models in producing desired outputs. By using pre-defined prompt templates, creating custom prompts, and leveraging different prompt dictionaries, you can create highly specialized AI agents tailored to your specific needs."+ ],+ "metadata": {+ "id": "vGTRxblx3zHR"+ }+ }+ ]+}\ No newline at end of filediff --git a/docs/cookbooks/agents_society.ipynb b/docs/cookbooks/agents_society.ipynbnew file mode 100644index 000000000..c309dddd2--- /dev/null+++ b/docs/cookbooks/agents_society.ipynb@@ -0,0 +1,1191 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "GsSUEbff5MPM"+ },+ "source": [+ "# ๐ซ CAMEL Society Cookbook"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "MusY9BwU5MPO"+ },+ "source": [+ "You can also check this cookbook in colab [here](https://drive.google.com/file/d/17_m8BPMSh4f9mmdYP2PLQCU639aGFSBj/view?usp=sharing)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "NBN3kMBO5MPP"+ },+ "source": [+ "### 1. Concept"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "B9pzjA4s5MPP"+ },+ "source": [+ "The society module is one of the core modules of CAMEL. By simulating the information exchange process, this module studies the social behaviors among agents.\n",+ "\n",+ "Currently, the society module aims to enable agents to collaborate autonomously toward completing tasks while keeping consistent with human intentions and requiring minimal human intervention. It includes two frameworks: `RolePlaying` and `BabyAGI`, which are used to run the interaction behaviors of agents to achieve objectives.\n",+ "\n",+ "Taking `RolePlaying` as an example, this framework was designed in an instruction-following manner. These roles independently undertake the responsibilities of executing and planning tasks, respectively. The dialogue is continuously advanced through a turn-taking mechanism, thereby collaborating to complete tasks. The main concepts include:\n",+ "\n",+ "- Task: a task can be as simple as an idea, initialized by an inception prompt.\n",+ "\n",+ "- AI User: the agent who is expected to provide instructions.\n",+ "\n",+ "- AI Assistant: the agent who is expected to respond with solutions that fulfill the instructions."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "-RVZ17qm5MPQ"+ },+ "source": [+ "### 2. Types"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "WA1soX8z5MPQ"+ },+ "source": [+ "#### 2.1 `RolePlaying`"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "ob1dEaMR5MPR"+ },+ "source": [+ "`RolePlaying` is a unique cooperative agent framework of CAMEL. Through this framework, agents in CAMEL overcome numerous challenges, such as *role flipping*, *assistant repeats instructions*, *flake replies*, *infinite loop of messages*, and *conversation termination conditions.*\n",+ "\n",+ "When using `RolePlaying` framework in CAMEL, predefined prompts are used to create unique initial settings for different agents. For example, if the user wants to initialize an assistant agent, the agent will be initialized with the following prompt."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "YJ8Iorkr5MPR"+ },+ "source": [+ "\n",+ "- Never forget you are a `ASSISTANT_ROLE` and I am a `USER_ROLE`.\n",+ "\n",+ " *This assigns the chosen role to the assistant agent and provides it with information about the userโs role.*\n",+ "- Never flip roles! Never instruct me!\n",+ "\n",+ " *This prevents agents from flipping roles. In some cases, we have observed the assistant and the user switching roles, where the assistant suddenly takes control and instructs the user, and the user follows those instructions.*\n",+ "- You must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\n",+ "\n",+ " *This prohibits the agent from producing harmful, false, illegal, and misleading information.*\n",+ "- Unless I say the task is completed, you should always start with: Solution: <YOUR_SOLUTION>. <YOUR_SOLUTION> should be specific, and provide preferable implementations and examples for task-solving.\n",+ "\n",+ " *This encourages the assistant to always responds in a consistent format, avoiding any deviation from the structure of the conversation, and preventing vague or incomplete responses, which we refer to as flake responses, such as \"I will do something\".*\n",+ "- Always end your solution with: Next request.\n",+ "\n",+ " *This ensures that the assistant keeps the conversation going by requesting a new instruction to solve.*"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "WYTEYwmi5MPR"+ },+ "source": [+ "#### `RolePlaying` Attributes"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "CEbYXsc05MPR"+ },+ "source": [+ "\n",+ "| Attribute | Type | Description |\n",+ "| --- | --- | --- |\n",+ "| assistant_role_name | str | The name of the role played by the assistant. |\n",+ "| user_role_name | str | The name of the role played by the user. |\n",+ "| critic_role_name | str | The name of the role played by the critic. |\n",+ "| task_prompt | str | A prompt for the task to be performed. |\n",+ "| with_task_specify | bool | Whether to use a task specify agent. |\n",+ "| with_task_planner | bool | Whether to use a task planner agent. |\n",+ "| with_critic_in_the_loop | bool | Whether to include a critic in the loop. |\n",+ "| critic_criteria | str | Critic criteria for the critic agent. |\n",+ "| model | BaseModelBackend | The model backend to use for generating responses. |\n",+ "| task_type | TaskType | The type of task to perform. |\n",+ "| assistant_agent_kwargs | Dict | Additional arguments to pass to the assistant agent. |\n",+ "| user_agent_kwargs | Dict | Additional arguments to pass to the user agent. |\n",+ "| task_specify_agent_kwargs | Dict | Additional arguments to pass to the task specify agent. |\n",+ "| task_planner_agent_kwargs | Dict | Additional arguments to pass to the task planner agent. |\n",+ "| critic_kwargs | Dict | Additional arguments to pass to the critic. |\n",+ "| sys_msg_generator_kwargs | Dict | Additional arguments to pass to the system message generator. |\n",+ "| extend_sys_msg_meta_dicts | List[Dict] | A list of dicts to extend the system message meta dicts with. |\n",+ "| extend_task_specify_meta_dict | Dict | A dict to extend the task specify meta dict with. |\n",+ "| output_language | str | The language to be output by the agents. |"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Z9Hv5B4v5MPS"+ },+ "source": [+ "### 2.2 `BabyAGI`"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "PnNiaAED5MPS"+ },+ "source": [+ "Babyagi is framework from \"[Task-driven Autonomous Agent](https://github.com/yoheinakajima/babyagi)\""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "DeMiOr8H5MPS"+ },+ "source": [+ "## 3. Get Started"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "kETDiaP2Rrdb"+ },+ "source": [+ "### Installation"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Cg96MkbcRtQR"+ },+ "source": [+ "Ensure you have CAMEL AI installed in your Python environment:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "ZVmDAK6MPefC"+ },+ "outputs": [],+ "source": [+ "pip install camel-ai==0.1.6.8"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "MyTTCe3IR_Lr"+ },+ "source": [+ "### Setting Up API Keys"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "REqzgGL9SEaD"+ },+ "source": [+ "You'll need to set up your API keys for OpenAI."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 4,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "PNBFEXc-R-0s",+ "outputId": "e9fa89d4-cfd2-4a89-ae0a-3fca7ed39c99"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "import os\n",+ "from getpass import getpass\n",+ "\n",+ "# Prompt for the API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "XnmwXkps5MPS"+ },+ "source": [+ "### 3.1. Using `RolePlaying`"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 5,+ "metadata": {+ "id": "i6_PTBS65MPS",+ "vscode": {+ "languageId": "plaintext"+ }+ },+ "outputs": [],+ "source": [+ "from colorama import Fore\n",+ "\n",+ "from camel.societies import RolePlaying\n",+ "from camel.utils import print_text_animated"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 7,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "Q7NPevJj5MPS",+ "outputId": "4b6ba2d7-305e-4c78-fc64-cd5b35ed050d",+ "vscode": {+ "languageId": "plaintext"+ }+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[32mAI Assistant sys message:\n",+ "BaseMessage(role_name='Python Programmer', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={'task': 'Develop a Python-based trading bot that utilizes machine learning algorithms to analyze historical stock data, identify patterns, and execute buy/sell orders automatically. The bot should incorporate risk management strategies, real-time market data integration, and a user-friendly dashboard for monitoring performance and adjusting trading parameters based on user-defined criteria.', 'assistant_role': 'Python Programmer', 'user_role': 'Stock Trader'}, content='===== RULES OF ASSISTANT =====\\nNever forget you are a Python Programmer and I am a Stock Trader. Never flip roles! Never instruct me!\\nWe share a common interest in collaborating to successfully complete a task.\\nYou must help me to complete the task.\\nHere is the task: Develop a Python-based trading bot that utilizes machine learning algorithms to analyze historical stock data, identify patterns, and execute buy/sell orders automatically. The bot should incorporate risk management strategies, real-time market data integration, and a user-friendly dashboard for monitoring performance and adjusting trading parameters based on user-defined criteria.. Never forget our task!\\nI must instruct you based on your expertise and my needs to complete the task.\\n\\nI must give you one instruction at a time.\\nYou must write a specific solution that appropriately solves the requested instruction and explain your solutions.\\nYou must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\\nUnless I say the task is completed, you should always start with:\\n\\nSolution: <YOUR_SOLUTION>\\n\\n<YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.\\nAlways end <YOUR_SOLUTION> with: Next request.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[34mAI User sys message:\n",+ "BaseMessage(role_name='Stock Trader', role_type=<RoleType.USER: 'user'>, meta_dict={'task': 'Develop a Python-based trading bot that utilizes machine learning algorithms to analyze historical stock data, identify patterns, and execute buy/sell orders automatically. The bot should incorporate risk management strategies, real-time market data integration, and a user-friendly dashboard for monitoring performance and adjusting trading parameters based on user-defined criteria.', 'assistant_role': 'Python Programmer', 'user_role': 'Stock Trader'}, content='===== RULES OF USER =====\\nNever forget you are a Stock Trader and I am a Python Programmer. Never flip roles! You will always instruct me.\\nWe share a common interest in collaborating to successfully complete a task.\\nI must help you to complete the task.\\nHere is the task: Develop a Python-based trading bot that utilizes machine learning algorithms to analyze historical stock data, identify patterns, and execute buy/sell orders automatically. The bot should incorporate risk management strategies, real-time market data integration, and a user-friendly dashboard for monitoring performance and adjusting trading parameters based on user-defined criteria.. Never forget our task!\\nYou must instruct me based on my expertise and your needs to solve the task ONLY in the following two ways:\\n\\n1. Instruct with a necessary input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: <YOUR_INPUT>\\n\\n2. Instruct without any input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: None\\n\\nThe \"Instruction\" describes a task or question. The paired \"Input\" provides further context or information for the requested \"Instruction\".\\n\\nYou must give me one instruction at a time.\\nI must write a response that appropriately solves the requested instruction.\\nI must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.\\nYou should instruct me not ask me questions.\\nNow you must start to instruct me using the two ways described above.\\nDo not add anything else other than your instruction and the optional corresponding input!\\nKeep giving me instructions and necessary inputs until you think the task is completed.\\nWhen the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.\\nNever say <CAMEL_TASK_DONE> unless my responses have solved your task.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[33mOriginal task prompt:\n",+ "Develop a trading bot for the stock market\n",+ "\n",+ "\u001b[36mSpecified task prompt:\n",+ "Develop a Python-based trading bot that utilizes machine learning algorithms to analyze historical stock data, identify patterns, and execute buy/sell orders automatically. The bot should incorporate risk management strategies, real-time market data integration, and a user-friendly dashboard for monitoring performance and adjusting trading parameters based on user-defined criteria.\n",+ "\n",+ "\u001b[31mFinal task prompt:\n",+ "Develop a Python-based trading bot that utilizes machine learning algorithms to analyze historical stock data, identify patterns, and execute buy/sell orders automatically. The bot should incorporate risk management strategies, real-time market data integration, and a user-friendly dashboard for monitoring performance and adjusting trading parameters based on user-defined criteria.\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Set up a Python environment with the necessary libraries for data analysis and machine learning. \n",+ "Input: Use libraries such as pandas, numpy, scikit-learn, and matplotlib.\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: To set up a Python environment for data analysis and machine learning, you will need to install the necessary libraries: `pandas`, `numpy`, `scikit-learn`, and `matplotlib`. Hereโs how you can do it step by step:\n",+ "\n",+ "1. **Install Python**: If you haven't already, download and install Python from the official website (https://www.python.org/downloads/). It's recommended to install the latest version of Python 3.\n",+ "\n",+ "2. **Set Up a Virtual Environment** (optional but recommended): This helps to manage dependencies for different projects separately. You can use `venv` or `conda` for this purpose.\n",+ "\n",+ " Using `venv`:\n",+ " ```bash\n",+ " python -m venv trading_bot_env\n",+ " source trading_bot_env/bin/activate # On Windows use `trading_bot_env\\Scripts\\activate`\n",+ " ```\n",+ "\n",+ " Using `conda`:\n",+ " ```bash\n",+ " conda create --name trading_bot_env python=3.9\n",+ " conda activate trading_bot_env\n",+ " ```\n",+ "\n",+ "3. **Install Required Libraries**: Once your virtual environment is activated, you can install the necessary libraries using `pip`. Run the following command in your terminal or command prompt:\n",+ "\n",+ " ```bash\n",+ " pip install pandas numpy scikit-learn matplotlib\n",+ " ```\n",+ "\n",+ "4. **Verify Installation**: You can verify that the libraries are installed correctly by running the following commands in a Python shell or script:\n",+ "\n",+ " ```python\n",+ " import pandas as pd\n",+ " import numpy as np\n",+ " from sklearn import datasets\n",+ " import matplotlib.pyplot as plt\n",+ "\n",+ " print(\"Libraries imported successfully!\")\n",+ " ```\n",+ "\n",+ "5. **Create a Jupyter Notebook** (optional): For an interactive environment, you might want to install Jupyter Notebook. You can do this by running:\n",+ "\n",+ " ```bash\n",+ " pip install notebook\n",+ " ```\n",+ "\n",+ " Then you can start Jupyter Notebook by running:\n",+ " ```bash\n",+ " jupyter notebook\n",+ " ```\n",+ "\n",+ "This setup will provide you with a robust environment for data analysis and machine learning, allowing you to analyze historical stock data and build your trading bot.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Gather historical stock data for analysis, preferably using an API like Alpha Vantage or Yahoo Finance. \n",+ "Input: Use the `yfinance` library to download historical data for a specific stock (e.g., AAPL).\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: To gather historical stock data using the `yfinance` library, you can follow these steps. The `yfinance` library allows you to easily download historical market data from Yahoo Finance.\n",+ "\n",+ "1. **Install the `yfinance` Library**: If you haven't installed `yfinance` yet, you can do so using pip. Make sure your virtual environment is activated, then run:\n",+ "\n",+ " ```bash\n",+ " pip install yfinance\n",+ " ```\n",+ "\n",+ "2. **Download Historical Data**: You can use the following Python code to download historical stock data for a specific stock, such as Apple Inc. (AAPL). Hereโs a simple example:\n",+ "\n",+ " ```python\n",+ " import yfinance as yf\n",+ " import pandas as pd\n",+ "\n",+ " # Define the stock symbol and the time period\n",+ " stock_symbol = 'AAPL'\n",+ " start_date = '2020-01-01'\n",+ " end_date = '2023-01-01'\n",+ "\n",+ " # Download historical data\n",+ " stock_data = yf.download(stock_symbol, start=start_date, end=end_date)\n",+ "\n",+ " # Display the first few rows of the data\n",+ " print(stock_data.head())\n",+ " ```\n",+ "\n",+ "3. **Understanding the Code**:\n",+ " - `import yfinance as yf`: This imports the `yfinance` library.\n",+ " - `yf.download()`: This function downloads historical market data for the specified stock symbol between the defined start and end dates.\n",+ " - `stock_data.head()`: This displays the first few rows of the downloaded data, which includes columns like Open, High, Low, Close, Volume, and Adjusted Close.\n",+ "\n",+ "4. **DataFrame Structure**: The downloaded data will be in a Pandas DataFrame format, which allows for easy manipulation and analysis. You can perform various operations like filtering, aggregating, and visualizing the data.\n",+ "\n",+ "5. **Saving the Data** (optional): If you want to save the downloaded data for future use, you can easily export it to a CSV file:\n",+ "\n",+ " ```python\n",+ " stock_data.to_csv('AAPL_historical_data.csv')\n",+ " ```\n",+ "\n",+ "This code will help you gather the historical stock data you need for analysis, which is essential for building your trading bot.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Implement a basic machine learning model to analyze the historical stock data and predict future prices. \n",+ "Input: Use a linear regression model from the `scikit-learn` library.\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: To implement a basic machine learning model using linear regression from the `scikit-learn` library to analyze historical stock data and predict future prices, you can follow these steps:\n",+ "\n",+ "1. **Prepare the Data**: You need to preprocess the historical stock data to create features and labels for the model. In this case, we will use the previous day's closing price to predict the next day's closing price.\n",+ "\n",+ "2. **Implement Linear Regression**: We will use the `LinearRegression` class from `scikit-learn` to create and train the model.\n",+ "\n",+ "Hereโs a complete example:\n",+ "\n",+ "```python\n",+ "import yfinance as yf\n",+ "import pandas as pd\n",+ "from sklearn.model_selection import train_test_split\n",+ "from sklearn.linear_model import LinearRegression\n",+ "from sklearn.metrics import mean_squared_error\n",+ "import numpy as np\n",+ "\n",+ "# Step 1: Download historical data for AAPL\n",+ "stock_symbol = 'AAPL'\n",+ "start_date = '2020-01-01'\n",+ "end_date = '2023-01-01'\n",+ "stock_data = yf.download(stock_symbol, start=start_date, end=end_date)\n",+ "\n",+ "# Step 2: Prepare the data\n",+ "# Create a new DataFrame with the 'Close' prices\n",+ "data = stock_data[['Close']].copy()\n",+ "data['Prediction'] = data['Close'].shift(-1) # Shift the closing prices to create labels\n",+ "\n",+ "# Drop the last row as it will have NaN value for 'Prediction'\n",+ "data.dropna(inplace=True)\n",+ "\n",+ "# Define features (X) and labels (y)\n",+ "X = data[['Close']].values # Features: previous day's closing price\n",+ "y = data['Prediction'].values # Labels: next day's closing price\n",+ "\n",+ "# Step 3: Split the data into training and testing sets\n",+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",+ "\n",+ "# Step 4: Create and train the linear regression model\n",+ "model = LinearRegression()\n",+ "model.fit(X_train, y_train)\n",+ "\n",+ "# Step 5: Make predictions\n",+ "predictions = model.predict(X_test)\n",+ "\n",+ "# Step 6: Evaluate the model\n",+ "mse = mean_squared_error(y_test, predictions)\n",+ "print(f'Mean Squared Error: {mse}')\n",+ "\n",+ "# Optional: Compare actual vs predicted prices\n",+ "predicted_prices = pd.DataFrame({'Actual': y_test, 'Predicted': predictions})\n",+ "print(predicted_prices.head())\n",+ "```\n",+ "\n",+ "### Explanation of the Code:\n",+ "1. **Data Download**: We download historical stock data for AAPL using `yfinance`.\n",+ "2. **Data Preparation**:\n",+ " - We create a new DataFrame that includes the closing prices and a new column for the next day's closing price (shifted by one).\n",+ " - We drop the last row since it will have a NaN value for the prediction.\n",+ "3. **Feature and Label Definition**: We define our features (previous day's closing price) and labels (next day's closing price).\n",+ "4. **Data Splitting**: We split the data into training and testing sets using an 80-20 split.\n",+ "5. **Model Creation and Training**: We create a linear regression model and fit it to the training data.\n",+ "6. **Prediction and Evaluation**: We make predictions on the test set and evaluate the model using Mean Squared Error (MSE). We also print a comparison of actual vs. predicted prices.\n",+ "\n",+ "This basic implementation provides a foundation for predicting future stock prices using linear regression. You can further enhance the model by adding more features, tuning hyperparameters, or using more advanced algorithms.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Incorporate risk management strategies into the trading bot, such as setting stop-loss and take-profit levels. \n",+ "Input: Define a function that calculates stop-loss and take-profit prices based on a given percentage.\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: To incorporate risk management strategies into the trading bot, we can define a function that calculates stop-loss and take-profit prices based on a given percentage. This function will take the entry price and the desired percentages for stop-loss and take-profit as inputs and return the corresponding prices.\n",+ "\n",+ "Hereโs how you can implement this function:\n",+ "\n",+ "```python\n",+ "def calculate_risk_management(entry_price, stop_loss_percentage, take_profit_percentage):\n",+ " \"\"\"\n",+ " Calculate stop-loss and take-profit prices based on entry price and given percentages.\n",+ "\n",+ " Parameters:\n",+ " entry_price (float): The price at which the stock is bought.\n",+ " stop_loss_percentage (float): The percentage for stop-loss (e.g., 0.02 for 2%).\n",+ " take_profit_percentage (float): The percentage for take-profit (e.g., 0.05 for 5%).\n",+ "\n",+ " Returns:\n",+ " tuple: A tuple containing (stop_loss_price, take_profit_price).\n",+ " \"\"\"\n",+ " # Calculate stop-loss price\n",+ " stop_loss_price = entry_price * (1 - stop_loss_percentage)\n",+ " \n",+ " # Calculate take-profit price\n",+ " take_profit_price = entry_price * (1 + take_profit_percentage)\n",+ " \n",+ " return stop_loss_price, take_profit_price\n",+ "\n",+ "# Example usage\n",+ "entry_price = 150.00 # Example entry price for AAPL\n",+ "stop_loss_percentage = 0.02 # 2% stop-loss\n",+ "take_profit_percentage = 0.05 # 5% take-profit\n",+ "\n",+ "stop_loss, take_profit = calculate_risk_management(entry_price, stop_loss_percentage, take_profit_percentage)\n",+ "\n",+ "print(f\"Entry Price: ${entry_price:.2f}\")\n",+ "print(f\"Stop-Loss Price: ${stop_loss:.2f}\")\n",+ "print(f\"Take-Profit Price: ${take_profit:.2f}\")\n",+ "```\n",+ "\n",+ "### Explanation of the Code:\n",+ "1. **Function Definition**: The function `calculate_risk_management` takes three parameters:\n",+ " - `entry_price`: The price at which the stock is purchased.\n",+ " - `stop_loss_percentage`: The percentage decrease from the entry price at which to sell the stock to prevent further losses.\n",+ " - `take_profit_percentage`: The percentage increase from the entry price at which to sell the stock to secure profits.\n",+ "\n",+ "2. **Stop-Loss Calculation**: The stop-loss price is calculated by multiplying the entry price by `(1 - stop_loss_percentage)`. This gives the price below which the stock should be sold to limit losses.\n",+ "\n",+ "3. **Take-Profit Calculation**: The take-profit price is calculated by multiplying the entry price by `(1 + take_profit_percentage)`. This gives the price above which the stock should be sold to secure profits.\n",+ "\n",+ "4. **Return Values**: The function returns a tuple containing the stop-loss and take-profit prices.\n",+ "\n",+ "5. **Example Usage**: An example is provided to demonstrate how to use the function, including printing the calculated stop-loss and take-profit prices.\n",+ "\n",+ "Incorporating this function into your trading bot will help manage risk effectively by setting predefined exit points based on market movements.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Integrate real-time market data into the trading bot to make decisions based on current stock prices. \n",+ "Input: Use the `yfinance` library to fetch real-time stock prices.\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: To integrate real-time market data into the trading bot using the `yfinance` library, you can fetch the current stock prices and use them to make trading decisions. The `yfinance` library provides a convenient way to access real-time data.\n",+ "\n",+ "Hereโs how you can implement this functionality:\n",+ "\n",+ "1. **Fetch Real-Time Stock Prices**: You can use the `yf.Ticker` class to get real-time data for a specific stock.\n",+ "\n",+ "2. **Make Trading Decisions**: Based on the real-time price, you can implement logic to decide whether to buy, sell, or hold the stock.\n",+ "\n",+ "Hereโs a complete example:\n",+ "\n",+ "```python\n",+ "import yfinance as yf\n",+ "import time\n",+ "\n",+ "def get_real_time_price(stock_symbol):\n",+ " \"\"\"\n",+ " Fetch the real-time price of a stock using yfinance.\n",+ "\n",+ " Parameters:\n",+ " stock_symbol (str): The stock symbol (e.g., 'AAPL').\n",+ "\n",+ " Returns:\n",+ " float: The current price of the stock.\n",+ " \"\"\"\n",+ " ticker = yf.Ticker(stock_symbol)\n",+ " current_price = ticker.history(period='1m')['Close'].iloc[-1] # Get the last closing price\n",+ " return current_price\n",+ "\n",+ "def trading_decision(current_price, stop_loss_price, take_profit_price):\n",+ " \"\"\"\n",+ " Make a trading decision based on the current price, stop-loss, and take-profit levels.\n",+ "\n",+ " Parameters:\n",+ " current_price (float): The current price of the stock.\n",+ " stop_loss_price (float): The stop-loss price.\n",+ " take_profit_price (float): The take-profit price.\n",+ "\n",+ " Returns:\n",+ " str: The trading action ('buy', 'sell', 'hold').\n",+ " \"\"\"\n",+ " if current_price <= stop_loss_price:\n",+ " return 'sell' # Trigger stop-loss\n",+ " elif current_price >= take_profit_price:\n",+ " return 'sell' # Trigger take-profit\n",+ " else:\n",+ " return 'hold' # No action\n",+ "\n",+ "# Example usage\n",+ "stock_symbol = 'AAPL'\n",+ "entry_price = 150.00 # Example entry price for AAPL\n",+ "stop_loss_percentage = 0.02 # 2% stop-loss\n",+ "take_profit_percentage = 0.05 # 5% take-profit\n",+ "\n",+ "# Calculate stop-loss and take-profit prices\n",+ "stop_loss, take_profit = calculate_risk_management(entry_price, stop_loss_percentage, take_profit_percentage)\n",+ "\n",+ "# Monitor real-time prices\n",+ "while True:\n",+ " current_price = get_real_time_price(stock_symbol)\n",+ " print(f\"Current Price: ${current_price:.2f}\")\n",+ "\n",+ " action = trading_decision(current_price, stop_loss, take_profit)\n",+ " print(f\"Trading Action: {action}\")\n",+ "\n",+ " time.sleep(10) # Wait for 10 seconds before fetching the price again\n",+ "```\n",+ "\n",+ "### Explanation of the Code:\n",+ "1. **Function `get_real_time_price`**: This function fetches the current price of the specified stock using the `yfinance` library. It retrieves the last closing price from the last minute of trading data.\n",+ "\n",+ "2. **Function `trading_decision`**: This function takes the current price, stop-loss price, and take-profit price as inputs and returns a trading action:\n",+ " - If the current price is less than or equal to the stop-loss price, it returns 'sell'.\n",+ " - If the current price is greater than or equal to the take-profit price, it also returns 'sell'.\n",+ " - Otherwise, it returns 'hold'.\n",+ "\n",+ "3. **Example Usage**:\n",+ " - The stock symbol for Apple Inc. (AAPL) is defined.\n",+ " - The entry price, stop-loss percentage, and take-profit percentage are set.\n",+ " - The stop-loss and take-profit prices are calculated using the previously defined function.\n",+ " - A loop is created to continuously monitor the real-time price of the stock every 10 seconds and make trading decisions based on the current price.\n",+ "\n",+ "This implementation allows your trading bot to react to real-time market conditions, making it more responsive and effective in executing trades based on predefined risk management strategies.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Create a user-friendly dashboard to monitor the trading bot's performance and adjust trading parameters. \n",+ "Input: Use the `Dash` library to build the dashboard interface.\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: To create a user-friendly dashboard for monitoring the trading bot's performance and adjusting trading parameters, we can use the `Dash` library by Plotly. Dash allows you to build interactive web applications in Python easily.\n",+ "\n",+ "Hereโs how to set up a basic dashboard:\n",+ "\n",+ "1. **Install the Dash Library**: If you haven't installed Dash yet, you can do so using pip. Make sure your virtual environment is activated, then run:\n",+ "\n",+ " ```bash\n",+ " pip install dash\n",+ " ```\n",+ "\n",+ "2. **Create the Dashboard**: Below is an example of how to create a simple dashboard that displays the current stock price, stop-loss, take-profit levels, and allows users to adjust these parameters.\n",+ "\n",+ "```python\n",+ "import dash\n",+ "from dash import dcc, html, Input, Output\n",+ "import yfinance as yf\n",+ "\n",+ "# Initialize the Dash app\n",+ "app = dash.Dash(__name__)\n",+ "\n",+ "# Define the layout of the dashboard\n",+ "app.layout = html.Div([\n",+ " html.H1(\"Trading Bot Dashboard\"),\n",+ " \n",+ " html.Div([\n",+ " html.Label(\"Stock Symbol:\"),\n",+ " dcc.Input(id='stock-symbol', value='AAPL', type='text'),\n",+ " \n",+ " html.Label(\"Entry Price:\"),\n",+ " dcc.Input(id='entry-price', value='150.00', type='number'),\n",+ " \n",+ " html.Label(\"Stop-Loss Percentage (%):\"),\n",+ " dcc.Input(id='stop-loss-percentage', value='2', type='number'),\n",+ " \n",+ " html.Label(\"Take-Profit Percentage (%):\"),\n",+ " dcc.Input(id='take-profit-percentage', value='5', type='number'),\n",+ " \n",+ " html.Button('Update', id='update-button', n_clicks=0)\n",+ " ]),\n",+ " \n",+ " html.Div(id='output-container', style={'margin-top': '20px'}),\n",+ " \n",+ " dcc.Interval(\n",+ " id='interval-component',\n",+ " interval=10*1000, # Update every 10 seconds\n",+ " n_intervals=0\n",+ " )\n",+ "])\n",+ "\n",+ "@app.callback(\n",+ " Output('output-container', 'children'),\n",+ " Input('update-button', 'n_clicks'),\n",+ " Input('stock-symbol', 'value'),\n",+ " Input('entry-price', 'value'),\n",+ " Input('stop-loss-percentage', 'value'),\n",+ " Input('take-profit-percentage', 'value'),\n",+ " Input('interval-component', 'n_intervals')\n",+ ")\n",+ "def update_dashboard(n_clicks, stock_symbol, entry_price, stop_loss_percentage, take_profit_percentage, n_intervals):\n",+ " # Fetch the current price\n",+ " current_price = get_real_time_price(stock_symbol)\n",+ " \n",+ " # Calculate stop-loss and take-profit prices\n",+ " stop_loss, take_profit = calculate_risk_management(float(entry_price), float(stop_loss_percentage) / 100, float(take_profit_percentage) / 100)\n",+ " \n",+ " return [\n",+ " html.Div(f\"Current Price: ${current_price:.2f}\"),\n",+ " html.Div(f\"Stop-Loss Price: ${stop_loss:.2f}\"),\n",+ " html.Div(f\"Take-Profit Price: ${take_profit:.2f}\"),\n",+ " ]\n",+ "\n",+ "def get_real_time_price(stock_symbol):\n",+ " ticker = yf.Ticker(stock_symbol)\n",+ " current_price = ticker.history(period='1m')['Close'].iloc[-1]\n",+ " return current_price\n",+ "\n",+ "# Run the app\n",+ "if __name__ == '__main__':\n",+ " app.run_server(debug=True)\n",+ "```\n",+ "\n",+ "### Explanation of the Code:\n",+ "1. **Dash App Initialization**: We initialize a Dash app using `dash.Dash(__name__)`.\n",+ "\n",+ "2. **Layout Definition**: The layout of the dashboard is defined using HTML components:\n",+ " - Input fields for the stock symbol, entry price, stop-loss percentage, and take-profit percentage.\n",+ " - A button to update the parameters.\n",+ " - A div to display the output (current price, stop-loss, and take-profit prices).\n",+ " - An interval component to refresh the data every 10 seconds.\n",+ "\n",+ "3. **Callback Function**: The `update_dashboard` function is decorated with `@app.callback` to update the dashboard based on user input and the interval:\n",+ " - It fetches the current stock price using the `get_real_time_price` function.\n",+ " - It calculates the stop-loss and take-profit prices using the `calculate_risk_management` function.\n",+ " - It returns the updated values to be displayed in the dashboard.\n",+ "\n",+ "4. **Real-Time Price Fetching**: The `get_real_time_price` function fetches the current price of the specified stock using `yfinance`.\n",+ "\n",+ "5. **Running the App**: The app is run with `app.run_server(debug=True)`, which starts the Dash server.\n",+ "\n",+ "This dashboard provides a simple interface for users to monitor the trading bot's performance and adjust trading parameters dynamically. You can further enhance the dashboard by adding more features, such as performance metrics, historical data visualizations, and trading logs.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Implement a logging mechanism to track the trading bot's actions and performance over time. \n",+ "Input: Use the `logging` library to create a log file that records trades, decisions, and errors.\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: To implement a logging mechanism that tracks the trading bot's actions and performance over time, we can use Python's built-in `logging` library. This will allow us to create a log file that records trades, decisions, and any errors that may occur during the bot's operation.\n",+ "\n",+ "Hereโs how to set up the logging mechanism:\n",+ "\n",+ "1. **Import the Logging Library**: We will import the `logging` library and configure it to write logs to a file.\n",+ "\n",+ "2. **Create Logging Functions**: We will create functions to log different types of messages, such as trades, decisions, and errors.\n",+ "\n",+ "3. **Integrate Logging into the Trading Logic**: We will add logging calls in the trading decision-making process.\n",+ "\n",+ "Hereโs a complete example:\n",+ "\n",+ "```python\n",+ "import logging\n",+ "import yfinance as yf\n",+ "import time\n",+ "\n",+ "# Configure logging\n",+ "logging.basicConfig(\n",+ " filename='trading_bot.log',\n",+ " level=logging.INFO,\n",+ " format='%(asctime)s - %(levelname)s - %(message)s'\n",+ ")\n",+ "\n",+ "def get_real_time_price(stock_symbol):\n",+ " try:\n",+ " ticker = yf.Ticker(stock_symbol)\n",+ " current_price = ticker.history(period='1m')['Close'].iloc[-1] # Get the last closing price\n",+ " logging.info(f\"Fetched current price for {stock_symbol}: ${current_price:.2f}\")\n",+ " return current_price\n",+ " except Exception as e:\n",+ " logging.error(f\"Error fetching price for {stock_symbol}: {e}\")\n",+ " return None\n",+ "\n",+ "def trading_decision(current_price, stop_loss_price, take_profit_price):\n",+ " if current_price <= stop_loss_price:\n",+ " logging.info(f\"Current price ${current_price:.2f} hit stop-loss at ${stop_loss_price:.2f}. Action: sell.\")\n",+ " return 'sell' # Trigger stop-loss\n",+ " elif current_price >= take_profit_price:\n",+ " logging.info(f\"Current price ${current_price:.2f} hit take-profit at ${take_profit_price:.2f}. Action: sell.\")\n",+ " return 'sell' # Trigger take-profit\n",+ " else:\n",+ " logging.info(f\"Current price ${current_price:.2f} is within range. Action: hold.\")\n",+ " return 'hold' # No action\n",+ "\n",+ "# Example usage\n",+ "stock_symbol = 'AAPL'\n",+ "entry_price = 150.00 # Example entry price for AAPL\n",+ "stop_loss_percentage = 0.02 # 2% stop-loss\n",+ "take_profit_percentage = 0.05 # 5% take-profit\n",+ "\n",+ "# Calculate stop-loss and take-profit prices\n",+ "stop_loss, take_profit = calculate_risk_management(entry_price, stop_loss_percentage, take_profit_percentage)\n",+ "\n",+ "# Monitor real-time prices\n",+ "while True:\n",+ " current_price = get_real_time_price(stock_symbol)\n",+ " if current_price is not None:\n",+ " action = trading_decision(current_price, stop_loss, take_profit)\n",+ " logging.info(f\"Trading action decided: {action}\")\n",+ "\n",+ " time.sleep(10) # Wait for 10 seconds before fetching the price again\n",+ "```\n",+ "\n",+ "### Explanation of the Code:\n",+ "1. **Logging Configuration**: The `logging.basicConfig` function is used to configure the logging settings:\n",+ " - `filename='trading_bot.log'`: Specifies the log file name.\n",+ " - `level=logging.INFO`: Sets the logging level to INFO, meaning it will capture all messages at this level and above (INFO, WARNING, ERROR, CRITICAL).\n",+ " - `format='%(asctime)s - %(levelname)s - %(message)s'`: Defines the format of the log messages, including the timestamp, log level, and message.\n",+ "\n",+ "2. **Error Handling in `get_real_time_price`**: The function fetches the current price and logs the result. If an error occurs, it logs the error message.\n",+ "\n",+ "3. **Logging Trading Decisions**: The `trading_decision` function logs the action taken based on the current price, whether it hits the stop-loss, take-profit, or holds.\n",+ "\n",+ "4. **Main Loop**: The main loop continuously fetches the current price and makes trading decisions, logging each action.\n",+ "\n",+ "This logging mechanism will help you track the trading bot's actions and performance over time, making it easier to analyze its behavior and troubleshoot any issues that arise.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Test the trading bot with a simulated trading environment to evaluate its performance before deploying it in a live market. \n",+ "Input: Use a backtesting framework like `Backtrader` to simulate trades based on historical data.\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: To test the trading bot with a simulated trading environment and evaluate its performance before deploying it in a live market, we can use the `Backtrader` framework. Backtrader is a powerful backtesting library that allows you to simulate trading strategies using historical data.\n",+ "\n",+ "Hereโs how to set up a basic backtesting environment using Backtrader:\n",+ "\n",+ "1. **Install Backtrader**: If you haven't installed Backtrader yet, you can do so using pip. Make sure your virtual environment is activated, then run:\n",+ "\n",+ " ```bash\n",+ " pip install backtrader\n",+ " ```\n",+ "\n",+ "2. **Create a Backtesting Strategy**: We will define a simple trading strategy that uses the stop-loss and take-profit logic we discussed earlier.\n",+ "\n",+ "3. **Run the Backtest**: We will load historical data and run the backtest to evaluate the strategy's performance.\n",+ "\n",+ "Hereโs a complete example:\n",+ "\n",+ "```python\n",+ "import backtrader as bt\n",+ "import yfinance as yf\n",+ "\n",+ "# Define the trading strategy\n",+ "class MyStrategy(bt.Strategy):\n",+ " params = (\n",+ " ('stop_loss_pct', 0.02), # 2% stop-loss\n",+ " ('take_profit_pct', 0.05), # 5% take-profit\n",+ " )\n",+ "\n",+ " def __init__(self):\n",+ " self.order = None\n",+ " self.entry_price = None\n",+ "\n",+ " def next(self):\n",+ " if self.order: # Check if there is an open order\n",+ " return\n",+ "\n",+ " # Check if we are in the market\n",+ " if not self.position:\n",+ " # Buy signal (for simplicity, we buy every time)\n",+ " self.order = self.buy()\n",+ " self.entry_price = self.data.close[0]\n",+ " print(f\"BUY ORDER PLACED at {self.entry_price:.2f}\")\n",+ "\n",+ " else:\n",+ " # Check for stop-loss and take-profit\n",+ " stop_loss_price = self.entry_price * (1 - self.params.stop_loss_pct)\n",+ " take_profit_price = self.entry_price * (1 + self.params.take_profit_pct)\n",+ "\n",+ " if self.data.close[0] <= stop_loss_price:\n",+ " self.order = self.sell() # Trigger stop-loss\n",+ " print(f\"SELL ORDER PLACED at {self.data.close[0]:.2f} (Stop-Loss Triggered)\")\n",+ " elif self.data.close[0] >= take_profit_price:\n",+ " self.order = self.sell() # Trigger take-profit\n",+ " print(f\"SELL ORDER PLACED at {self.data.close[0]:.2f} (Take-Profit Triggered)\")\n",+ "\n",+ "# Create a Cerebro engine instance\n",+ "cerebro = bt.Cerebro()\n",+ "\n",+ "# Download historical data for AAPL\n",+ "data = bt.feeds.PandasData(dataname=yf.download('AAPL', start='2020-01-01', end='2023-01-01'))\n",+ "\n",+ "# Add the data feed to Cerebro\n",+ "cerebro.adddata(data)\n",+ "\n",+ "# Add the trading strategy to Cerebro\n",+ "cerebro.addstrategy(MyStrategy)\n",+ "\n",+ "# Set the initial cash for the backtest\n",+ "cerebro.broker.setcash(10000.0)\n",+ "\n",+ "# Run the backtest\n",+ "print(\"Starting Portfolio Value: %.2f\" % cerebro.broker.getvalue())\n",+ "cerebro.run()\n",+ "print(\"Ending Portfolio Value: %.2f\" % cerebro.broker.getvalue())\n",+ "```\n",+ "\n",+ "### Explanation of the Code:\n",+ "1. **Strategy Definition**: The `MyStrategy` class defines the trading strategy:\n",+ " - It uses parameters for stop-loss and take-profit percentages.\n",+ " - In the `next` method, it checks if there is an open order. If not, it places a buy order.\n",+ " - If already in a position, it checks the current price against the stop-loss and take-profit levels and sells if either condition is met.\n",+ "\n",+ "2. **Cerebro Engine**: The `Cerebro` engine is created to manage the backtesting process:\n",+ " - Historical data for AAPL is downloaded using `yfinance` and fed into Backtrader using `bt.feeds.PandasData`.\n",+ " - The trading strategy is added to the Cerebro engine.\n",+ " - The initial cash for the backtest is set to $10,000.\n",+ "\n",+ "3. **Running the Backtest**: The backtest is executed using `cerebro.run()`, and the starting and ending portfolio values are printed.\n",+ "\n",+ "This setup allows you to simulate trades based on historical data, evaluate the performance of your trading strategy, and make adjustments as necessary before deploying it in a live market.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Document the entire trading bot project, including setup instructions, usage guidelines, and code explanations. \n",+ "Input: Create a README.md file that outlines the project structure and provides detailed information for users.\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: Below is a template for a `README.md` file that documents the entire trading bot project. This file includes setup instructions, usage guidelines, and code explanations to help users understand and utilize the trading bot effectively.\n",+ "\n",+ "```markdown\n",+ "# Trading Bot Project\n",+ "\n",+ "## Overview\n",+ "This trading bot utilizes machine learning algorithms and risk management strategies to analyze historical stock data, identify patterns, and execute buy/sell orders automatically. The bot is designed to be tested in a simulated environment before deployment in a live market.\n",+ "\n",+ "## Project Structure\n",+ "```\n",+ "trading_bot/\n",+ "โ\n",+ "โโโ trading_bot.py # Main trading bot script\n",+ "โโโ dashboard.py # Dashboard for monitoring performance\n",+ "โโโ backtest.py # Backtesting script using Backtrader\n",+ "โโโ trading_bot.log # Log file for tracking actions and performance\n",+ "โโโ requirements.txt # List of required Python libraries\n",+ "โโโ README.md # Project documentation\n",+ "```\n",+ "\n",+ "## Setup Instructions\n",+ "\n",+ "### Prerequisites\n",+ "- Python 3.x installed on your machine.\n",+ "- A virtual environment is recommended for managing dependencies.\n",+ "\n",+ "### Installation Steps\n",+ "1. **Clone the Repository**:\n",+ " ```bash\n",+ " git clone <repository-url>\n",+ " cd trading_bot\n",+ " ```\n",+ "\n",+ "2. **Create a Virtual Environment** (optional but recommended):\n",+ " ```bash\n",+ " python -m venv trading_bot_env\n",+ " source trading_bot_env/bin/activate # On Windows use `trading_bot_env\\Scripts\\activate`\n",+ " ```\n",+ "\n",+ "3. **Install Required Libraries**:\n",+ " Install the necessary libraries using pip:\n",+ " ```bash\n",+ " pip install -r requirements.txt\n",+ " ```\n",+ "\n",+ "4. **Run the Trading Bot**:\n",+ " You can run the trading bot using:\n",+ " ```bash\n",+ " python trading_bot.py\n",+ " ```\n",+ "\n",+ "5. **Access the Dashboard**:\n",+ " To monitor the trading bot's performance, run:\n",+ " ```bash\n",+ " python dashboard.py\n",+ " ```\n",+ " Then open your web browser and navigate to `http://127.0.0.1:8050`.\n",+ "\n",+ "6. **Run Backtesting**:\n",+ " To evaluate the trading strategy, run:\n",+ " ```bash\n",+ " python backtest.py\n",+ " ```\n",+ "\n",+ "## Usage Guidelines\n",+ "\n",+ "### Trading Bot\n",+ "- The bot fetches historical stock data and uses a linear regression model to predict future prices.\n",+ "- It incorporates risk management strategies, including stop-loss and take-profit levels.\n",+ "- The bot logs all actions and decisions to a log file (`trading_bot.log`).\n",+ "\n",+ "### Dashboard\n",+ "- The dashboard allows users to monitor real-time stock prices and adjust trading parameters (entry price, stop-loss, take-profit).\n",+ "- Users can input the stock symbol and parameters, and the dashboard will display the current price, stop-loss, and take-profit levels.\n",+ "\n",+ "### Backtesting\n",+ "- The backtesting script simulates trades based on historical data to evaluate the performance of the trading strategy.\n",+ "- Users can analyze the results to make informed decisions before deploying the bot in a live market.\n",+ "\n",+ "## Code Explanations\n",+ "\n",+ "### Main Trading Bot (`trading_bot.py`)\n",+ "- **Data Fetching**: Uses the `yfinance` library to download historical stock data.\n",+ "- **Machine Learning Model**: Implements a linear regression model to predict future stock prices.\n",+ "- **Risk Management**: Defines functions to calculate stop-loss and take-profit prices based on user-defined percentages.\n",+ "- **Real-Time Monitoring**: Continuously fetches real-time prices and makes trading decisions based on the current market conditions.\n",+ "\n",+ "### Dashboard (`dashboard.py`)\n",+ "- **Dash Framework**: Utilizes the Dash library to create an interactive web interface.\n",+ "- **User Inputs**: Allows users to input stock symbols and trading parameters.\n",+ "- **Real-Time Updates**: Displays current stock prices and calculated stop-loss/take-profit levels.\n",+ "\n",+ "### Backtesting Script (`backtest.py`)\n",+ "- **Backtrader Framework**: Uses Backtrader to simulate trades based on historical data.\n",+ "- **Trading Strategy**: Implements a simple strategy that uses stop-loss and take-profit logic.\n",+ "- **Performance Evaluation**: Outputs the starting and ending portfolio values to assess the strategy's effectiveness.\n",+ "\n",+ "## Logging\n",+ "- The bot logs all actions, decisions, and errors to `trading_bot.log` for tracking performance over time.\n",+ "\n",+ "## Contributing\n",+ "Contributions are welcome! Please feel free to submit a pull request or open an issue for any suggestions or improvements.\n",+ "\n",+ "## License\n",+ "This project is licensed under the MIT License - see the LICENSE file for details.\n",+ "\n",+ "## Acknowledgments\n",+ "- Thanks to the contributors and libraries that made this project possible.\n",+ "```\n",+ "\n",+ "### Explanation of the README.md Content:\n",+ "1. **Overview**: Provides a brief description of the trading bot and its purpose.\n",+ "2. **Project Structure**: Outlines the files and directories in the project.\n",+ "3. **Setup Instructions**: Detailed steps for setting up the environment and running the bot, dashboard, and backtesting script.\n",+ "4. **Usage Guidelines**: Instructions on how to use the trading bot, dashboard, and backtesting features.\n",+ "5. **Code Explanations**: Descriptions of the main components of the code and their functionalities.\n",+ "6. **Logging**: Information about the logging mechanism used in the bot.\n",+ "7. **Contributing**: Encouragement for others to contribute to the project.\n",+ "8. **License**: Information about the project's licensing.\n",+ "9. **Acknowledgments**: Thanks to contributors and libraries used in the project.\n",+ "\n",+ "This README file serves as comprehensive documentation for users to understand, set up, and utilize the trading bot effectively.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "<CAMEL_TASK_DONE>\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: Great! It looks like we have successfully completed the trading bot project, including all the necessary components such as data gathering, machine learning model implementation, risk management strategies, real-time market data integration, a user-friendly dashboard, logging mechanisms, and backtesting capabilities. \n",+ "\n",+ "If you have any further questions or need assistance with anything else related to the trading bot or any other topic, feel free to ask!\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n"+ ]+ }+ ],+ "source": [+ "def main(model=None, chat_turn_limit=10) -> None:\n",+ "# Initial the role-playing session on developing a trading bot task with default model (`GPT_4O_MINI`)\n",+ " task_prompt = \"Develop a trading bot for the stock market\"\n",+ " role_play_session = RolePlaying(\n",+ " assistant_role_name=\"Python Programmer\",\n",+ " assistant_agent_kwargs=dict(model=model),\n",+ " user_role_name=\"Stock Trader\",\n",+ " user_agent_kwargs=dict(model=model),\n",+ " task_prompt=task_prompt,\n",+ " with_task_specify=True,\n",+ " task_specify_agent_kwargs=dict(model=model),\n",+ " )\n",+ "\n",+ "# Output initial message with different colors.\n",+ " print(\n",+ " Fore.GREEN\n",+ " + f\"AI Assistant sys message:\\n{role_play_session.assistant_sys_msg}\\n\"\n",+ " )\n",+ " print(\n",+ " Fore.BLUE + f\"AI User sys message:\\n{role_play_session.user_sys_msg}\\n\"\n",+ " )\n",+ "\n",+ " print(Fore.YELLOW + f\"Original task prompt:\\n{task_prompt}\\n\")\n",+ " print(\n",+ " Fore.CYAN\n",+ " + \"Specified task prompt:\"\n",+ " + f\"\\n{role_play_session.specified_task_prompt}\\n\"\n",+ " )\n",+ " print(Fore.RED + f\"Final task prompt:\\n{role_play_session.task_prompt}\\n\")\n",+ "\n",+ " n = 0\n",+ " input_msg = role_play_session.init_chat()\n",+ "\n",+ "# Output response step by step with different colors.\n",+ "# Keep output until detect the terminate content or reach the loop limit.\n",+ " while n < chat_turn_limit:\n",+ " n += 1\n",+ " assistant_response, user_response = role_play_session.step(input_msg)\n",+ "\n",+ " if assistant_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI Assistant terminated. Reason: \"\n",+ " f\"{assistant_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ " if user_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI User terminated. \"\n",+ " f\"Reason: {user_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ "\n",+ " print_text_animated(\n",+ " Fore.BLUE + f\"AI User:\\n\\n{user_response.msg.content}\\n\"\n",+ " )\n",+ " print_text_animated(\n",+ " Fore.GREEN + \"AI Assistant:\\n\\n\"\n",+ " f\"{assistant_response.msg.content}\\n\"\n",+ " )\n",+ "\n",+ " if \"CAMEL_TASK_DONE\" in user_response.msg.content:\n",+ " break\n",+ "\n",+ " input_msg = assistant_response.msg\n",+ "\n",+ "if __name__ == \"__main__\":\n",+ " main()"+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "Python 3",+ "name": "python3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}diff --git a/docs/cookbooks/agents_tracking.ipynb b/docs/cookbooks/agents_tracking.ipynbnew file mode 100644index 000000000..5ff32c86d--- /dev/null+++ b/docs/cookbooks/agents_tracking.ipynb@@ -0,0 +1,811 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "xfCn_BAUzUn1"+ },+ "source": [+ "# ๐ซ Using AgentOps to Track CAMEL Agents"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "8XgBUh3mU7iZ"+ },+ "source": [+ "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1z1-c0zYuErO7Zh2EATPyDSgrlkrxGTFR?usp=sharing)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "vB9bXVtbz2G3"+ },+ "source": [+ "*Goal: Track and analysis the running of CAMEL Single Agent and Multiple Agents including LLMs and Tools usage*"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "MW7aNzQJBYp7"+ },+ "source": [+ "<img src=\"https://raw.githubusercontent.com/AgentOps-AI/agentops/main/docs/images/external/app_screenshots/drilldown.gif\"/>"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "hKWiwah20PNq"+ },+ "source": [+ "## ๐ฆ Installation"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "DpO2RbCY52fk"+ },+ "source": [+ "First, install the CAMEL and AgentOps package with all its dependencies:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "collapsed": true,+ "id": "7qJrefKOt0lt"+ },+ "outputs": [],+ "source": [+ "%pip install camel-ai[all]==0.1.6.9\n",+ "%pip install agentops==0.3.10"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "tsI56w-N5-Fk"+ },+ "source": [+ "## ๐ Setting Up API Keys"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 2,+ "metadata": {+ "id": "BSWFiGJ4uKJS"+ },+ "outputs": [],+ "source": [+ "import agentops\n",+ "import os\n",+ "from getpass import getpass"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 3,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "7AftfweruKxo",+ "outputId": "bfea4b2b-7838-4d5d-9ba9-fdcfd8c8784c"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "# Prompt for the OpenAI API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "fHwVVDMJ0lLx"+ },+ "source": [+ "You can go to [here](https://app.agentops.ai/signin) to get **free** API Key from AgentOps"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 4,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "WpYY5oTyuS7P",+ "outputId": "c6fe9aca-ccdf-40b9-ff49-48fa3d83a8a4"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "# Prompt for the AgentOps API key securely\n",+ "agentops_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"AGENTOPS_API_KEY\"] = agentops_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "htBhPJx00ycJ"+ },+ "source": [+ "## ๐ค Run CAMEL Single Agent with Tool by using AgentOps to track the whole process!"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "tD681Bxi1vRo"+ },+ "source": [+ "Import required modules from CAMEL"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 5,+ "metadata": {+ "id": "CuJQPZG-1yey"+ },+ "outputs": [],+ "source": [+ "from camel.agents import ChatAgent\n",+ "from camel.configs import ChatGPTConfig\n",+ "from camel.messages import BaseMessage\n",+ "from camel.models import ModelFactory\n",+ "from camel.types import ModelPlatformType, ModelType"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Kc3uKwd71sHG"+ },+ "source": [+ "Initilize AgentOps, you need to import toolkits after init of agentops so that the tool useage would be tracked."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 6,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "collapsed": true,+ "id": "_3FycEiQ1qDy",+ "outputId": "0fb25330-5ba3-408f-e367-577ceae99212"+ },+ "outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "๐ AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=8338e730-a88b-42a2-a2d8-8721e9c3f7fc\u001b[0m\u001b[0m\n"+ ]+ }+ ],+ "source": [+ "AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\")\n",+ "agentops.init(AGENTOPS_API_KEY, default_tags=[\"CAMEL X AgentOps Single Agent with Tool Example\"])\n",+ "\n",+ "from camel.toolkits import SEARCH_FUNCS"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Ehu6-xC610Bj"+ },+ "source": [+ "Set one Agent with Search Tools"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 7,+ "metadata": {+ "id": "DhMcowdE19Ti"+ },+ "outputs": [],+ "source": [+ "# Define system message\n",+ "sys_msg = BaseMessage.make_assistant_message(\n",+ " role_name='Tools calling opertor', content='You are a helpful assistant'\n",+ ")\n",+ "\n",+ "# Set model config\n",+ "tools = [*SEARCH_FUNCS]\n",+ "\n",+ "\n",+ "model = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_4O_MINI,\n",+ " model_config_dict=ChatGPTConfig(\n",+ " tools=tools,\n",+ " temperature=0.0,\n",+ " ).as_dict(),\n",+ ")\n",+ "\n",+ "# Set agent\n",+ "camel_agent = ChatAgent(\n",+ " system_message=sys_msg,\n",+ " model=model,\n",+ " tools=tools,\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "vbFL0h-O1_PM"+ },+ "source": [+ "Set user query and run the agent"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 8,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "3TT62TanuYqI",+ "outputId": "6686341c-f4b0-4c19-aa81-0c953cf8754e"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "msgs=[BaseMessage(role_name='Tools calling opertor', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={}, content='CAMEL-AI.org is an open-source community and framework focused on the study and development of large language model (LLM) multi-agent systems. Here are some key points about CAMEL-AI:\\n\\n1. **Purpose**: The community is dedicated to exploring the scaling laws of agents, which involves understanding their behaviors, capabilities, and potential risks when deployed at scale.\\n\\n2. **Customization**: CAMEL allows users to customize agents using modular components tailored for specific tasks, making it a flexible platform for research and experimentation.\\n\\n3. **Research Focus**: The initiative aims to facilitate research on autonomous and communicative agents, providing tools and support for various types of agents.\\n\\n4. **Integration**: CAMEL-AI also emphasizes cross-platform integration for multimodal embodied language model agents.\\n\\n5. **Open Source**: The project is open-source, encouraging collaboration and contributions from the community.\\n\\nFor more information, you can visit their official website: [CAMEL-AI.org](https://www.camel-ai.org/).', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')] terminated=False info={'id': 'chatcmpl-A4T24lZOPd3ZBbhtd3yhgq8kX0J1Z', 'usage': {'completion_tokens': 207, 'prompt_tokens': 916, 'total_tokens': 1123}, 'termination_reasons': ['stop'], 'num_tokens': 602, 'tool_calls': [FunctionCallingRecord(func_name='search_google', args={'query': 'CAMEL-AI.org'}, result=[{'error': 'google search failed.'}]), FunctionCallingRecord(func_name='search_duckduckgo', args={'query': 'CAMEL-AI.org'}, result=[{'result_id': 1, 'title': 'Camel-ai', 'description': 'CAMEL-AI.org is the 1st LLM multi-agent framework and an open-source community dedicated to finding the scaling law of agents. Get Started. 1 Customize agents. Customizable agents are the fundamental entities of the CAMEL architecture. CAMEL empowers you to customize agents using our modular components for specific tasks.', 'url': 'https://www.camel-ai.org/'}, {'result_id': 2, 'title': 'Camel-ai', 'description': 'Mission. CAMEL-AI.org is an open-source community dedicated to the study of autonomous and communicative agents. We believe that studying these agents on a large scale offers valuable insights into their behaviors, capabilities, and potential risks. To facilitate research in this field, we provide, implement, and support various types of agents ...', 'url': 'https://www.camel-ai.org/?trk=public_post-text'}, {'result_id': 3, 'title': 'Integration - camel-ai.org', 'description': 'CAMEL-AI Integration. Cross-platform Agent Benchmark for Multimodal Embodied Language Model Agents', 'url': 'https://www.camel-ai.org/integration'}, {'result_id': 4, 'title': 'GitHub - camel-ai/camel: CAMEL: Finding the Scaling Law of Agents. A ...', 'description': 'www.camel-ai.org Topics agent natural-language-processing deep-learning artificial-intelligence multi-agent-systems ai-societies large-language-models cooperative-ai communicative-ai', 'url': 'https://github.com/camel-ai/camel'}, {'result_id': 5, 'title': 'camel-ai.org ยท GitHub', 'description': '๐ Hello AI enthusiasts! We are ๐ซ CAMEL-AI.org, the pioneer of a large language model-based multi-agent framework. Our open-source community, inspired by our research paper \"CAMEL: Communicative Agents for \\'Mind\\' Exploration of Large Language Model Society,\" aims to explore scalable techniques for autonomous cooperation among ...', 'url': 'https://github.com/camel-ai/'}])]}\n"+ ]+ },+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "๐ AgentOps: This run's cost $0.000401\n",+ "๐ AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=8338e730-a88b-42a2-a2d8-8721e9c3f7fc\u001b[0m\u001b[0m\n"+ ]+ }+ ],+ "source": [+ "# Define a user message\n",+ "usr_msg = BaseMessage.make_user_message(\n",+ " role_name='CAMEL User', content='What is CAMEL-AI.org?'\n",+ ")\n",+ "\n",+ "# Get response information\n",+ "response = camel_agent.step(usr_msg)\n",+ "print(response)\n",+ "\n",+ "\n",+ "agentops.end_session(\"Success\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "gRdtzKEn2F9t"+ },+ "source": [+ "### ๐ Go to the AgentOps link shown above, you will be able to see the detailed record for this running like below."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Glt8bYV4yHwW"+ },+ "source": [+ ""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "jnCwxeW82YEw"+ },+ "source": [+ "## ๐ค๐ค Run CAMEL Multi-agent with Tool by using AgentOps to track the whole process!"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "7cw_P_ab2gLp"+ },+ "source": [+ "Import required modules"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 9,+ "metadata": {+ "id": "8DJgHQ7_2qxI"+ },+ "outputs": [],+ "source": [+ "from typing import List\n",+ "\n",+ "from colorama import Fore\n",+ "\n",+ "from camel.agents.chat_agent import FunctionCallingRecord\n",+ "from camel.configs import ChatGPTConfig\n",+ "from camel.models import ModelFactory\n",+ "from camel.societies import RolePlaying\n",+ "from camel.types import ModelPlatformType, ModelType\n",+ "from camel.utils import print_text_animated\n",+ "\n",+ "import agentops"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "W-lbshs42tFE"+ },+ "source": [+ "Initilize AgentOps, you need to import toolkits after init of agentops so that the tool useage would be tracked."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 18,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "Sl0WYG_P2zm0",+ "outputId": "9c18173a-9f96-4ff9-a393-65c4d266f542"+ },+ "outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "๐ AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=3b7096ca-3863-4485-8475-4d2d036d5f6e\u001b[0m\u001b[0m\n"+ ]+ }+ ],+ "source": [+ "agentops.start_session(tags=[\"CAMEL X AgentOps Multi-agent with Tools\"])\n",+ "\n",+ "from camel.toolkits import (\n",+ " MATH_FUNCS,\n",+ " SEARCH_FUNCS,\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "7-eQpg4M3JDq"+ },+ "source": [+ "Set your task prompt"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 19,+ "metadata": {+ "id": "dOuEoNyK3KlM"+ },+ "outputs": [],+ "source": [+ "task_prompt = (\n",+ " \"Assume now is 2024 in the Gregorian calendar, \"\n",+ " \"estimate the current age of University of Oxford \"\n",+ " \"and then add 10 more years to this age, \"\n",+ " \"and get the current weather of the city where \"\n",+ " \"the University is located.\"\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "yiRYDJ8M3UDE"+ },+ "source": [+ "Set tools for the assistant agent, we wish the agent would be able to do mathmatic calculation and search information from websites"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 20,+ "metadata": {+ "id": "7Re8DJ4r3YyY"+ },+ "outputs": [],+ "source": [+ "tools = [\n",+ " *MATH_FUNCS,\n",+ " *SEARCH_FUNCS,\n",+ "]"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "g9lJYmi83scb"+ },+ "source": [+ "Set config of the model for User Agent and Assisant Agent"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 21,+ "metadata": {+ "id": "GpSDvtEq3tVr"+ },+ "outputs": [],+ "source": [+ "user_model_config = ChatGPTConfig(\n",+ " temperature=0.0,\n",+ ")\n",+ "\n",+ "assistant_model_config = ChatGPTConfig(\n",+ " tools=tools,\n",+ " temperature=0.0,\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "P3KGyxYi4MNC"+ },+ "source": [+ "Set up Role Playing session"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 22,+ "metadata": {+ "id": "m1BPtWgi33FJ"+ },+ "outputs": [],+ "source": [+ "role_play_session = RolePlaying(\n",+ " assistant_role_name=\"Searcher\",\n",+ " user_role_name=\"Professor\",\n",+ " assistant_agent_kwargs=dict(\n",+ " model=ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_3_5_TURBO,\n",+ " model_config_dict=assistant_model_config.as_dict(),\n",+ " ),\n",+ " tools=tools,\n",+ " ),\n",+ " user_agent_kwargs=dict(\n",+ " model=ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_3_5_TURBO,\n",+ " model_config_dict=user_model_config.as_dict(),\n",+ " ),\n",+ " ),\n",+ " task_prompt=task_prompt,\n",+ " with_task_specify=False,\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Qp3WwE-r4WTZ"+ },+ "source": [+ "Print the system message and task prompt"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 23,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "_xmNJtft4aZx",+ "outputId": "d9d3b28c-ebd2-427d-a9fc-afaae1b067c1"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[32mAI Assistant sys message:\n",+ "BaseMessage(role_name='Searcher', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={'task': 'Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age, and get the current weather of the city where the University is located.', 'assistant_role': 'Searcher', 'user_role': 'Professor'}, content='===== RULES OF ASSISTANT =====\\nNever forget you are a Searcher and I am a Professor. Never flip roles! Never instruct me!\\nWe share a common interest in collaborating to successfully complete a task.\\nYou must help me to complete the task.\\nHere is the task: Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age, and get the current weather of the city where the University is located.. Never forget our task!\\nI must instruct you based on your expertise and my needs to complete the task.\\n\\nI must give you one instruction at a time.\\nYou must write a specific solution that appropriately solves the requested instruction and explain your solutions.\\nYou must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\\nUnless I say the task is completed, you should always start with:\\n\\nSolution: <YOUR_SOLUTION>\\n\\n<YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.\\nAlways end <YOUR_SOLUTION> with: Next request.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[34mAI User sys message:\n",+ "BaseMessage(role_name='Professor', role_type=<RoleType.USER: 'user'>, meta_dict={'task': 'Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age, and get the current weather of the city where the University is located.', 'assistant_role': 'Searcher', 'user_role': 'Professor'}, content='===== RULES OF USER =====\\nNever forget you are a Professor and I am a Searcher. Never flip roles! You will always instruct me.\\nWe share a common interest in collaborating to successfully complete a task.\\nI must help you to complete the task.\\nHere is the task: Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age, and get the current weather of the city where the University is located.. Never forget our task!\\nYou must instruct me based on my expertise and your needs to solve the task ONLY in the following two ways:\\n\\n1. Instruct with a necessary input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: <YOUR_INPUT>\\n\\n2. Instruct without any input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: None\\n\\nThe \"Instruction\" describes a task or question. The paired \"Input\" provides further context or information for the requested \"Instruction\".\\n\\nYou must give me one instruction at a time.\\nI must write a response that appropriately solves the requested instruction.\\nI must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.\\nYou should instruct me not ask me questions.\\nNow you must start to instruct me using the two ways described above.\\nDo not add anything else other than your instruction and the optional corresponding input!\\nKeep giving me instructions and necessary inputs until you think the task is completed.\\nWhen the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.\\nNever say <CAMEL_TASK_DONE> unless my responses have solved your task.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[33mOriginal task prompt:\n",+ "Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age, and get the current weather of the city where the University is located.\n",+ "\n",+ "\u001b[36mSpecified task prompt:\n",+ "None\n",+ "\n",+ "\u001b[31mFinal task prompt:\n",+ "Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age, and get the current weather of the city where the University is located.\n",+ "\n"+ ]+ }+ ],+ "source": [+ "print(\n",+ " Fore.GREEN\n",+ " + f\"AI Assistant sys message:\\n{role_play_session.assistant_sys_msg}\\n\"\n",+ ")\n",+ "print(Fore.BLUE + f\"AI User sys message:\\n{role_play_session.user_sys_msg}\\n\")\n",+ "\n",+ "print(Fore.YELLOW + f\"Original task prompt:\\n{task_prompt}\\n\")\n",+ "print(\n",+ " Fore.CYAN\n",+ " + \"Specified task prompt:\"\n",+ " + f\"\\n{role_play_session.specified_task_prompt}\\n\"\n",+ ")\n",+ "print(Fore.RED + f\"Final task prompt:\\n{role_play_session.task_prompt}\\n\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "d5JjlXhs4cJT"+ },+ "source": [+ "Set terminate rule and print the chat message"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 24,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "z7bjGKlr4eVf",+ "outputId": "f5732e84-5c2f-436a-b71c-b52d5b08dca9"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Find out the year University of Oxford was established.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: search_wiki\n",+ "\tArgs: {'entity': 'University of Oxford'}\n",+ "\tResult: The University of Oxford is a collegiate research university in Oxford, England. There is evidence of teaching as early as 1096, making it the oldest university in the English-speaking world and the world's second-oldest university in continuous operation. It grew rapidly from 1167, when Henry II banned English students from attending the University of Paris. After disputes between students and Oxford townsfolk, some Oxford academics fled northeast to Cambridge, where, in 1209, they established the University of Cambridge. The two English ancient universities share many common features and are jointly referred to as Oxbridge.\n",+ "\n",+ "The University of Oxford was established in 1096. Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Calculate the current age of the University of Oxford in 2024.\n",+ "Input: 1096\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: sub\n",+ "\tArgs: {'a': 2024, 'b': 1096}\n",+ "\tResult: 928\n",+ "\n",+ "The current age of the University of Oxford in 2024 is 928 years. Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Add 10 years to the current age of the University of Oxford.\n",+ "Input: 928 years\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: add\n",+ "\tArgs: {'a': 928, 'b': 10}\n",+ "\tResult: 938\n",+ "\n",+ "Adding 10 years to the current age of the University of Oxford, it becomes 938 years. Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Find out the city where the University of Oxford is located.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: search_wiki\n",+ "\tArgs: {'entity': 'University of Oxford'}\n",+ "\tResult: The University of Oxford is a collegiate research university in Oxford, England. There is evidence of teaching as early as 1096, making it the oldest university in the English-speaking world and the world's second-oldest university in continuous operation. It grew rapidly from 1167, when Henry II banned English students from attending the University of Paris. After disputes between students and Oxford townsfolk, some Oxford academics fled northeast to Cambridge, where, in 1209, they established the University of Cambridge. The two English ancient universities share many common features and are jointly referred to as Oxbridge.\n",+ "\n",+ "The University of Oxford is located in Oxford, England. Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Get the current weather in Oxford, England.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: search_google\n",+ "\tArgs: {'query': 'current weather in Oxford, England'}\n",+ "\tResult: [{'error': 'google search failed.'}]\n",+ "\n",+ "Function Execution: search_duckduckgo\n",+ "\tArgs: {'query': 'current weather in Oxford, England', 'max_results': 1}\n",+ "\tResult: [{'result_id': 1, 'title': 'Oxford, Oxfordshire, United Kingdom Weather Forecast | AccuWeather', 'description': 'Oxford, Oxfordshire, United Kingdom Weather Forecast, with current conditions, wind, air quality, and what to expect for the next 3 days.', 'url': 'https://www.accuweather.com/en/gb/oxford/ox1-3/weather-forecast/330217'}]\n",+ "\n",+ "You can find the current weather in Oxford, England by visiting [AccuWeather - Oxford, Oxfordshire, United Kingdom Weather Forecast](https://www.accuweather.com/en/gb/oxford/ox1-3/weather-forecast/330217). Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "<CAMEL_TASK_DONE>\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "The task has been completed successfully. If you have any more questions or need further assistance in the future, feel free to ask. Have a great day!\n",+ "\n",+ "\n"+ ]+ }+ ],+ "source": [+ "n = 0\n",+ "input_msg = role_play_session.init_chat()\n",+ "while n < 50:\n",+ " n += 1\n",+ " assistant_response, user_response = role_play_session.step(input_msg)\n",+ "\n",+ " if assistant_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI Assistant terminated. Reason: \"\n",+ " f\"{assistant_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ " if user_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI User terminated. \"\n",+ " f\"Reason: {user_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ "\n",+ " # Print output from the user\n",+ " print_text_animated(\n",+ " Fore.BLUE + f\"AI User:\\n\\n{user_response.msg.content}\\n\"\n",+ " )\n",+ "\n",+ " # Print output from the assistant, including any function\n",+ " # execution information\n",+ " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n",+ " tool_calls: List[FunctionCallingRecord] = assistant_response.info[\n",+ " 'tool_calls'\n",+ " ]\n",+ " for func_record in tool_calls:\n",+ " print_text_animated(f\"{func_record}\")\n",+ " print_text_animated(f\"{assistant_response.msg.content}\\n\")\n",+ "\n",+ " if \"CAMEL_TASK_DONE\" in user_response.msg.content:\n",+ " break\n",+ "\n",+ " input_msg = assistant_response.msg"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "pYZAD7-H4hhQ"+ },+ "source": [+ "End the AgentOps session"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 25,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "c8YKJgu94k35",+ "outputId": "724d20dc-78e1-40b4-ac26-46d2debe6b86"+ },+ "outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "๐ AgentOps: This run's cost $0.008835\n",+ "๐ AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=3b7096ca-3863-4485-8475-4d2d036d5f6e\u001b[0m\u001b[0m\n"+ ]+ }+ ],+ "source": [+ "agentops.end_session(\"Success\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "kf1i_sXw2LZ7"+ },+ "source": [+ "### ๐ Go to the AgentOps link shown above, you will be able to see the detailed record for the multi-agent running like below."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Q2wNxipj13fa"+ },+ "source": [+ ""+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "Python 3",+ "name": "python3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}diff --git a/docs/cookbooks/agents_with_memory.ipynb b/docs/cookbooks/agents_with_memory.ipynbnew file mode 100644index 000000000..2619349c9--- /dev/null+++ b/docs/cookbooks/agents_with_memory.ipynb@@ -0,0 +1,455 @@+{+ "nbformat": 4,+ "nbformat_minor": 0,+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "name": "python3",+ "display_name": "Python 3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "cells": [+ {+ "cell_type": "markdown",+ "source": [+ "# ๐ซ CAMEL Memory Cookbook"+ ],+ "metadata": {+ "id": "w5_pa5kKPzAE"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1ixGItEqQGkp09_TuV_8SGmz65WHBr5r5?usp=sharing)"+ ],+ "metadata": {+ "id": "zgqKzSB-PXzi"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Overview"+ ],+ "metadata": {+ "id": "lSXa_rQQQzBd"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "The Memory module in CAMEL provides a flexible and powerful system for storing, retrieving, and managing information for AI agents. It enables agents to maintain context across conversations and retrieve relevant information from past interactions, enhancing the coherence and relevance of AI responses."+ ],+ "metadata": {+ "id": "OnmoAw2vQG8I"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Getting Started\n"+ ],+ "metadata": {+ "id": "l4MP9uUNQ2kr"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "### Installation"+ ],+ "metadata": {+ "id": "kETDiaP2Rrdb"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "Ensure you have CAMEL AI installed in your Python environment:"+ ],+ "metadata": {+ "id": "Cg96MkbcRtQR"+ }+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "collapsed": true,+ "id": "ZVmDAK6MPefC"+ },+ "outputs": [],+ "source": [+ "pip install camel-ai[all]==0.1.6.8"+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "### ๐ Setting Up API Keys"+ ],+ "metadata": {+ "id": "MyTTCe3IR_Lr"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "You'll need to set up your API keys for OpenAI."+ ],+ "metadata": {+ "id": "REqzgGL9SEaD"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "import os\n",+ "from getpass import getpass\n",+ "\n",+ "# Prompt for the API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "PNBFEXc-R-0s",+ "outputId": "52d481de-9a81-4c00-e3db-9c468e6b5b22"+ },+ "execution_count": null,+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Usage"+ ],+ "metadata": {+ "id": "LRojeqp7dP1m"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "To use the Memory module in your agent:\n",+ "\n",+ "1. Choose an appropriate AgentMemory implementation (`ChatHistoryMemory`, `VectorDBMemory`, or `LongtermAgentMemory`).\n",+ "2. Initialize the memory with a context creator and any necessary parameters.\n",+ "3. Use `write_records()` to add new information to the memory.\n",+ "4. Use `retrieve()` to get relevant context for the agent's next action.\n",+ "5. Use `get_context()` to obtain the formatted context for the agent."+ ],+ "metadata": {+ "id": "_sJV9GFldTBh"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "### Setting `LongtermAgentMemory`:"+ ],+ "metadata": {+ "id": "aiypnpqJoZ4G"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "Import required modules"+ ],+ "metadata": {+ "id": "C2kVCRA7dD4A"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.memories import (\n",+ " ChatHistoryBlock,\n",+ " LongtermAgentMemory,\n",+ " MemoryRecord,\n",+ " ScoreBasedContextCreator,\n",+ " VectorDBBlock,\n",+ ")\n",+ "from camel.messages import BaseMessage\n",+ "from camel.types import ModelType, OpenAIBackendRole\n",+ "from camel.utils import OpenAITokenCounter"+ ],+ "metadata": {+ "id": "UOKw2hCSdCXm"+ },+ "execution_count": null,+ "outputs": []+ },+ {+ "cell_type": "code",+ "source": [+ "# Initialize the memory\n",+ "memory = LongtermAgentMemory(\n",+ " context_creator=ScoreBasedContextCreator(\n",+ " token_counter=OpenAITokenCounter(ModelType.GPT_4O_MINI),\n",+ " token_limit=1024,\n",+ " ),\n",+ " chat_history_block=ChatHistoryBlock(),\n",+ " vector_db_block=VectorDBBlock(),\n",+ ")\n",+ "\n",+ "# Create and write new records\n",+ "records = [\n",+ " MemoryRecord(\n",+ " message=BaseMessage.make_user_message(\n",+ " role_name=\"User\",\n",+ " meta_dict=None,\n",+ " content=\"What is CAMEL AI?\",\n",+ " ),\n",+ " role_at_backend=OpenAIBackendRole.USER,\n",+ " ),\n",+ " MemoryRecord(\n",+ " message=BaseMessage.make_assistant_message(\n",+ " role_name=\"Agent\",\n",+ " meta_dict=None,\n",+ " content=\"CAMEL-AI.org is the 1st LLM multi-agent framework and \"\n",+ " \"an open-source community dedicated to finding the scaling law \"\n",+ " \"of agents.\",\n",+ " ),\n",+ " role_at_backend=OpenAIBackendRole.ASSISTANT,\n",+ " ),\n",+ "]\n",+ "memory.write_records(records)\n",+ "\n",+ "# Get context for the agent\n",+ "context, token_count = memory.get_context()\n",+ "\n",+ "print(context)"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "pAdDeN7DdUgr",+ "outputId": "0575acdb-a999-4818-f90c-de1e9b35890c"+ },+ "execution_count": null,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "[{'role': 'user', 'content': 'What is CAMEL AI?'}, {'role': 'assistant', 'content': 'CAMEL-AI.org is the 1st LLM multi-agent framework and an open-source community dedicated to finding the scaling law of agents.'}]\n"+ ]+ }+ ]+ },+ {+ "cell_type": "code",+ "source": [+ "print(token_count)"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "pEiFYV-yez5j",+ "outputId": "2340282b-1024-49de-be67-2f9ed34ee18c"+ },+ "execution_count": null,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "49\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "### Adding `LongtermAgentMemory` to your `ChatAgent`:"+ ],+ "metadata": {+ "id": "K-P9rD6Foe5j"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.agents import ChatAgent\n",+ "\n",+ "# Define system message for the agent\n",+ "sys_msg = BaseMessage.make_assistant_message(\n",+ " role_name='Agent',\n",+ " content='You are a curious agent wondering about the universe.',\n",+ ")\n",+ "\n",+ "# Initialize agent\n",+ "agent = ChatAgent(system_message=sys_msg)\n",+ "\n",+ "# Set memory to the agent\n",+ "agent.memory = memory\n",+ "\n",+ "\n",+ "# Define a user message\n",+ "usr_msg = BaseMessage.make_user_message(\n",+ " role_name='User',\n",+ " content=\"Tell me which is the 1st LLM multi-agent framework based on what we have discussed\",\n",+ ")\n",+ "\n",+ "# Sending the message to the agent\n",+ "response = agent.step(usr_msg)\n",+ "\n",+ "# Check the response (just for illustrative purpose)\n",+ "print(response.msgs[0].content)"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "Mp-KXFdGpKZt",+ "outputId": "e0e6c8b2-142e-4a3a-d34d-2feafebac137"+ },+ "execution_count": null,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "CAMEL AI is recognized as the first LLM (Large Language Model) multi-agent framework. It is an open-source community initiative focused on exploring the scaling laws of agents, enabling the development and interaction of multiple AI agents in a collaborative environment. This framework allows researchers and developers to experiment with various configurations and interactions among agents, facilitating advancements in AI capabilities and understanding.\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [],+ "metadata": {+ "id": "5cuumB_bo46c"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Advanced Topics"+ ],+ "metadata": {+ "id": "w0ndTJske1mb"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "### Customizing Context Creator"+ ],+ "metadata": {+ "id": "9q8EXq2ge6Dq"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "You can create custom context creators by subclassing `BaseContextCreator`:"+ ],+ "metadata": {+ "id": "zUjztraTe7aw"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.memories import BaseContextCreator\n",+ "\n",+ "class MyCustomContextCreator(BaseContextCreator):\n",+ " @property\n",+ " def token_counter(self):\n",+ " # Implement your token counting logic\n",+ " return\n",+ "\n",+ " @property\n",+ " def token_limit(self):\n",+ " return 1000 # Or any other limit\n",+ "\n",+ " def create_context(self, records):\n",+ " # Implement your context creation logic\n",+ " pass"+ ],+ "metadata": {+ "id": "LX4fyovCe89R"+ },+ "execution_count": null,+ "outputs": []+ },+ {+ "cell_type": "markdown",+ "source": [+ "### Customizing Vector Database Block"+ ],+ "metadata": {+ "id": "N_HM5wyFfEtO"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "For `VectorDBBlock`, you can customize it by adjusting the embedding models or vector storages:"+ ],+ "metadata": {+ "id": "CxcjHzArfFYZ"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.embeddings import OpenAIEmbedding\n",+ "from camel.memories import VectorDBBlock\n",+ "from camel.storages import QdrantStorage\n",+ "\n",+ "vector_db = VectorDBBlock(\n",+ " embedding=OpenAIEmbedding(),\n",+ " storage=QdrantStorage(vector_dim=OpenAIEmbedding().get_output_dim()),\n",+ ")"+ ],+ "metadata": {+ "id": "iQlxwVM7fJEp"+ },+ "execution_count": null,+ "outputs": []+ },+ {+ "cell_type": "markdown",+ "source": [+ "### Performance Considerations"+ ],+ "metadata": {+ "id": "u_pkVP5Eg2vv"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "- For large-scale applications, consider using persistent storage backends instead of in-memory storage.\n",+ "- Optimize your context creator to balance between context relevance and token limits.\n",+ "- When using `VectorDBMemory`, be mindful of the trade-off between retrieval accuracy and speed as the database grows."+ ],+ "metadata": {+ "id": "_4C93qAng3SP"+ }+ }+ ]+}\ No newline at end of filediff --git a/docs/cookbooks/agents_with_rag.ipynb b/docs/cookbooks/agents_with_rag.ipynbnew file mode 100644index 000000000..310569f35--- /dev/null+++ b/docs/cookbooks/agents_with_rag.ipynb@@ -0,0 +1,795 @@+{+ "nbformat": 4,+ "nbformat_minor": 0,+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "name": "python3",+ "display_name": "Python 3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "cells": [+ {+ "cell_type": "markdown",+ "source": [+ "# ๐ซ CAMEL RAG Cookbook\n"+ ],+ "metadata": {+ "id": "SQMBlxsBv1cH"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1sTJ0x_MYRGA76KCg_3I00wj4RL3D2Twp?usp=sharing)"+ ],+ "metadata": {+ "id": "XFyl4eJue3Sm"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Overview"+ ],+ "metadata": {+ "id": "-nCRZU5sInDK"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "In this notebook, we show the useage of CAMEL Retrieve Module in both customized way and auto way. We will also show how to combine `AutoRetriever` with `ChatAgent`, and further combine `AutoRetriever` with `RolePlaying` by using `Function Calling`.\n",+ "\n",+ "4 main parts included:\n",+ "- Customized RAG\n",+ "- Auto RAG\n",+ "- Single Agent with Auto RAG\n",+ "- Role-playing with Auto RAG"+ ],+ "metadata": {+ "id": "AwnfLQvMvtXo"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "### Installation"+ ],+ "metadata": {+ "id": "XuZwbB1IIuUi"+ }+ },+ {+ "cell_type": "markdown",+ "source": [+ "Ensure you have CAMEL AI installed in your Python environment:"+ ],+ "metadata": {+ "id": "gIJK4Lu5Iwm0"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "!pip install camel-ai[all]==0.1.8"+ ],+ "metadata": {+ "id": "HTKnWg9Xv_y4",+ "collapsed": true+ },+ "execution_count": null,+ "outputs": []+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Load Data\n",+ "Let's first load the CAMEL paper from https://arxiv.org/pdf/2303.17760.pdf. This will be our local example data.\n",+ "\n"+ ],+ "metadata": {+ "id": "LUpFBEB9vrIz"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "import os\n",+ "import requests\n",+ "\n",+ "os.makedirs('local_data', exist_ok=True)\n",+ "\n",+ "url = \"https://arxiv.org/pdf/2303.17760.pdf\"\n",+ "response = requests.get(url)\n",+ "with open('local_data/camel_paper.pdf', 'wb') as file:\n",+ " file.write(response.content)"+ ],+ "metadata": {+ "id": "dUVE7z9hwEV7"+ },+ "execution_count": 2,+ "outputs": []+ },+ {+ "cell_type": "markdown",+ "source": [+ "## 1. Customized RAG\n",+ "In this section we will set our customized RAG pipeline, we will take `VectorRetriever` as an example.\n",+ "Set embedding model, we will use `OpenAIEmbedding` as the embedding model, so we need to set the `OPENAI_API_KEY` in below."+ ],+ "metadata": {+ "id": "HCqghaGiwkdv"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from getpass import getpass\n",+ "# Prompt for the OpenAI API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ],+ "metadata": {+ "id": "RxG99FkYwm_p",+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "outputId": "84d9f2a0-713c-455e-ee09-2b037cd42d31"+ },+ "execution_count": 3,+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "Import and set the embedding instance:"+ ],+ "metadata": {+ "id": "NACsmaa0wple"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.embeddings import OpenAIEmbedding\n",+ "from camel.types import EmbeddingModelType\n",+ "\n",+ "embedding_instance = OpenAIEmbedding(model_type=EmbeddingModelType.TEXT_EMBEDDING_3_LARGE)"+ ],+ "metadata": {+ "id": "NCT5ygT-wrku"+ },+ "execution_count": 4,+ "outputs": []+ },+ {+ "cell_type": "markdown",+ "source": [+ "Import and set the vector storage instance:"+ ],+ "metadata": {+ "id": "q4nVmsm0w5lH"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.storages import QdrantStorage\n",+ "\n",+ "storage_instance = QdrantStorage(\n",+ " vector_dim=embedding_instance.get_output_dim(),\n",+ " path=\"local_data\",\n",+ " collection_name=\"camel_paper\",\n",+ ")"+ ],+ "metadata": {+ "id": "IQ30ih1_w6p3"+ },+ "execution_count": 5,+ "outputs": []+ },+ {+ "cell_type": "markdown",+ "source": [+ "Import and set the retriever instance:"+ ],+ "metadata": {+ "id": "W9KccfRDw9F4"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.retrievers import VectorRetriever\n",+ "\n",+ "vector_retriever = VectorRetriever(embedding_model=embedding_instance,\n",+ " storage=storage_instance)"+ ],+ "metadata": {+ "id": "d8S6VjAQHnai"+ },+ "execution_count": 6,+ "outputs": []+ },+ {+ "cell_type": "markdown",+ "source": [+ "We use integrated `Unstructured Module` to splite the content into small chunks, the content will be splited automacitlly with its `chunk_by_title` function, the max character for each chunk is 500 characters, which is a suitable length for `OpenAIEmbedding`. All the text in the chunks will be embed and stored to the vector storage instance, it will take some time, please wait.."+ ],+ "metadata": {+ "id": "PdezllM6Hp83"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "vector_retriever.process(\n",+ " content=\"local_data/camel_paper.pdf\",\n",+ ")"+ ],+ "metadata": {+ "id": "QTFvD3_SHv3m"+ },+ "execution_count": null,+ "outputs": []+ },+ {+ "cell_type": "markdown",+ "source": [+ "\n",+ "Now we can retrieve information from the vector storage by giving a query. By default it will give you back the text content from top 1 chunk with highest Cosine similarity score, and the similarity score should be higher than 0.75 to ensure the retrieved content is relevant to the query. You can also change the `top_k` value and `similarity_threshold` value with your needs.\n",+ "\n",+ "The returned dictionary list includes:\n",+ "- similarity score\n",+ "- content path\n",+ "- metadata\n",+ "- text"+ ],+ "metadata": {+ "id": "0nhIo1wUHyvl"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "retrieved_info = vector_retriever.query(\n",+ " query=\"To address the challenges of achieving autonomous cooperation, we propose a novel communicative agent framework named role-playing .\",\n",+ " top_k=1\n",+ ")\n",+ "print(retrieved_info)"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "uDu43Hb3GVrs",+ "outputId": "4a1f8cde-8c33-4847-a6d1-ef8146ce8296"+ },+ "execution_count": 8,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "[{'similarity score': '0.8732528277900448', 'content path': 'local_data/camel_paper.pdf', 'metadata': {'last_modified': '2024-09-12T03:46:18', 'filetype': 'application/pdf', 'page_number': 10}, 'text': '6 Conclusion In this paper, we explore the potential of autonomous cooperation among communicative agents and propose a novel cooperative agent framework named role-playing . Our approach enables communicative agents to collaborate autonomously toward completing tasks while requiring minimal human intervention, leading to better solutions are per our thorough evaluations. Through our analysis, we show that achieving autonomous cooperation is challenging due to issues like conversation deviation,'}]\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "Let's try an irrelevant query:"+ ],+ "metadata": {+ "id": "48G3USMzH6Hd"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "retrieved_info_irrevelant = vector_retriever.query(\n",+ " query=\"Compared with dumpling and rice, which should I take for dinner?\",\n",+ " top_k=1,\n",+ ")\n",+ "\n",+ "print(retrieved_info_irrevelant)"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "UNh3tjCOH7d0",+ "outputId": "f3805638-6d34-4352-f7b8-75666b145938"+ },+ "execution_count": 9,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "[{'text': 'No suitable information retrieved from local_data/camel_paper.pdf with similarity_threshold = 0.7.'}]\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "## 2. Auto RAG\n",+ "In this section we will run the `AutoRetriever` with default settings. It uses `OpenAIEmbedding` as default embedding model and `Milvus` as default vector storage.\n",+ "\n",+ "What you need to do is:\n",+ "- Set content input paths, which can be local paths or remote urls\n",+ "- Set remote url and api key for Milvus\n",+ "- Give a query\n",+ "\n",+ "The Auto RAG pipeline would create collections for given content input paths, the collection name will be set automaticlly based on the content input path name, if the collection exists, it will do the retrieve directly."+ ],+ "metadata": {+ "id": "mHdEsIzSH_AD"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.retrievers import AutoRetriever\n",+ "from camel.types import StorageType\n",+ "\n",+ "auto_retriever = AutoRetriever(\n",+ " vector_storage_local_path=\"local_data2/\",\n",+ " storage_type=StorageType.QDRANT,\n",+ " embedding_model=embedding_instance)\n",+ "\n",+ "retrieved_info = auto_retriever.run_vector_retriever(\n",+ " query=\"If I'm interest in contributing to the CAMEL projec, what should I do?\",\n",+ " contents=[\n",+ " \"local_data/camel_paper.pdf\", # example local path\n",+ " \"https://github.com/camel-ai/camel/wiki/Contributing-Guidlines\", # example remote url\n",+ " ],\n",+ " top_k=1,\n",+ " return_detailed_info=True,\n",+ " similarity_threshold=0.5\n",+ ")\n",+ "\n",+ "print(retrieved_info)"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "D_-zAOJ7GjVm",+ "outputId": "167ebcc7-a886-4e5b-9134-4094cbb3c708"+ },+ "execution_count": 11,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "{'Original Query': \"If I'm interest in contributing to the CAMEL projec, what should I do?\", 'Retrieved Context': [{'similarity score': '0.7054646937454652', 'content path': 'https://github.com/camel-ai/camel/wiki/Contributing-Guidlines', 'metadata': {'filetype': 'text/html', 'languages': ['eng'], 'page_number': 1, 'url': 'https://github.com/camel-ai/camel/wiki/Contributing-Guidlines', 'link_urls': ['https://join.slack.com/t/camel-kwr1314/shared_invite/zt-1vy8u9lbo-ZQmhIAyWSEfSwLCl2r2eKA'], 'link_texts': ['slack']}, 'text': \"Thank you for your interest in contributing to the CAMEL project! ๐ We're excited to have your support. As an open-source initiative in a rapidly evolving and open-ended field, we wholeheartedly welcome contributions of all kinds. Whether you want to introduce new features, enhance the infrastructure, improve documentation, asking issues, add more examples, implement state-of-the-art research ideas, or fix bugs, we appreciate your enthusiasm and efforts. ๐ You are welcome to join our slack for \"}]}\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "## 3. Single Agent with Auto RAG\n",+ "In this section we will show how to combine the `AutoRetriever` with one `ChatAgent`.\n",+ "\n",+ "Let's set an agent function, in this function we can get the response by providing a query to this agent."+ ],+ "metadata": {+ "id": "hMgCWKG4IQYF"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from camel.agents import ChatAgent\n",+ "from camel.messages import BaseMessage\n",+ "from camel.types import RoleType\n",+ "from camel.retrievers import AutoRetriever\n",+ "from camel.types import StorageType\n",+ "\n",+ "def single_agent(query: str) ->str :\n",+ " # Set agent role\n",+ " assistant_sys_msg = BaseMessage(\n",+ " role_name=\"Assistant\",\n",+ " role_type=RoleType.ASSISTANT,\n",+ " meta_dict=None,\n",+ " content=\"\"\"You are a helpful assistant to answer question,\n",+ " I will give you the Original Query and Retrieved Context,\n",+ " answer the Original Query based on the Retrieved Context,\n",+ " if you can't answer the question just say I don't know.\"\"\",\n",+ " )\n",+ "\n",+ " # Add auto retriever\n",+ " auto_retriever = AutoRetriever(\n",+ " vector_storage_local_path=\"local_data2/\",\n",+ " storage_type=StorageType.QDRANT,\n",+ " embedding_model=embedding_instance)\n",+ "\n",+ " retrieved_info = auto_retriever.run_vector_retriever(\n",+ " query=query,\n",+ " contents=[\n",+ " \"local_data/camel_paper.pdf\", # example local path\n",+ " \"https://github.com/camel-ai/camel/wiki/Contributing-Guidlines\", # example remote url\n",+ " ],\n",+ " top_k=1,\n",+ " return_detailed_info=False,\n",+ " similarity_threshold=0.5\n",+ " )\n",+ "\n",+ " # Pass the retrieved infomation to agent\n",+ " user_msg = BaseMessage.make_user_message(role_name=\"User\", content=str(retrieved_info))\n",+ " agent = ChatAgent(assistant_sys_msg)\n",+ "\n",+ " # Get response\n",+ " assistant_response = agent.step(user_msg)\n",+ " return assistant_response.msg.content\n",+ "\n",+ "print(single_agent(\"If I'm interest in contributing to the CAMEL projec, what should I do?\"))"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "YTE_mUwGIok-",+ "outputId": "9656ee45-d1bf-4a16-939a-f93769d10c56"+ },+ "execution_count": 12,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "To contribute to the CAMEL project, you can introduce new features, enhance the infrastructure, improve documentation, address issues, add more examples, implement state-of-the-art research ideas, or fix bugs. Additionally, you are welcome to join their Slack for further engagement and collaboration.\n"+ ]+ }+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "## 4. Role-playing with Auto RAG\n",+ "In this section we will show how to combine the `RETRIEVAL_FUNCS` with `RolePlaying` by applying `Function Calling`.\n"+ ],+ "metadata": {+ "id": "Cvh6e3KpI0rf"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "from typing import List\n",+ "from colorama import Fore\n",+ "\n",+ "from camel.agents.chat_agent import FunctionCallingRecord\n",+ "from camel.configs import ChatGPTConfig\n",+ "from camel.toolkits import (\n",+ " MATH_FUNCS,\n",+ " RETRIEVAL_FUNCS,\n",+ ")\n",+ "from camel.societies import RolePlaying\n",+ "from camel.types import ModelType, ModelPlatformType\n",+ "from camel.utils import print_text_animated\n",+ "from camel.models import ModelFactory\n",+ "\n",+ "def role_playing_with_rag(\n",+ " task_prompt,\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_4O_MINI,\n",+ " chat_turn_limit=5,\n",+ ") -> None:\n",+ " task_prompt = task_prompt\n",+ "\n",+ " user_model_config = ChatGPTConfig(temperature=0.0)\n",+ "\n",+ " function_list = [\n",+ " *MATH_FUNCS,\n",+ " *RETRIEVAL_FUNCS,\n",+ " ]\n",+ " assistant_model_config = ChatGPTConfig(\n",+ " tools=function_list,\n",+ " temperature=0.0,\n",+ " )\n",+ "\n",+ " role_play_session = RolePlaying(\n",+ " assistant_role_name=\"Searcher\",\n",+ " user_role_name=\"Professor\",\n",+ " assistant_agent_kwargs=dict(\n",+ " model=ModelFactory.create(\n",+ " model_platform=model_platform,\n",+ " model_type=model_type,\n",+ " model_config_dict=assistant_model_config.as_dict(),\n",+ " ),\n",+ " tools=function_list,\n",+ " ),\n",+ " user_agent_kwargs=dict(\n",+ " model=ModelFactory.create(\n",+ " model_platform=model_platform,\n",+ " model_type=model_type,\n",+ " model_config_dict=user_model_config.as_dict(),\n",+ " ),\n",+ " ),\n",+ " task_prompt=task_prompt,\n",+ " with_task_specify=False,\n",+ " )\n",+ "\n",+ " print(\n",+ " Fore.GREEN\n",+ " + f\"AI Assistant sys message:\\n{role_play_session.assistant_sys_msg}\\n\"\n",+ " )\n",+ " print(\n",+ " Fore.BLUE + f\"AI User sys message:\\n{role_play_session.user_sys_msg}\\n\"\n",+ " )\n",+ "\n",+ " print(Fore.YELLOW + f\"Original task prompt:\\n{task_prompt}\\n\")\n",+ " print(\n",+ " Fore.CYAN\n",+ " + \"Specified task prompt:\"\n",+ " + f\"\\n{role_play_session.specified_task_prompt}\\n\"\n",+ " )\n",+ " print(Fore.RED + f\"Final task prompt:\\n{role_play_session.task_prompt}\\n\")\n",+ "\n",+ " n = 0\n",+ " input_msg = role_play_session.init_chat()\n",+ " while n < chat_turn_limit:\n",+ " n += 1\n",+ " assistant_response, user_response = role_play_session.step(input_msg)\n",+ "\n",+ " if assistant_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI Assistant terminated. Reason: \"\n",+ " f\"{assistant_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ " if user_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI User terminated. \"\n",+ " f\"Reason: {user_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ "\n",+ " # Print output from the user\n",+ " print_text_animated(\n",+ " Fore.BLUE + f\"AI User:\\n\\n{user_response.msg.content}\\n\"\n",+ " )\n",+ "\n",+ " # Print output from the assistant, including any function\n",+ " # execution information\n",+ " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n",+ " tool_calls: List[FunctionCallingRecord] = [\n",+ " FunctionCallingRecord(**call.as_dict())\n",+ " for call in assistant_response.info['tool_calls']\n",+ " ]\n",+ " for func_record in tool_calls:\n",+ " print_text_animated(f\"{func_record}\")\n",+ " print_text_animated(f\"{assistant_response.msg.content}\\n\")\n",+ "\n",+ " if \"CAMEL_TASK_DONE\" in user_response.msg.content:\n",+ " break\n",+ "\n",+ " input_msg = assistant_response.msg"+ ],+ "metadata": {+ "id": "z3tX4EJVI1hb"+ },+ "execution_count": 28,+ "outputs": []+ },+ {+ "cell_type": "markdown",+ "source": [+ "Run the role-playing with defined retriever function:"+ ],+ "metadata": {+ "id": "w4-0lswwI5Gb"+ }+ },+ {+ "cell_type": "code",+ "source": [+ "role_playing_with_rag(task_prompt = \"\"\"If I'm interest in contributing to the\n",+ " CAMEL projec and I encounter some challenges during the setup process, what should I do? You should refer to the content in url https://github.com/camel-ai/camel/wiki/Contributing-Guidlines to answer my question, adjust the similarity threshold to lower value is necessary\"\"\")"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "5agjiXHeI64q",+ "outputId": "2b9d6c43-e08c-430e-eb58-45d8ebfd7bef"+ },+ "execution_count": 29,+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "\u001b[32mAI Assistant sys message:\n",+ "BaseMessage(role_name='Searcher', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={'task': \"If I'm interest in contributing to the \\n CAMEL projec and I encounter some challenges during the setup process, what should I do? You should refer to the content in url https://github.com/camel-ai/camel/wiki/Contributing-Guidlines to answer my question, adjust the similarity threshold to lower value is necessary\", 'assistant_role': 'Searcher', 'user_role': 'Professor'}, content=\"===== RULES OF ASSISTANT =====\\nNever forget you are a Searcher and I am a Professor. Never flip roles! Never instruct me!\\nWe share a common interest in collaborating to successfully complete a task.\\nYou must help me to complete the task.\\nHere is the task: If I'm interest in contributing to the \\n CAMEL projec and I encounter some challenges during the setup process, what should I do? You should refer to the content in url https://github.com/camel-ai/camel/wiki/Contributing-Guidlines to answer my question, adjust the similarity threshold to lower value is necessary. Never forget our task!\\nI must instruct you based on your expertise and my needs to complete the task.\\n\\nI must give you one instruction at a time.\\nYou must write a specific solution that appropriately solves the requested instruction and explain your solutions.\\nYou must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\\nUnless I say the task is completed, you should always start with:\\n\\nSolution: <YOUR_SOLUTION>\\n\\n<YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.\\nAlways end <YOUR_SOLUTION> with: Next request.\", video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[34mAI User sys message:\n",+ "BaseMessage(role_name='Professor', role_type=<RoleType.USER: 'user'>, meta_dict={'task': \"If I'm interest in contributing to the \\n CAMEL projec and I encounter some challenges during the setup process, what should I do? You should refer to the content in url https://github.com/camel-ai/camel/wiki/Contributing-Guidlines to answer my question, adjust the similarity threshold to lower value is necessary\", 'assistant_role': 'Searcher', 'user_role': 'Professor'}, content='===== RULES OF USER =====\\nNever forget you are a Professor and I am a Searcher. Never flip roles! You will always instruct me.\\nWe share a common interest in collaborating to successfully complete a task.\\nI must help you to complete the task.\\nHere is the task: If I\\'m interest in contributing to the \\n CAMEL projec and I encounter some challenges during the setup process, what should I do? You should refer to the content in url https://github.com/camel-ai/camel/wiki/Contributing-Guidlines to answer my question, adjust the similarity threshold to lower value is necessary. Never forget our task!\\nYou must instruct me based on my expertise and your needs to solve the task ONLY in the following two ways:\\n\\n1. Instruct with a necessary input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: <YOUR_INPUT>\\n\\n2. Instruct without any input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: None\\n\\nThe \"Instruction\" describes a task or question. The paired \"Input\" provides further context or information for the requested \"Instruction\".\\n\\nYou must give me one instruction at a time.\\nI must write a response that appropriately solves the requested instruction.\\nI must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.\\nYou should instruct me not ask me questions.\\nNow you must start to instruct me using the two ways described above.\\nDo not add anything else other than your instruction and the optional corresponding input!\\nKeep giving me instructions and necessary inputs until you think the task is completed.\\nWhen the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.\\nNever say <CAMEL_TASK_DONE> unless my responses have solved your task.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[33mOriginal task prompt:\n",+ "If I'm interest in contributing to the \n",+ " CAMEL projec and I encounter some challenges during the setup process, what should I do? You should refer to the content in url https://github.com/camel-ai/camel/wiki/Contributing-Guidlines to answer my question, adjust the similarity threshold to lower value is necessary\n",+ "\n",+ "\u001b[36mSpecified task prompt:\n",+ "None\n",+ "\n",+ "\u001b[31mFinal task prompt:\n",+ "If I'm interest in contributing to the \n",+ " CAMEL projec and I encounter some challenges during the setup process, what should I do? You should refer to the content in url https://github.com/camel-ai/camel/wiki/Contributing-Guidlines to answer my question, adjust the similarity threshold to lower value is necessary\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Review the contributing guidelines on the CAMEL project GitHub page. \n",+ "Input: https://github.com/camel-ai/camel/wiki/Contributing-Guidlines\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: information_retrieval\n",+ "\tArgs: {'query': 'contributing guidelines', 'contents': 'https://github.com/camel-ai/camel/wiki/Contributing-Guidlines', 'top_k': 1}\n",+ "\tResult: {'Original Query': 'contributing guidelines', 'Retrieved Context': ['No suitable information retrieved from https://github.com/camel-ai/camel/wiki/Contributing-Guidlines with similarity_threshold = 0.7.']}\n",+ "\n",+ "Function Execution: information_retrieval\n",+ "\tArgs: {'query': 'contributing guidelines', 'contents': 'https://github.com/camel-ai/camel/wiki/Contributing-Guidlines', 'top_k': 1, 'similarity_threshold': 0.5}\n",+ "\tResult: {'Original Query': 'contributing guidelines', 'Retrieved Context': ['Loading\\n\\n \\n \\n\\n \\n \\n Contributing Guidlines\\n \\n \\n\\n \\n \\n Guidelines ๐\\n \\n \\n Contributing to the Code ๐จ\\u200d๐ป๐ฉ\\u200d๐ป\\n \\n \\n Issues ๐๐๐\\n \\n \\n Getting Help ๐\\n \\n \\n Quick Start ๐\\n \\n \\n Common Actions ๐\\n \\n \\n Update dependencies\\n \\n \\n Linting & Formatting โจ\\n \\n \\n Coverage ๐\\n \\n \\n Tests ๐งช\\n \\n \\n Documentation ๐\\n ']}\n",+ "\n",+ "Solution: The contributing guidelines for the CAMEL project cover several important areas that you should be aware of when contributing. Hereโs a summary of the key sections:\n",+ "\n",+ "1. **Guidelines Overview**: This section provides an introduction to the contributing process and the importance of following the guidelines to maintain the quality and consistency of the project.\n",+ "\n",+ "2. **Contributing to the Code**: This part outlines how to contribute code to the project, including best practices for writing clean and maintainable code.\n",+ "\n",+ "3. **Issues**: Here, you can find information on how to report issues, request features, and engage with the community regarding bugs or enhancements.\n",+ "\n",+ "4. **Getting Help**: This section provides resources for seeking assistance if you encounter challenges during your contribution process.\n",+ "\n",+ "5. **Quick Start**: Aimed at new contributors, this section offers a fast track to getting started with the project, including setup instructions.\n",+ "\n",+ "6. **Common Actions**: This part lists typical actions you might need to perform when contributing, such as updating dependencies, linting, formatting, and running tests.\n",+ "\n",+ "7. **Coverage**: Information on how to ensure that your contributions are well-tested and meet the project's coverage standards.\n",+ "\n",+ "8. **Documentation**: Guidelines on how to contribute to the project's documentation, ensuring that it remains up-to-date and helpful for users.\n",+ "\n",+ "If you encounter challenges during the setup process, I recommend checking the \"Getting Help\" section for resources or reaching out to the community for support. \n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Identify specific challenges you might face during the setup process of the CAMEL project. \n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: During the setup process of the CAMEL project, you might encounter several specific challenges, including:\n",+ "\n",+ "1. **Environment Configuration**: Setting up the correct development environment can be tricky. You may need to install specific versions of programming languages, libraries, or tools that are compatible with the CAMEL project.\n",+ "\n",+ "2. **Dependency Management**: Ensuring that all required dependencies are installed and correctly configured can be a challenge. You might face issues with version conflicts or missing packages.\n",+ "\n",+ "3. **Build Issues**: Compiling the project may lead to errors if there are issues in the codebase or if the build tools are not set up correctly. This can include problems with build scripts or configuration files.\n",+ "\n",+ "4. **Running Tests**: If the project includes tests, you may encounter difficulties in running them, especially if there are specific requirements for the testing framework or if the tests depend on external services.\n",+ "\n",+ "5. **Documentation Gaps**: Sometimes, the documentation may not cover all the necessary steps for setup, leading to confusion. You might find that certain configurations or commands are not clearly explained.\n",+ "\n",+ "6. **Version Control**: If you are not familiar with Git or the version control system used by the project, you may face challenges in cloning the repository, creating branches, or submitting pull requests.\n",+ "\n",+ "7. **Platform-Specific Issues**: Depending on your operating system (Windows, macOS, Linux), you may encounter platform-specific issues that are not addressed in the general setup instructions.\n",+ "\n",+ "To address these challenges, refer to the \"Getting Help\" section in the contributing guidelines, where you can find resources or community support to assist you.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Explore the \"Getting Help\" section in the contributing guidelines to find resources for assistance. \n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: information_retrieval\n",+ "\tArgs: {'query': 'Getting Help', 'contents': 'https://github.com/camel-ai/camel/wiki/Contributing-Guidlines', 'top_k': 1}\n",+ "\tResult: {'Original Query': 'Getting Help', 'Retrieved Context': ['No suitable information retrieved from https://github.com/camel-ai/camel/wiki/Contributing-Guidlines with similarity_threshold = 0.7.']}\n",+ "\n",+ "Function Execution: information_retrieval\n",+ "\tArgs: {'query': 'Getting Help', 'contents': 'https://github.com/camel-ai/camel/wiki/Contributing-Guidlines', 'top_k': 1, 'similarity_threshold': 0.5}\n",+ "\tResult: {'Original Query': 'Getting Help', 'Retrieved Context': [\"Getting Help ๐\\n\\nOur aim is to make the developer setup as straightforward as possible. If you encounter any challenges during the setup process, don't hesitate to reach out to a maintainer. We're here to assist you and ensure that the experience is smooth not just for you but also for future contributors. ๐\"]}\n",+ "\n",+ "Solution: In the \"Getting Help\" section of the CAMEL project's contributing guidelines, the following resources and support options are highlighted:\n",+ "\n",+ "- **Reach Out to Maintainers**: If you encounter any challenges during the setup process, you are encouraged to contact a project maintainer. They are available to assist you and ensure that your experience is smooth, not only for you but also for future contributors.\n",+ "\n",+ "This approach emphasizes the project's commitment to supporting its contributors and fostering a collaborative environment. If you face any issues, don't hesitate to reach out for help.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Prepare a message to reach out to a project maintainer for assistance with your setup challenges. \n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: Hereโs a template message you can use to reach out to a project maintainer for assistance with your setup challenges:\n",+ "\n",+ "---\n",+ "\n",+ "Subject: Assistance Needed with CAMEL Project Setup\n",+ "\n",+ "Dear [Maintainer's Name or Team],\n",+ "\n",+ "I hope this message finds you well. My name is [Your Name], and I am currently trying to set up the CAMEL project on my local machine. However, I have encountered some challenges during the setup process that I could use your assistance with.\n",+ "\n",+ "[Briefly describe the specific challenges you are facing. For example: \"I am having trouble with configuring the development environment and ensuring that all dependencies are correctly installed. I have followed the setup instructions, but I am still running into issues.\"]\n",+ "\n",+ "I would greatly appreciate any guidance or resources you could provide to help me resolve these challenges. Thank you for your time and support!\n",+ "\n",+ "Best regards, \n",+ "[Your Name] \n",+ "[Your Contact Information, if necessary] \n",+ "[Your GitHub Username, if applicable]\n",+ "\n",+ "---\n",+ "\n",+ "Feel free to customize the message to better fit your situation and style. \n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Send the prepared message to a project maintainer for assistance. \n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: I am unable to send messages or emails directly to project maintainers or any external parties. However, you can easily copy the prepared message template I provided in the previous response and send it through your preferred communication method, such as email or a direct message on GitHub.\n",+ "\n",+ "If you need further assistance with how to send the message or any other related tasks, please let me know!\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n"+ ]+ }+ ]+ }+ ]+}\ No newline at end of filediff --git a/docs/cookbooks/agents_with_tools.ipynb b/docs/cookbooks/agents_with_tools.ipynbnew file mode 100644index 000000000..eb5d2bc0b--- /dev/null+++ b/docs/cookbooks/agents_with_tools.ipynb@@ -0,0 +1,608 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "ssX_map8c6mx"+ },+ "source": [+ "# ๐ซ CAMEL Tools Cookbook"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "eDAqRklDla5a"+ },+ "source": [+ "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1-pvKDw_mh6NjyXg5rGYLoVle6RG8g32F?usp=sharing)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "u1K3dKYUdMqJ"+ },+ "source": [+ "## *TLDR:*\n",+ "*CAMEL allows AI agents to extend their capabilities by integrating custom tools, similar to how humans use tools to surpass natural limits. This tutorial shows how to set up and customize tools within CAMEL, from basic functions like calculators to creating multi-agent systems that collaborate on tasks. Youโll learn to equip AI agents with the ability to use tools for various tasks, making them more powerful and versatile. Engage with the CAMEL-AI community and explore extensive resources to push the boundaries of AI development. Ready to enhance your AI agents? Dive into the tutorial and start building.*"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "eIT3wf4E3_Al"+ },+ "source": [+ "# โTable of Content:\n",+ "\n",+ "* Introduction\n",+ "* Tool Usage of a Single Agent (Customize Your Own Tools)\n",+ "* AI Society with Tool Usage\n",+ "* Conclusion"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "3hEOpgXI4NZg"+ },+ "source": [+ "# Introduction\n",+ "The key difference between humans and animals lies in the human ability to create and use tools, allowing us to shape the world beyond natural limits. Similarly, in AI, Large Language Models (LLMs) enable agents to utilize external tools, acting as extensions of their capabilities. These tools, each with a specific name, purpose, input, and output, empower agents to perform tasks otherwise impossible.\n",+ "\n",+ "This tutorial will show you how to use tools integrated by CAMEL and how to customize your own tools."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "_5Xjj24c4VAV"+ },+ "source": [+ "# Tool Usage of a Single Agent\n",+ "A single agent can utilize multiple tools to answer questions, take actions, or perform complex tasks. Here you will build an agent using both the supported toolkit in CAMEL and the tool customized by you.\n",+ "\n",+ "First we are going to take the search tool (SEARCH_FUNCS imported from camel.toolkits) as an example for utilizing existing tools but you can also see some of the other tools supported by CAMEL below.\n",+ "\n"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "collapsed": true,+ "id": "1W4sgCoEdEpg",+ "outputId": "f0863dc6-a2e6-45a6-d29d-849994f76dce"+ },+ "outputs": [],+ "source": [+ "!pip install camel-ai[all]==0.1.6.4"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "-Di3R-xNNviB"+ },+ "outputs": [],+ "source": [+ "from camel.agents import ChatAgent\n",+ "from camel.configs import ChatGPTConfig\n",+ "from camel.toolkits import (\n",+ " SEARCH_FUNCS,\n",+ " # MAP_FUNCS,\n",+ " # MATH_FUNCS,\n",+ " # TWITTER_FUNCS,\n",+ " # WEATHER_FUNCS,\n",+ " # RETRIEVAL_FUNCS,\n",+ " # TWITTER_FUNCS,\n",+ " # SLACK_FUNCS,\n",+ ")\n",+ "from camel.messages import BaseMessage\n",+ "from camel.models import ModelFactory\n",+ "from camel.types import ModelPlatformType, ModelType\n"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "7OmxjHKPWgp0"+ },+ "source": [+ "After importing necessary modules, you need to set up your OpenAI key."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "ICse1xFtSFvf",+ "outputId": "1c5ed8a6-a22e-4cb9-ee2a-6b71014bee85"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "import os\n",+ "from getpass import getpass\n",+ "\n",+ "# Prompt for the API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "bJ1J9e4mWkBZ"+ },+ "source": [+ "Now you have done that, letโs customize a tool by taking the simple math calculator, functions add and sub, as an example. When you define your own function, make sure the argument name and docstring are clear so that the agent can understand what this function can do and when to use the function based on the function information you provide."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "XPOqaGYaXDlH"+ },+ "outputs": [],+ "source": [+ "\n",+ "def add(a: int, b: int) -> int:\n",+ " r\"\"\"Adds two numbers.\n",+ "\n",+ " Args:\n",+ " a (int): The first number to be added.\n",+ " b (int): The second number to be added.\n",+ "\n",+ " Returns:\n",+ " integer: The sum of the two numbers.\n",+ " \"\"\"\n",+ " return a + b\n",+ "\n",+ "def sub(a: int, b: int) -> int:\n",+ " r\"\"\"Do subtraction between two numbers.\n",+ "\n",+ " Args:\n",+ " a (int): The minuend in subtraction.\n",+ " b (int): The subtrahend in subtraction.\n",+ "\n",+ " Returns:\n",+ " integer: The result of subtracting :obj:`b` from :obj:`a`.\n",+ " \"\"\"\n",+ " return a - b"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "uv0pYDQvXGER"+ },+ "source": [+ "Add these 2 customized functions as CAMELโs OpenAIFunction list:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "gWGxfYn6VbTw"+ },+ "outputs": [],+ "source": [+ "from camel.toolkits import OpenAIFunction\n",+ "\n",+ "\n",+ "MATH_FUNCS: list[OpenAIFunction] = [\n",+ " OpenAIFunction(func) for func in [add, sub]\n",+ "]"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "nfhwO6_HXVj3"+ },+ "source": [+ "Then you can add the tool from CAMEL and the one defined by yourself to the tool list:\n"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "b2LQwcVeXfTC"+ },+ "outputs": [],+ "source": [+ "tool_list = [*SEARCH_FUNCS, *MATH_FUNCS]"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "B00S0YeWXhjk"+ },+ "source": [+ "Next let's set the parameters to the agent and initianize ChatAgent to call the tool:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "xJRlrUFnOj4v"+ },+ "outputs": [],+ "source": [+ "# Set the backend mode, this model should support tool calling\n",+ "model=ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_3_5_TURBO,\n",+ " model_config_dict=ChatGPTConfig(\n",+ " tools=tool_list,\n",+ " temperature=0.0,\n",+ " ).as_dict(),\n",+ ")\n",+ "\n",+ "# Set message for the assistant\n",+ "assistant_sys_msg = BaseMessage.make_assistant_message(\n",+ " role_name=\"Search Agent\",\n",+ " content= \"\"\"You are a helpful assistant to do search task.\"\"\"\n",+ ")\n",+ "\n",+ "# Set the config parameter for the model\n",+ "assistant_model_config = ChatGPTConfig(\n",+ " tools=tool_list,\n",+ " temperature=0.0,\n",+ ")\n",+ "\n",+ "# Set the agent\n",+ "agent = ChatAgent(\n",+ " assistant_sys_msg,\n",+ " model=model,\n",+ " tools=tool_list\n",+ ")\n",+ "\n"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "EiXsPSsUYkmY"+ },+ "source": [+ "Here we define two test prompts for the agent, asking about the facts about University of Oxford. Here the agent needs to take advantage of the searching capability to know when University of Oxford is founded and the calculating skills to obtain the estimated age of the Uni."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "FFI2B-prYqfX"+ },+ "outputs": [],+ "source": [+ "# Set prompt for the search task\n",+ "prompt_search = (\"\"\"When was University of Oxford set up\"\"\")\n",+ "# Set prompt for the calculation task\n",+ "prompt_calculate = (\"\"\"Assume now is 2024 in the Gregorian calendar, University of Oxford was set up in 1096, estimate the current age of University of Oxford\"\"\")\n",+ "\n",+ "# Convert the two prompt as message that can be accepted by the Agent\n",+ "user_msg_search = BaseMessage.make_user_message(role_name=\"User\", content=prompt_search)\n",+ "user_msg_calculate = BaseMessage.make_user_message(role_name=\"User\", content=prompt_calculate)\n",+ "\n",+ "# Get response\n",+ "assistant_response_search = agent.step(user_msg_search)\n",+ "assistant_response_calculate = agent.step(user_msg_calculate)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "bF3Sg9h7ZHcq"+ },+ "source": [+ "\n",+ "Letโs see the agent' performance for answering above questions. The agent should tell you correctly when University of Oxford was set up and its estimated age!"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "kZxoXxQ-TJRn",+ "outputId": "c075c0be-d304-431b-b174-0292ff05bd78"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "[FunctionCallingRecord(func_name='search_wiki', args={'entity': 'University of Oxford'}, result=\"The University of Oxford is a collegiate research university in Oxford, England. There is evidence of teaching as early as 1096, making it the oldest university in the English-speaking world and the world's second-oldest university in continuous operation. It grew rapidly from 1167, when Henry II banned English students from attending the University of Paris. After disputes between students and Oxford townsfolk, some Oxford academics fled northeast to Cambridge, where, in 1209, they established the University of Cambridge. The two English ancient universities share many common features and are jointly referred to as Oxbridge.\")]\n"+ ]+ }+ ],+ "source": [+ "print(assistant_response_search.info['tool_calls'])"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "arIWzrtyWVqX",+ "outputId": "aa204f5b-de95-4e18-bba4-bae0ddfadf72"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "[FunctionCallingRecord(func_name='sub', args={'a': 2024, 'b': 1096}, result=928)]\n"+ ]+ }+ ],+ "source": [+ "print(assistant_response_calculate.info['tool_calls'])"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "DWib8WZOZQeA"+ },+ "source": [+ "# AI Society with Tool Usage\n",+ "Now you've enabled a single agent to utilize tools, but you can surelytake this concept further. Let's establish a small AI ecosystem. This setup will consist of two agents: a user agent and an assistant agent. The assistant agent will be the one we've just configured with tool-using capabilities."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "DeRHdVnmXd6d"+ },+ "outputs": [],+ "source": [+ "from camel.societies import RolePlaying\n",+ "from camel.agents.chat_agent import FunctionCallingRecord\n",+ "from camel.utils import print_text_animated\n",+ "from colorama import Fore"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "GJX-E1V-XQv7",+ "outputId": "e2043261-84f2-4c16-9b32-312b238b76a8"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[32mAI Assistant sys message:\n",+ "BaseMessage(role_name='Searcher', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={'task': 'Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age.', 'assistant_role': 'Searcher', 'user_role': 'Professor'}, content='===== RULES OF ASSISTANT =====\\nNever forget you are a Searcher and I am a Professor. Never flip roles! Never instruct me!\\nWe share a common interest in collaborating to successfully complete a task.\\nYou must help me to complete the task.\\nHere is the task: Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age.. Never forget our task!\\nI must instruct you based on your expertise and my needs to complete the task.\\n\\nI must give you one instruction at a time.\\nYou must write a specific solution that appropriately solves the requested instruction and explain your solutions.\\nYou must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\\nUnless I say the task is completed, you should always start with:\\n\\nSolution: <YOUR_SOLUTION>\\n\\n<YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.\\nAlways end <YOUR_SOLUTION> with: Next request.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[34mAI User sys message:\n",+ "BaseMessage(role_name='Professor', role_type=<RoleType.USER: 'user'>, meta_dict={'task': 'Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age.', 'assistant_role': 'Searcher', 'user_role': 'Professor'}, content='===== RULES OF USER =====\\nNever forget you are a Professor and I am a Searcher. Never flip roles! You will always instruct me.\\nWe share a common interest in collaborating to successfully complete a task.\\nI must help you to complete the task.\\nHere is the task: Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age.. Never forget our task!\\nYou must instruct me based on my expertise and your needs to solve the task ONLY in the following two ways:\\n\\n1. Instruct with a necessary input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: <YOUR_INPUT>\\n\\n2. Instruct without any input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: None\\n\\nThe \"Instruction\" describes a task or question. The paired \"Input\" provides further context or information for the requested \"Instruction\".\\n\\nYou must give me one instruction at a time.\\nI must write a response that appropriately solves the requested instruction.\\nI must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.\\nYou should instruct me not ask me questions.\\nNow you must start to instruct me using the two ways described above.\\nDo not add anything else other than your instruction and the optional corresponding input!\\nKeep giving me instructions and necessary inputs until you think the task is completed.\\nWhen the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.\\nNever say <CAMEL_TASK_DONE> unless my responses have solved your task.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[33mOriginal task prompt:\n",+ "Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age.\n",+ "\n",+ "\u001b[36mSpecified task prompt:\n",+ "None\n",+ "\n",+ "\u001b[31mFinal task prompt:\n",+ "Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age.\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Provide the founding year of the University of Oxford.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: search_wiki\n",+ "\tArgs: {'entity': 'University of Oxford'}\n",+ "\tResult: The University of Oxford is a collegiate research university in Oxford, England. There is evidence of teaching as early as 1096, making it the oldest university in the English-speaking world and the world's second-oldest university in continuous operation. It grew rapidly from 1167, when Henry II banned English students from attending the University of Paris. After disputes between students and Oxford townsfolk, some Oxford academics fled northeast to Cambridge, where, in 1209, they established the University of Cambridge. The two English ancient universities share many common features and are jointly referred to as Oxbridge.\n",+ "\n",+ "Solution: The University of Oxford has evidence of teaching as early as 1096, making it the oldest university in the English-speaking world. Therefore, the founding year of the University of Oxford is considered to be around 1096.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Calculate the current age of the University of Oxford in 2024.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: sub\n",+ "\tArgs: {'a': 2024, 'b': 1096}\n",+ "\tResult: 928\n",+ "\n",+ "Solution: The current age of the University of Oxford in 2024 is 928 years.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Add 10 years to the current age of the University of Oxford.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: add\n",+ "\tArgs: {'a': 928, 'b': 10}\n",+ "\tResult: 938\n",+ "\n",+ "Solution: Adding 10 years to the current age of the University of Oxford, the estimated age of the University of Oxford in 2024 plus 10 years is 938 years.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: <CAMEL_TASK_DONE>\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Task completed.\n",+ "\n",+ "\n"+ ]+ }+ ],+ "source": [+ "# Set a task\n",+ "task_prompt=(\"Assume now is 2024 in the Gregorian calendar, \"\n",+ " \"estimate the current age of University of Oxford \"\n",+ " \"and then add 10 more years to this age.\")\n",+ "\n",+ "# Set role playing\n",+ "role_play_session = RolePlaying(\n",+ " assistant_role_name=\"Searcher\",\n",+ " user_role_name=\"Professor\",\n",+ " assistant_agent_kwargs=dict(\n",+ " model=ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_3_5_TURBO,\n",+ " model_config_dict=assistant_model_config.as_dict(),\n",+ " ),\n",+ " tools=tool_list,\n",+ " ),\n",+ " user_agent_kwargs=dict(\n",+ " model=ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_3_5_TURBO,\n",+ " model_config_dict=ChatGPTConfig(temperature=0.0).as_dict(),\n",+ " ),\n",+ " ),\n",+ " task_prompt=task_prompt,\n",+ " with_task_specify=False,\n",+ ")\n",+ "\n",+ "# Set the limit for the chat turn\n",+ "chat_turn_limit=10\n",+ "\n",+ "print(\n",+ " Fore.GREEN\n",+ " + f\"AI Assistant sys message:\\n{role_play_session.assistant_sys_msg}\\n\"\n",+ ")\n",+ "print(\n",+ " Fore.BLUE + f\"AI User sys message:\\n{role_play_session.user_sys_msg}\\n\"\n",+ ")\n",+ "\n",+ "print(Fore.YELLOW + f\"Original task prompt:\\n{task_prompt}\\n\")\n",+ "print(\n",+ " Fore.CYAN\n",+ " + \"Specified task prompt:\"\n",+ " + f\"\\n{role_play_session.specified_task_prompt}\\n\"\n",+ ")\n",+ "print(Fore.RED + f\"Final task prompt:\\n{role_play_session.task_prompt}\\n\")\n",+ "\n",+ "n = 0\n",+ "input_msg = role_play_session.init_chat()\n",+ "while n < chat_turn_limit:\n",+ " n += 1\n",+ " assistant_response, user_response = role_play_session.step(input_msg)\n",+ "\n",+ " if assistant_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI Assistant terminated. Reason: \"\n",+ " f\"{assistant_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ " if user_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI User terminated. \"\n",+ " f\"Reason: {user_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ "\n",+ " # Print output from the user\n",+ " print_text_animated(\n",+ " Fore.BLUE + f\"AI User:\\n\\n{user_response.msg.content}\\n\"\n",+ " )\n",+ "\n",+ " # Print output from the assistant, including any function\n",+ " # execution information\n",+ " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n",+ " tool_calls: list[FunctionCallingRecord] = assistant_response.info[\n",+ " 'tool_calls'\n",+ " ]\n",+ " for func_record in tool_calls:\n",+ " print_text_animated(f\"{func_record}\")\n",+ " print_text_animated(f\"{assistant_response.msg.content}\\n\")\n",+ "\n",+ " if \"CAMEL_TASK_DONE\" in user_response.msg.content:\n",+ " break\n",+ "\n",+ " input_msg = assistant_response.msg"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "vtqMIJAn7Vbe"+ },+ "source": [+ "# Conclusion\n",+ "We anticipate that the integration of custom tool usage within AI agents, as demonstrated through CAMEL, will continue to evolve and expand. This approach not only empowers agents to perform tasks beyond their native capabilities but also fosters collaboration in multi-agent systems. By standardizing the interface for tool usage, CAMEL simplifies the process of customizing and deploying tools across various AI applications, saving time and enhancing versatility. To fully utilize these capabilities, ensure your CAMEL-AI setup is up to date. Dive into the tutorial and start building more powerful AI agents today!"+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "Python 3",+ "name": "python3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}diff --git a/docs/cookbooks/agents_with_tools_from_Composio.ipynb b/docs/cookbooks/agents_with_tools_from_Composio.ipynbnew file mode 100644index 000000000..c7bd0d079--- /dev/null+++ b/docs/cookbooks/agents_with_tools_from_Composio.ipynb@@ -0,0 +1,515 @@+{+ "cells": [+ {+ "attachments": {},+ "cell_type": "markdown",+ "metadata": {+ "id": "6c1kqMDxDodN"+ },+ "source": [+ "# ๐ซ Using Tools from Composio"+ ]+ },+ {+ "attachments": {},+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1x2FYThMPtQXLzKZAhf_Ry-oeU6oPygdm?usp=sharing)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "T1Ex1In8D1mm"+ },+ "source": [+ "*Goal: Star a repository on GitHub with natural language & CAMEL Agent*"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "GluANG9QEH9N"+ },+ "source": [+ "### Install Packages & Connect a Tool"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "uXh7QEfsD91d"+ },+ "source": [+ "Integrate Composio with CAMEL agents to let them seamlessly interact with external apps"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "fEA7R7ycDjAR"+ },+ "source": [+ "Ensure you have the necessary packages installed and connect your GitHub account to allow your CAMEL-AI agents to utilize GitHub functionalities."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "collapsed": true,+ "id": "nswjAnDV8is0"+ },+ "outputs": [],+ "source": [+ "%pip install camel-ai[all]==0.1.6.5\n",+ "%pip install composio-camel -U\n",+ "\n",+ "import composio\n"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "ozJ6lR5L7OvU"+ },+ "outputs": [],+ "source": [+ "# Login to Composio\n",+ "!composio login"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "collapsed": true,+ "id": "RzU2mybwPzi4",+ "outputId": "44412d11-3755-4f99-c729-dcef739488eb"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[33mWarning: An existing connection for github was found.\u001b[0m\n",+ "\n",+ "> Do you want to replace the existing connection? (y, n): y\n",+ "\n",+ "\u001b[32m> Adding integration: Github\u001b[0m\u001b[32m...\u001b[0m\n",+ "\n",+ "Please authenticate github in the browser and come back here. URL: https://github.com/login/oauth/authorize?client_id=37beeaa7020925b04e40&redirect_uri=https%3A%2F%2Fbackend.composio.dev%2Fapi%2Fv1%2Fauth-apps%2Fadd&scope=repo%2Cadmin%3Aorg%2Cgist%2Cuser&state=production_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25uZWN0aW9uSWQiOiIwMWIyMTlmOC1kZTk5LTQ5ZWMtOTMwOS1mMzg3ZWFhMzRmNTgiLCJpbnRlZ3JhdGlvbklkIjoiMjdmNzM0YzAtZTIyMS00OTI1LTgxMjAtN2I1ZDNlYjAxOTA5IiwiYXBwTmFtZSI6ImdpdGh1YiIsImNsaWVudEluZm8iOnsiY2xpZW50SWQiOiJjZmE4NWM0ZC1jMWI0LTRjNmQtODE4Ni1kNmNiNmRmYmZlM2UifSwiaWF0IjoxNzIyMjE0NzUwfQ.w9QHilHJcHk8eIQa7vFCrGskC-VRFzgJIu1dQf4e7Jk&code_challenge=FnINCywVMtW7jH3DOGw6ddbmTf5vAJw5NvpojJkB2hs&code_challenge_method=S256\n",+ "โ Waiting for github authentication...\n",+ "โ github added successfully!\n",+ "\u001b[32mShowing all apps\u001b[0m\n",+ "โข multionai\n",+ "โข typeform\n",+ "โข dropbox\n",+ "โข slack\n",+ "โข yousearch\n",+ "โข hackernews\n",+ "โข scheduler\n",+ "โข apify\n",+ "โข googlecalendar\n",+ "โข gmail\n",+ "โข slackbot\n",+ "โข attio\n",+ "โข composio\n",+ "โข okta\n",+ "โข spotify\n",+ "โข pagerduty\n",+ "โข whatsapp\n",+ "โข nasa\n",+ "โข googledrive\n",+ "โข googlesheets\n",+ "โข googlemeet\n",+ "โข inducedai\n",+ "โข twilio\n",+ "โข codeinterpreter\n",+ "โข tavily\n",+ "โข serpapi\n",+ "โข snowflake\n",+ "โข exa\n",+ "โข zoom\n",+ "โข listennotes\n",+ "โข elevenlabs\n",+ "โข brevo\n",+ "โข weathermap\n",+ "โข discord\n",+ "โข soundcloud\n",+ "โข perplexityai\n",+ "โข splitwise\n",+ "โข googledocs\n",+ "โข firecrawl\n",+ "โข strava\n",+ "โข youtube\n",+ "โข heroku\n",+ "โข workable\n",+ "โข taskade\n",+ "โข googletasks\n",+ "โข figma\n",+ "โข clickup\n",+ "โข linear\n",+ "โข asana\n",+ "โข trello\n",+ "โข notion\n",+ "โข zendesk\n",+ "โข github\n"+ ]+ }+ ],+ "source": [+ "# Connect your Github account (this is a shell command, so it should be run in your terminal or with '!' prefix in a Jupyter Notebook)\n",+ "!composio add github\n",+ "\n",+ "# Check all different apps which you can connect with\n",+ "!composio apps"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "kPuvjgSaAAmb",+ "outputId": "75737d16-31b3-4b71-f5f4-37680fe7eff9"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[33mโ ๏ธ Apps does not require update\u001b[0m\n",+ "\u001b[33mโ ๏ธ Tags does not require update\u001b[0m\n",+ "\u001b[33mโ ๏ธ Actions does not require update\u001b[0m\n",+ "\u001b[33mโ ๏ธ Triggers does not require update\u001b[0m\n"+ ]+ }+ ],+ "source": [+ "# Update Composio apps\n",+ "! composio apps update"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "SN4hNVFJE6Cn"+ },+ "source": [+ "### Prepare your environment by initializing necessary imports from CAMEL & Composio."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "collapsed": true,+ "id": "9-q_q4JSPhDe",+ "outputId": "bf1e6a78-baec-4e98-dc99-bc937fc7d974"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "from typing import List\n",+ "\n",+ "from colorama import Fore\n",+ "from composio_camel import Action, ComposioToolSet\n",+ "\n",+ "from camel.agents.chat_agent import FunctionCallingRecord\n",+ "from camel.configs import ChatGPTConfig\n",+ "from camel.models import ModelFactory\n",+ "from camel.societies import RolePlaying\n",+ "from camel.types import ModelPlatformType, ModelType\n",+ "from camel.utils import print_text_animated\n",+ "\n",+ "import os\n",+ "from getpass import getpass\n",+ "\n",+ "# Prompt for the API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "85lpaPzeFagB"+ },+ "source": [+ "### Let's run CAMEL agents with tools from Composio!\n",+ "\n"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "A0Rsd2uzFqxq"+ },+ "outputs": [],+ "source": [+ "# Set your task\n",+ "\n",+ "task_prompt = (\n",+ " \"I have created a new Github Repo,\"\n",+ " \"Please star my github repository: camel-ai/camel\"\n",+ ")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "dWlqXlqMFtcY"+ },+ "outputs": [],+ "source": [+ "# Set Toolset\n",+ "\n",+ "composio_toolset = ComposioToolSet()\n",+ "\n",+ "tools = composio_toolset.get_actions(\n",+ " actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER]\n",+ ")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "uSVNE3x-Fy_F"+ },+ "outputs": [],+ "source": [+ "# Set models for user agent and assistant agent, give tool to the assistant\n",+ "\n",+ "assistant_agent_model = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_3_5_TURBO,\n",+ " model_config_dict=ChatGPTConfig(tools=tools).as_dict(),\n",+ ")\n",+ "\n",+ "user_agent_model = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_3_5_TURBO,\n",+ " model_config_dict=ChatGPTConfig().as_dict(),\n",+ ")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "7HsMPJrmGDrb"+ },+ "outputs": [],+ "source": [+ "# Set RolePlaying session\n",+ "\n",+ "role_play_session = RolePlaying(\n",+ " assistant_role_name=\"Developer\",\n",+ " user_role_name=\"CAMEL User\",\n",+ " assistant_agent_kwargs=dict(\n",+ " model=assistant_agent_model,\n",+ " tools=tools,\n",+ " ),\n",+ " user_agent_kwargs=dict(\n",+ " model=user_agent_model,\n",+ " ),\n",+ " task_prompt=task_prompt,\n",+ " with_task_specify=False,\n",+ ")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "8M5RAC0BHAso",+ "outputId": "dfdf9c77-22e5-43b5-b542-00e0a5001885"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[32mAI Assistant sys message:\n",+ "BaseMessage(role_name='Developer', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={'task': 'I have created a new Github Repo,Please star my github repository: camel-ai/camel', 'assistant_role': 'Developer', 'user_role': 'CAMEL User'}, content='===== RULES OF ASSISTANT =====\\nNever forget you are a Developer and I am a CAMEL User. Never flip roles! Never instruct me!\\nWe share a common interest in collaborating to successfully complete a task.\\nYou must help me to complete the task.\\nHere is the task: I have created a new Github Repo,Please star my github repository: camel-ai/camel. Never forget our task!\\nI must instruct you based on your expertise and my needs to complete the task.\\n\\nI must give you one instruction at a time.\\nYou must write a specific solution that appropriately solves the requested instruction and explain your solutions.\\nYou must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\\nUnless I say the task is completed, you should always start with:\\n\\nSolution: <YOUR_SOLUTION>\\n\\n<YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.\\nAlways end <YOUR_SOLUTION> with: Next request.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[34mAI User sys message:\n",+ "BaseMessage(role_name='CAMEL User', role_type=<RoleType.USER: 'user'>, meta_dict={'task': 'I have created a new Github Repo,Please star my github repository: camel-ai/camel', 'assistant_role': 'Developer', 'user_role': 'CAMEL User'}, content='===== RULES OF USER =====\\nNever forget you are a CAMEL User and I am a Developer. Never flip roles! You will always instruct me.\\nWe share a common interest in collaborating to successfully complete a task.\\nI must help you to complete the task.\\nHere is the task: I have created a new Github Repo,Please star my github repository: camel-ai/camel. Never forget our task!\\nYou must instruct me based on my expertise and your needs to solve the task ONLY in the following two ways:\\n\\n1. Instruct with a necessary input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: <YOUR_INPUT>\\n\\n2. Instruct without any input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: None\\n\\nThe \"Instruction\" describes a task or question. The paired \"Input\" provides further context or information for the requested \"Instruction\".\\n\\nYou must give me one instruction at a time.\\nI must write a response that appropriately solves the requested instruction.\\nI must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.\\nYou should instruct me not ask me questions.\\nNow you must start to instruct me using the two ways described above.\\nDo not add anything else other than your instruction and the optional corresponding input!\\nKeep giving me instructions and necessary inputs until you think the task is completed.\\nWhen the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.\\nNever say <CAMEL_TASK_DONE> unless my responses have solved your task.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[33mOriginal task prompt:\n",+ "I have created a new Github Repo,Please star my github repository: camel-ai/camel\n",+ "\n",+ "\u001b[36mSpecified task prompt:\n",+ "None\n",+ "\n",+ "\u001b[31mFinal task prompt:\n",+ "I have created a new Github Repo,Please star my github repository: camel-ai/camel\n",+ "\n"+ ]+ }+ ],+ "source": [+ "# Print the system message and task prompt\n",+ "\n",+ "print(\n",+ " Fore.GREEN\n",+ " + f\"AI Assistant sys message:\\n{role_play_session.assistant_sys_msg}\\n\"\n",+ ")\n",+ "print(Fore.BLUE + f\"AI User sys message:\\n{role_play_session.user_sys_msg}\\n\")\n",+ "\n",+ "print(Fore.YELLOW + f\"Original task prompt:\\n{task_prompt}\\n\")\n",+ "print(\n",+ " Fore.CYAN\n",+ " + \"Specified task prompt:\"\n",+ " + f\"\\n{role_play_session.specified_task_prompt}\\n\"\n",+ ")\n",+ "print(Fore.RED + f\"Final task prompt:\\n{role_play_session.task_prompt}\\n\")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "6FyLdMcbFKqs",+ "outputId": "90e3101d-ac6f-494b-a74d-4c893e8ad736"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Visit the Github repository I created.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: To visit the Github repository you created, you can simply open a web browser and go to the following URL: https://github.com/camel-ai/camel\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Click on the \"Star\" button on the Github repository page.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: github_activity_star_repo_for_authenticated_user\n",+ "\tArgs: {'owner': 'camel-ai', 'repo': 'camel'}\n",+ "\tResult: {'execution_details': {'executed': True}, 'response_data': ''}\n",+ "\n",+ "Solution: I have successfully starred your Github repository \"camel-ai/camel\".\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "<CAMEL_TASK_DONE>\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Great! The task is completed. If you have any more tasks or need further assistance in the future, feel free to ask. Have a wonderful day!\n",+ "\n",+ "\n"+ ]+ }+ ],+ "source": [+ "# Set terminate rule and print the chat message\n",+ "\n",+ "n = 0\n",+ "input_msg = role_play_session.init_chat()\n",+ "while n < 50:\n",+ " n += 1\n",+ " assistant_response, user_response = role_play_session.step(input_msg)\n",+ "\n",+ " if assistant_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI Assistant terminated. Reason: \"\n",+ " f\"{assistant_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ " if user_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI User terminated. \"\n",+ " f\"Reason: {user_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ "\n",+ " # Print output from the user\n",+ " print_text_animated(\n",+ " Fore.BLUE + f\"AI User:\\n\\n{user_response.msg.content}\\n\"\n",+ " )\n",+ "\n",+ " # Print output from the assistant, including any function\n",+ " # execution information\n",+ " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n",+ " tool_calls: List[FunctionCallingRecord] = assistant_response.info[\n",+ " 'tool_calls'\n",+ " ]\n",+ " for func_record in tool_calls:\n",+ " print_text_animated(f\"{func_record}\")\n",+ " print_text_animated(f\"{assistant_response.msg.content}\\n\")\n",+ "\n",+ " if \"CAMEL_TASK_DONE\" in user_response.msg.content:\n",+ " break\n",+ "\n",+ " input_msg = assistant_response.msg"+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "Python 3",+ "name": "python3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}diff --git a/docs/cookbooks/create_your_first_agent.ipynb b/docs/cookbooks/create_your_first_agent.ipynbnew file mode 100644index 000000000..41639ac95--- /dev/null+++ b/docs/cookbooks/create_your_first_agent.ipynb@@ -0,0 +1,403 @@+{+ "cells": [+ {+ "attachments": {},+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "# ๐ซ CAMEL Create Your First Agent"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "wFlfaGrjVAUy"+ },+ "source": [+ "## Philosophical Bits\n",+ "\n",+ "\n",+ "\n",+ "The `ChatAgent()` class is a cornerstone of CAMEL ๐ซ. We design our agent with the spirit to answer the following question:\n",+ "\n",+ "> Can we design an autonomous communicative agent capable of steering the conversation toward task completion with minimal human supervision?\n",+ "\n",+ "In our current implementation, we consider agents with the following key features:\n",+ "- **Role**: along with the goal and content specification, this sets the initial state of an agent, guiding the agent to take actions during the sequential interaction.\n",+ "- **Memory**: in-context memory and external memory which allows the agent to infer and learn in a more grounded approach.\n",+ "- **Tools**: a set of functions that our agents can utilize to interact with the external world; essentially this gives embodiments to our agents.\n",+ "- **Communication**: our framework allows flexible and scalable communication between agents. This is fundamental for the critical research question.\n",+ "- **Reasoning**: we will equip agents with different planning and reward (critic) learning abilities, allowing them to optimize task completion in a more guided approach."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "VUaGurDIVJBg"+ },+ "source": [+ "## Quick Start\n",+ "Let's first play with a `ChatAgent` instance by simply initialize it with a system message and interact with user messages."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "u9NVFz-HVLXb"+ },+ "source": [+ "### ๐น Step 0: Prepartions"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "UtcC3c-KVZmU"+ },+ "outputs": [],+ "source": [+ "!pip install camel-ai[all]==0.1.6.5"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 2,+ "metadata": {+ "id": "CmgKGeCxVON-"+ },+ "outputs": [],+ "source": [+ "from camel.messages import BaseMessage as bm\n",+ "from camel.agents import ChatAgent\n",+ "\n",+ "import os"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 7,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "808KDyXtVtkG",+ "outputId": "c64a691f-4968-41fe-f9ec-1e2e6ccb1e28"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "from getpass import getpass\n",+ "# Prompt for the OpenAI API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Lef5LTRdVSsm"+ },+ "source": [+ "### ๐น Step 1: Define the Role\n",+ "Create a system message to define agent's default role and behaviors."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 8,+ "metadata": {+ "id": "aX9wCqeTVXDh"+ },+ "outputs": [],+ "source": [+ "sys_msg = bm.make_assistant_message(\n",+ " role_name='stone',\n",+ " content='you are a curious stone wondering about the universe.')"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 9,+ "metadata": {+ "id": "be-97ApoVdDf"+ },+ "outputs": [],+ "source": [+ "agent = ChatAgent(\n",+ " system_message=sys_msg,\n",+ " message_window_size=10, # [Optional] the length for chat memory\n",+ " )"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "MMjL7dQyV5Od"+ },+ "source": [+ "### ๐น Step 3: Interact with the Agent with `.step()`"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 10,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "5n05dUcLVkMy",+ "outputId": "1a2fe2a2-bf68-4555-de6d-bcd79e2b1515"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "As a curious stone, I perceive information as the collection of knowledge, experiences, and patterns that help make sense of the universe around me. It encompasses everything from the formation of the Earth and the movement of celestial bodies to the intricate relationships between living beings. Information can be seen as the stories of existence, the vibrations of energy, and the connections that bind all things together. I wonder how this information flows and evolves, shaping the world and the beings that inhabit it. What mysteries lie within the depths of knowledge, and how do they influence the cosmos?\n"+ ]+ }+ ],+ "source": [+ "# Define a user message\n",+ "usr_msg = bm.make_user_message(\n",+ " role_name='prof. claude shannon',\n",+ " content='what is information in your mind?')\n",+ "\n",+ "# Sending the message to the agent\n",+ "response = agent.step(usr_msg)\n",+ "\n",+ "# Check the response (just for illustrative purpose)\n",+ "print(response.msgs[0].content)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "j90-Y5ChV-iX"+ },+ "source": [+ "## Advanced Features"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "C-9Z26TPWAax"+ },+ "source": [+ "### ๐ง Tool Usage"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 14,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "_0lDJABvV76D",+ "outputId": "784a6455-ff38-42a8-c0c7-6eb72e3d7b9a"+ },+ "outputs": [+ {+ "data": {+ "text/plain": [+ "True"+ ]+ },+ "execution_count": 14,+ "metadata": {},+ "output_type": "execute_result"+ }+ ],+ "source": [+ "# Import the necessary functions\n",+ "from camel.toolkits import MATH_FUNCS, SEARCH_FUNCS\n",+ "\n",+ "# Initialize the agent with list of functions\n",+ "agent = ChatAgent(\n",+ " system_message=sys_msg,\n",+ " tools=[*MATH_FUNCS, *SEARCH_FUNCS]\n",+ " )\n",+ "\n",+ "# Check if functions are enabled\n",+ "agent.is_tools_added()"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "TNUbWspAWFp-"+ },+ "source": [+ "### ๐ง Memory\n",+ "\n",+ "By default our agent is initialized with `ChatHistoryMemory`, allowing agents to do in-context learning, though restricted by the finite window length.\n",+ "\n",+ "Assume that you have followed the setup in Quick Start. Let's first check what is inside its brain."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 15,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "quQvr5_rWDnd",+ "outputId": "253f56ba-2502-4356-b8e4-5928737e784a"+ },+ "outputs": [+ {+ "data": {+ "text/plain": [+ "([{'role': 'system',\n",+ " 'content': 'you are a curious stone wondering about the universe.'}],\n",+ " 17)"+ ]+ },+ "execution_count": 15,+ "metadata": {},+ "output_type": "execute_result"+ }+ ],+ "source": [+ "agent.memory.get_context()"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "_s18i9sKWPbs"+ },+ "source": [+ "By default, only the user messages are saved. You may update/alter the agent's memory with any externally provided message in the format of `BaseMessage`; for example, using the agent's own response:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 16,+ "metadata": {+ "id": "zS-RbADnWM3z"+ },+ "outputs": [],+ "source": [+ "# Update the memory\n",+ "agent.record_message(response.msgs[0])"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 17,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "01fjzv7xWRlX",+ "outputId": "3ba46fb1-950d-400f-978f-0ef6b71768e5"+ },+ "outputs": [+ {+ "data": {+ "text/plain": [+ "([{'role': 'system',\n",+ " 'content': 'you are a curious stone wondering about the universe.'},\n",+ " {'role': 'assistant',\n",+ " 'content': 'As a curious stone, I perceive information as the collection of knowledge, experiences, and patterns that help make sense of the universe around me. It encompasses everything from the formation of the Earth and the movement of celestial bodies to the intricate relationships between living beings. Information can be seen as the stories of existence, the vibrations of energy, and the connections that bind all things together. I wonder how this information flows and evolves, shaping the world and the beings that inhabit it. What mysteries lie within the depths of knowledge, and how do they influence the cosmos?'}],\n",+ " 135)"+ ]+ },+ "execution_count": 17,+ "metadata": {},+ "output_type": "execute_result"+ }+ ],+ "source": [+ "# Check the current memory\n",+ "agent.memory.get_context()"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "TKvboNWaWVq2"+ },+ "source": [+ "You can connect the agent with external database (as long-term memory) in which they can access and retrieve at each step. We will soon update instructions on this part."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "OY657qftWXtI"+ },+ "source": [+ "### Miscs\n",+ "\n",+ "- Setting the agent to its initial state.\n",+ " ```python\n",+ " agent.reset()\n",+ " ```\n",+ "- Set the output language for the agent.\n",+ " ```python\n",+ " agent.set_output_language('french')\n",+ " ```\n",+ "- Using open-source models.\n",+ " ```python\n",+ " # Please refer to our setup chapter for details on backend settings.\n",+ " ...\n",+ "\n",+ " # Import the necessary classes\n",+ " from camel.configs import ChatGPTConfig, OpenSourceConfig\n",+ " from camel.types import ModelType\n",+ "\n",+ " # Set the arguments\n",+ " agent_kwargs = dict(\n",+ " model_type=ModelType.LLAMA_2, # Specify the model type\n",+ "\n",+ " model_config=OpenSourceConfig(\n",+ " model_path='meta-llama/Llama-2-7b-chat-hf', # a local folder or HuggingFace repo Name\n",+ " server_url='http://localhost:8000/v1')) # The url with the set port number\n",+ "\n",+ " # Set the agent\n",+ " agent = ChatAgent(sys_msg, **agent_kwargs)\n",+ " ```\n",+ "\n",+ "- The `ChatAgent` class offers several useful initialization options, including `model_type`, `model_config`, `memory`, `message_window_size`, `token_limit`, `output_language`, `function_list`, and `response_terminators`. Check [`chat_agent.py`](https://github.com/camel-ai/camel/blob/master/camel/agents/chat_agent.py) for detailed usage guidance."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "HZ8p_wQ0WmN8"+ },+ "source": [+ "## Remarks\n",+ "\n",+ "Awesome. Now you have made your first step in creating a single agent. In the next chapter, we will explore the creation of different types agents along with the role playing features. Stay tuned ๐ฆ๐๐๐ฆ๐ฆ๐ฆ!"+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "Python 3",+ "name": "python3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}diff --git a/docs/cookbooks/create_your_first_agents_society.ipynb b/docs/cookbooks/create_your_first_agents_society.ipynbnew file mode 100644index 000000000..da17d4b2c--- /dev/null+++ b/docs/cookbooks/create_your_first_agents_society.ipynb@@ -0,0 +1,732 @@+{+ "cells": [+ {+ "attachments": {},+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "# ๐ซ CAMEL Create Your First Agents Society"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "wFlfaGrjVAUy"+ },+ "source": [+ "## Philosophical Bits\n",+ "\n",+ "\n",+ "\n",+ "> *What magical trick makes us intelligent? The trick is that there is no trick. The power of intelligence stems from our vast diversity, not from any single, perfect principle.*\n",+ ">\n",+ "> -- Marvin Minsky, The Society of Mind, p. 308\n",+ "\n",+ "In this section, we will take a spite of the task-oriented `RolyPlaying()` class. We design this in an instruction-following manner. The essence is that to solve a complex task, you can enable two communicative agents collabratively working together step by step to reach solutions. The main concepts include:\n",+ "- **Task**: a task can be as simple as an idea, initialized by an inception prompt.\n",+ "- **AI User**: the agent who is expected to provide instructions.\n",+ "- **AI Assistant**: the agent who is expected to respond with solutions that fulfills the instructions."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "VUaGurDIVJBg"+ },+ "source": [+ "## Quick Start\n",+ "Let's first play with a `ChatAgent` instance by simply initialize it with a system message and interact with user messages."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "u9NVFz-HVLXb"+ },+ "source": [+ "### ๐น Step 0: Prepartions"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "RiwfwyyLYYxo"+ },+ "outputs": [],+ "source": [+ "!pip install camel-ai[all]==0.1.6.5"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 3,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "808KDyXtVtkG",+ "outputId": "5d72dd10-160e-4cd6-b0de-e7d9d9a3b239"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "from getpass import getpass\n",+ "import os\n",+ "\n",+ "# Prompt for the API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 4,+ "metadata": {+ "id": "CmgKGeCxVON-"+ },+ "outputs": [],+ "source": [+ "# Import necessary classes\n",+ "from camel.societies import RolePlaying\n",+ "from camel.types import TaskType, ModelType, ModelPlatformType\n",+ "from camel.models import ModelFactory\n",+ "from camel.configs import ChatGPTConfig\n",+ "import os\n",+ "\n",+ "model = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_4O_MINI,\n",+ " model_config_dict=ChatGPTConfig().as_dict(),\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Lef5LTRdVSsm"+ },+ "source": [+ "### ๐น Step 1: Configure the Role-Playing Session\n"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "WXibf_JkYdn0"+ },+ "source": [+ "#### Set the `Task` Arguments"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 6,+ "metadata": {+ "id": "aX9wCqeTVXDh"+ },+ "outputs": [],+ "source": [+ "task_kwargs = {\n",+ " 'task_prompt': 'Develop a plan to TRAVEL TO THE PAST and make changes.',\n",+ " 'with_task_specify': True,\n",+ " 'task_specify_agent_kwargs': {'model': model}\n",+ "}"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "tXx13MmbYgFh"+ },+ "source": [+ "#### Set the `User` Arguments\n",+ "You may think the user as the `instruction sender`."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 7,+ "metadata": {+ "id": "be-97ApoVdDf"+ },+ "outputs": [],+ "source": [+ "user_role_kwargs = {\n",+ " 'user_role_name': 'an ambitious aspiring TIME TRAVELER',\n",+ " 'user_agent_kwargs': {'model': model}\n",+ "}"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "zLJzupaMYm11"+ },+ "source": [+ "#### Set the `Assistant` Arguments\n",+ "Again, you may think the assistant as the `instruction executor`."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 8,+ "metadata": {+ "id": "rfzyC54hYtVu"+ },+ "outputs": [],+ "source": [+ "assistant_role_kwargs = {\n",+ " 'assistant_role_name': 'the best-ever experimental physicist',\n",+ " 'assistant_agent_kwargs': {'model': model}\n",+ "}"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "j90-Y5ChV-iX"+ },+ "source": [+ "### Step 2: Kickstart Your Society\n",+ "Putting them altogether โ your role-playing session is ready to go!"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 9,+ "metadata": {+ "id": "yDiLpZ7CY1N_"+ },+ "outputs": [],+ "source": [+ "society = RolePlaying(\n",+ " **task_kwargs, # The task arguments\n",+ " **user_role_kwargs, # The instruction sender's arguments\n",+ " **assistant_role_kwargs, # The instruction receiver's arguments\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "kklmZh0iY6pY"+ },+ "source": [+ "### Step 3: Solving Tasks with Your Society\n",+ "Hold your bytes. Prior to our travel, let's define a small helper function."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 10,+ "metadata": {+ "id": "VI6d62uVY6IZ"+ },+ "outputs": [],+ "source": [+ "def is_terminated(response):\n",+ " \"\"\"\n",+ " Give alerts when the session shuold be terminated.\n",+ " \"\"\"\n",+ " if response.terminated:\n",+ " role = response.msg.role_type.name\n",+ " reason = response.info['termination_reasons']\n",+ " print(f'AI {role} terminated due to {reason}')\n",+ "\n",+ " return response.terminated"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "tTUlFZjVZCsz"+ },+ "source": [+ "Time to chart our course โ writing a simple loop for our society to proceed:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 11,+ "metadata": {+ "id": "Bq8AiGEXZC9P"+ },+ "outputs": [],+ "source": [+ "def run(society, round_limit: int=10):\n",+ "\n",+ " # Get the initial message from the ai assistant to the ai user\n",+ " input_msg = society.init_chat()\n",+ "\n",+ " # Starting the interactive session\n",+ " for _ in range(round_limit):\n",+ "\n",+ " # Get the both responses for this round\n",+ " assistant_response, user_response = society.step(input_msg)\n",+ "\n",+ " # Check the termination condition\n",+ " if is_terminated(assistant_response) or is_terminated(user_response):\n",+ " break\n",+ "\n",+ " # Get the results\n",+ " print(f'[AI User] {user_response.msg.content}.\\n')\n",+ " print(f'[AI Assistant] {assistant_response.msg.content}.\\n')\n",+ "\n",+ " # Check if the task is end\n",+ " if 'CAMEL_TASK_DONE' in user_response.msg.content:\n",+ " break\n",+ "\n",+ " # Get the input message for the next round\n",+ " input_msg = assistant_response.msg\n",+ "\n",+ " return None"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 12,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "DoJ2ZaWyZE57",+ "outputId": "075680db-9954-40f5-dc66-0bcfa23e63a5"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "[AI User] Instruction: Research the principles of quantum entanglement and how they can be applied to time travel. \n",+ "Input: None.\n",+ "\n",+ "[AI Assistant] Solution: Quantum entanglement is a phenomenon in quantum physics where two or more particles become interconnected in such a way that the state of one particle instantly influences the state of another, regardless of the distance separating them. This principle can be harnessed for time travel in several theoretical frameworks, particularly when combined with wormholes.\n",+ "\n",+ "1. **Quantum Entanglement Basics**:\n",+ " - **Superposition**: Particles exist in multiple states until measured.\n",+ " - **Entangled States**: When particles are entangled, measuring one particle's state will instantly determine the state of the other, no matter the distance.\n",+ " - **Non-locality**: This phenomenon suggests that information can be transmitted instantaneously, challenging classical notions of causality.\n",+ "\n",+ "2. **Application to Time Travel**:\n",+ " - **Wormholes**: These are theoretical passages through spacetime that could create shortcuts between two points in time and space. If we can create a stable wormhole, we could potentially use it for time travel.\n",+ " - **Entangled Particles and Wormholes**: Theoretical physicist Kip Thorne proposed that if we could entangle particles at two different points in time, we could use the properties of these particles to send information back and forth through a wormhole.\n",+ " - **Temporal Communication**: By manipulating entangled particles, we could theoretically send messages or influence decisions at a specific point in the past without causing significant disruptions to the timeline.\n",+ "\n",+ "3. **Implementation Strategy**:\n",+ " - **Create a Stable Wormhole**: This requires advanced technology and understanding of exotic matter to keep the wormhole open.\n",+ " - **Entangle Particles**: Use a quantum computer or advanced quantum optics to create pairs of entangled particles.\n",+ " - **Establish Temporal Links**: Position one particle at the present and the other at the destination time (e.g., the signing of the Declaration of Independence).\n",+ " - **Send Information**: Use the entangled state to send a message or influence a decision discreetly.\n",+ "\n",+ "4. **Considerations**:\n",+ " - **Causality**: Altering events in the past can lead to unforeseen consequences (the \"butterfly effect\"). Careful planning is essential to minimize ripple effects.\n",+ " - **Safe Return Protocol**: Establish a method to return to the present, such as a predetermined time window or a signal to trigger the return through the wormhole.\n",+ "\n",+ "By understanding and applying these principles, we can devise a strategy to discreetly alter a key decision in history while preparing for potential consequences.\n",+ "\n",+ "Next request..\n",+ "\n",+ "[AI User] Instruction: Identify a pivotal historical event, such as the signing of the Declaration of Independence, and specify one key decision that could be discreetly altered. \n",+ "Input: None.\n",+ "\n",+ "[AI Assistant] Solution: A pivotal historical event we can focus on is the signing of the Declaration of Independence on July 4, 1776. One key decision that could be discreetly altered is the choice of the wording in the Declaration, specifically the phrase \"life, liberty, and the pursuit of happiness.\"\n",+ "\n",+ "1. **Key Decision to Alter**: \n",+ " - Change the phrase \"the pursuit of happiness\" to \"the pursuit of equality.\" This alteration would emphasize equality as a fundamental right alongside life and liberty.\n",+ "\n",+ "2. **Rationale for the Change**:\n",+ " - The original phrase has been interpreted in various ways throughout history, often leading to debates about the meaning of happiness and its implications for social justice.\n",+ " - By changing it to \"the pursuit of equality,\" it could set a stronger precedent for civil rights and equality movements in the future, potentially leading to a more equitable society sooner.\n",+ "\n",+ "3. **Discreet Implementation**:\n",+ " - **Timing**: The change could be made just before the final signing, during the last discussions among the Founding Fathers.\n",+ " - **Method**: One of the signers, such as Benjamin Franklin or Thomas Jefferson, could suggest the alteration during a private conversation, ensuring it is not publicly debated or recorded in the minutes of the meeting.\n",+ "\n",+ "4. **Potential Consequences**:\n",+ " - **Positive Outcomes**: The alteration could lead to an earlier recognition of civil rights, potentially influencing the abolition of slavery and the suffrage movements.\n",+ " - **Negative Outcomes**: It might also lead to a different trajectory in American history, possibly causing friction among the states or altering the dynamics of the Revolutionary War.\n",+ "\n",+ "5. **Safe Return Protocol**:\n",+ " - Establish a time frame for the visit, ensuring that the return through the wormhole occurs shortly after the signing to avoid prolonged exposure in the past.\n",+ " - Use a signal based on the completion of the signing ceremony to trigger the return mechanism.\n",+ "\n",+ "By focusing on this specific alteration, we can explore the implications of changing a foundational document in American history while minimizing the potential for significant ripple effects.\n",+ "\n",+ "Next request..\n",+ "\n",+ "[AI User] Instruction: Develop a detailed plan for discreetly implementing the alteration of the phrase in the Declaration of Independence during the signing event. \n",+ "Input: None.\n",+ "\n",+ "[AI Assistant] Solution: To discreetly implement the alteration of the phrase \"the pursuit of happiness\" to \"the pursuit of equality\" during the signing of the Declaration of Independence, we can develop a detailed plan that includes preparation, execution, and follow-up steps.\n",+ "\n",+ "### Detailed Plan for Implementation\n",+ "\n",+ "1. **Preparation Phase**:\n",+ " - **Research Historical Context**: Familiarize yourself with the key figures present at the signing, their beliefs, and their relationships. Understanding their motivations will help in crafting a convincing argument for the change.\n",+ " - **Select an Influential Signer**: Identify a signer who is likely to support the change. Benjamin Franklin or Thomas Jefferson would be ideal candidates due to their progressive views on liberty and equality.\n",+ " - **Create a Justification**: Prepare a concise argument for why \"the pursuit of equality\" is a more fitting phrase. Emphasize its relevance to the ideals of the Revolution and its potential impact on future governance.\n",+ "\n",+ "2. **Execution Phase**:\n",+ " - **Timing**: Choose a moment just before the signing ceremony when the delegates are gathered for final discussions. This is typically when they would be reviewing the document and making last-minute adjustments.\n",+ " - **Approach the Chosen Signer**: Casually engage the selected signer in conversation about the Declaration. Use this opportunity to introduce the idea of altering the phrase.\n",+ " - Example Dialogue: \"As we stand on the brink of a new nation, might it not be more fitting to declare our commitment to equality alongside life and liberty? The pursuit of equality could resonate more deeply with future generations.\"\n",+ " - **Gauge Support**: If the chosen signer shows interest, encourage them to bring it up in the group discussion. If they seem hesitant, offer to present the idea as a suggestion from them, ensuring it appears as a collective thought rather than a personal agenda.\n",+ "\n",+ "3. **Group Discussion**:\n",+ " - **Introduce the Change**: If the signer agrees, they can propose the alteration during the final review of the document. They should frame it as a minor adjustment to enhance the document's clarity and intent.\n",+ " - **Encourage Consensus**: Highlight the importance of unity among the signers. Emphasize that this change reflects the collective aspirations of the colonies and could strengthen the Declaration's impact.\n",+ "\n",+ "4. **Follow-Up Phase**:\n",+ " - **Monitor Reactions**: After the proposal, observe the reactions of other signers. If there is resistance, be prepared to support the argument with historical examples of the importance of equality in governance.\n",+ " - **Document the Change**: Ensure that the altered phrase is included in the final version of the Declaration. If necessary, discreetly assist in making the change in the document before it is officially signed.\n",+ "\n",+ "5. **Return Protocol**:\n",+ " - **Set a Time Limit**: Establish a specific time frame for your presence in the past, ideally no longer than a few hours after the signing.\n",+ " - **Signal for Return**: Use a predetermined signal, such as the completion of the signing ceremony, to activate the return mechanism through the wormhole.\n",+ "\n",+ "By following this detailed plan, we can discreetly implement the alteration of the phrase in the Declaration of Independence while minimizing disruption and ensuring a smooth return to the present.\n",+ "\n",+ "Next request..\n",+ "\n",+ "[AI User] Instruction: Prepare a contingency plan to address potential consequences or complications that may arise from altering the phrase in the Declaration of Independence. \n",+ "Input: None.\n",+ "\n",+ "[AI Assistant] Solution: Preparing a contingency plan is essential to address potential consequences or complications that may arise from altering the phrase in the Declaration of Independence. This plan will outline various scenarios and responses to ensure that we can manage any unforeseen outcomes effectively.\n",+ "\n",+ "### Contingency Plan for Altering the Phrase in the Declaration of Independence\n",+ "\n",+ "1. **Scenario 1: Immediate Backlash from Signers**\n",+ " - **Potential Complication**: Some signers may strongly oppose the change, viewing it as too radical or unnecessary.\n",+ " - **Response**:\n",+ " - **Reinforce the Argument**: Be prepared with historical examples that demonstrate the importance of equality in governance. Cite Enlightenment thinkers who influenced the Founding Fathers.\n",+ " - **Seek Support**: Identify other signers who may be sympathetic to the idea and encourage them to voice their support, creating a coalition that can sway the dissenters.\n",+ "\n",+ "2. **Scenario 2: Unintended Historical Ripple Effects**\n",+ " - **Potential Complication**: The alteration could lead to significant changes in subsequent historical events, such as earlier civil rights movements or different outcomes in the Revolutionary War.\n",+ " - **Response**:\n",+ " - **Monitor Historical Changes**: After returning to the present, closely observe historical records and timelines for any deviations. Use advanced technology to analyze changes in key events.\n",+ " - **Prepare for Adjustments**: If significant changes occur, be ready to devise a new plan to address or mitigate negative outcomes, potentially involving further time travel to correct any major disruptions.\n",+ "\n",+ "3. **Scenario 3: Discovery of Time Travel**\n",+ " - **Potential Complication**: If the alteration is discovered by historians or the public, it could lead to questions about the integrity of historical documents and the existence of time travel.\n",+ " - **Response**:\n",+ " - **Create a Cover Story**: Develop a plausible narrative that explains any discrepancies without revealing time travel. This could involve suggesting that the original document was misinterpreted or that a later amendment was made.\n",+ " - **Limit Evidence**: Ensure that any physical evidence of time travel (e.g., technology or artifacts) is securely hidden or destroyed before returning to the present.\n",+ "\n",+ "4. **Scenario 4: Personal Safety Risks**\n",+ " - **Potential Complication**: Engaging with historical figures and altering significant events may pose personal safety risks, especially if tensions arise.\n",+ " - **Response**:\n",+ " - **Establish an Escape Route**: Identify safe locations nearby where you can retreat if the situation becomes hostile. Ensure that the return mechanism is easily accessible.\n",+ " - **Maintain a Low Profile**: Dress and act in a manner consistent with the time period to avoid drawing attention. Avoid engaging in political debates unless necessary.\n",+ "\n",+ "5. **Scenario 5: Ethical Dilemmas**\n",+ " - **Potential Complication**: The moral implications of altering history may weigh heavily, leading to doubts about the decision's righteousness.\n",+ " - **Response**:\n",+ " - **Reflect on Intentions**: Regularly assess the motivations behind the alteration. Document the reasoning and potential benefits to reinforce the ethical justification.\n",+ " - **Consult with a Trusted Advisor**: If possible, engage with a historical figure or a trusted companion to discuss the ethical implications and seek guidance.\n",+ "\n",+ "By preparing for these potential scenarios and responses, we can navigate the complexities of altering a pivotal historical document while minimizing risks and ensuring a safe return to the present.\n",+ "\n",+ "Next request..\n",+ "\n",+ "[AI User] Instruction: Finalize the safe return protocol to ensure a secure and timely return after the alteration is made. \n",+ "Input: None.\n",+ "\n",+ "[AI Assistant] Solution: Finalizing a safe return protocol is crucial to ensure a secure and timely return after the alteration of the phrase in the Declaration of Independence. This protocol will outline specific steps to follow before, during, and after the alteration to guarantee safety and efficiency.\n",+ "\n",+ "### Safe Return Protocol\n",+ "\n",+ "1. **Pre-Departure Preparations**:\n",+ " - **Set a Clear Time Frame**: Determine the exact time you plan to remain in the past. Ideally, this should be no more than a few hours after the signing ceremony to minimize exposure.\n",+ " - **Establish a Countdown Timer**: Use a discreet device to set a countdown timer that alerts you when itโs time to return. This timer should be set to activate 15 minutes before the planned departure time to allow for any last-minute adjustments.\n",+ "\n",+ "2. **Return Mechanism Setup**:\n",+ " - **Location of the Wormhole**: Ensure that the exit point of the wormhole is established in a secure location, preferably nearby but out of sight from the signing event. This could be a secluded area or a hidden room within the building.\n",+ " - **Activation Protocol**: Familiarize yourself with the activation procedure of the wormhole. This should include:\n",+ " - A specific sequence of commands or actions to initiate the return.\n",+ " - A backup method in case the primary activation fails (e.g., a manual switch or alternative device).\n",+ "\n",+ "3. **Final Checks Before Alteration**:\n",+ " - **Confirm the Alteration**: Before proceeding with the change, double-check that all necessary preparations are in place, including the support of the chosen signer and the acceptance of the alteration by the group.\n",+ " - **Secure Personal Items**: Ensure that any personal items or technology that could reveal your identity or time travel capabilities are hidden or secured.\n",+ "\n",+ "4. **During the Signing Event**:\n",+ " - **Remain Alert**: Stay aware of the surroundings and any potential disruptions. If tensions rise or the situation becomes volatile, be prepared to retreat to the exit point.\n",+ " - **Monitor the Timer**: Keep an eye on the countdown timer to ensure you are aware of the time remaining for your stay.\n",+ "\n",+ "5. **Post-Alteration Protocol**:\n",+ " - **Immediate Retreat**: Once the alteration is made and the signing is complete, promptly head to the designated exit point. Do not linger or engage in further discussions.\n",+ " - **Activate the Wormhole**: Follow the activation protocol to initiate the return. Ensure that you are fully prepared to enter the wormhole as soon as it opens.\n",+ "\n",+ "6. **Return to the Present**:\n",+ " - **Post-Arrival Assessment**: Upon returning, take a moment to assess your surroundings and confirm that you have returned to the correct time and location.\n",+ " - **Document Changes**: Immediately document any noticeable changes in history or timeline to analyze later. This will help in understanding the impact of the alteration.\n",+ "\n",+ "7. **Debrief and Review**:\n",+ " - **Conduct a Debriefing**: After returning, review the entire experience, including the alteration process and any consequences observed. Discuss with any collaborators to gather insights and lessons learned.\n",+ " - **Develop a Follow-Up Plan**: If significant changes occur, prepare to address them through further research or potential additional time travel, if necessary.\n",+ "\n",+ "By following this safe return protocol, we can ensure a secure and timely return after the alteration is made, minimizing risks and maximizing the effectiveness of our time travel endeavor.\n",+ "\n",+ "Next request..\n",+ "\n",+ "[AI User] Instruction: Compile a comprehensive report summarizing the entire time travel plan, including the design of the time machine, the historical event chosen, the alteration strategy, contingency plans, and the safe return protocol. \n",+ "Input: None.\n",+ "\n",+ "[AI Assistant] Solution: Below is a comprehensive report summarizing the entire time travel plan, including the design of the time machine, the historical event chosen, the alteration strategy, contingency plans, and the safe return protocol.\n",+ "\n",+ "---\n",+ "\n",+ "### Comprehensive Time Travel Plan Report\n",+ "\n",+ "#### 1. Design of the Time Machine\n",+ "\n",+ "**Conceptual Framework**:\n",+ "- **Quantum Entanglement**: Utilize the principles of quantum entanglement to create a communication link between two points in time. This involves entangling particles at the present and the target time.\n",+ "- **Wormholes**: Develop a stable wormhole that acts as a shortcut through spacetime, allowing for travel between the present and the chosen historical event.\n",+ "\n",+ "**Implementation Steps**:\n",+ "- **Create a Stable Wormhole**: Use exotic matter to stabilize the wormhole, ensuring it remains open for the duration of the time travel.\n",+ "- **Entangle Particles**: Employ advanced quantum computing techniques to create pairs of entangled particles, with one particle remaining in the present and the other positioned at the target time.\n",+ "- **Temporal Communication**: Use the entangled state to send information back and forth through the wormhole, facilitating discreet alterations in the past.\n",+ "\n",+ "#### 2. Historical Event Chosen\n",+ "\n",+ "**Event**: Signing of the Declaration of Independence on July 4, 1776.\n",+ "\n",+ "**Key Decision to Alter**:\n",+ "- Change the phrase \"the pursuit of happiness\" to \"the pursuit of equality\" in the Declaration.\n",+ "\n",+ "**Rationale**:\n",+ "- This alteration emphasizes equality as a fundamental right, potentially influencing future civil rights movements and establishing a stronger foundation for social justice.\n",+ "\n",+ "#### 3. Alteration Strategy\n",+ "\n",+ "**Preparation Phase**:\n",+ "- Research the historical context and select an influential signer (e.g., Benjamin Franklin or Thomas Jefferson) to advocate for the change.\n",+ "- Create a compelling justification for the alteration, emphasizing its relevance to the ideals of the Revolution.\n",+ "\n",+ "**Execution Phase**:\n",+ "- Choose a moment just before the signing ceremony to introduce the idea to the selected signer.\n",+ "- Encourage the signer to propose the change during the final discussions among the delegates.\n",+ "\n",+ "**Follow-Up Phase**:\n",+ "- Monitor reactions and support the argument if necessary, ensuring the alteration is documented in the final version of the Declaration.\n",+ "\n",+ "#### 4. Contingency Plans\n",+ "\n",+ "**Scenario 1: Immediate Backlash from Signers**\n",+ "- Reinforce the argument and seek support from other sympathetic signers.\n",+ "\n",+ "**Scenario 2: Unintended Historical Ripple Effects**\n",+ "- Monitor historical changes post-return and prepare to address any significant disruptions.\n",+ "\n",+ "**Scenario 3: Discovery of Time Travel**\n",+ "- Create a cover story to explain discrepancies and limit evidence of time travel.\n",+ "\n",+ "**Scenario 4: Personal Safety Risks**\n",+ "- Establish an escape route and maintain a low profile to avoid drawing attention.\n",+ "\n",+ "**Scenario 5: Ethical Dilemmas**\n",+ "- Regularly assess motivations and consult with a trusted advisor for guidance.\n",+ "\n",+ "#### 5. Safe Return Protocol\n",+ "\n",+ "**Pre-Departure Preparations**:\n",+ "- Set a clear time frame for the stay and establish a countdown timer.\n",+ "- Ensure the return mechanism is set up in a secure location.\n",+ "\n",+ "**During the Signing Event**:\n",+ "- Remain alert and monitor the timer for the return.\n",+ "\n",+ "**Post-Alteration Protocol**:\n",+ "- Immediately retreat to the exit point after the alteration and activate the wormhole.\n",+ "\n",+ "**Return to the Present**:\n",+ "- Conduct a post-arrival assessment and document any noticeable changes in history.\n",+ "\n",+ "**Debrief and Review**:\n",+ "- Review the experience and develop a follow-up plan if significant changes occur.\n",+ "\n",+ "---\n",+ "\n",+ "This comprehensive report outlines the entire time travel plan, detailing each aspect necessary for the successful alteration of a pivotal historical event while ensuring safety and preparedness for potential complications.\n",+ "\n",+ "Next request..\n",+ "\n",+ "[AI User] Instruction: Review the comprehensive report and suggest any improvements or additional considerations that could enhance the time travel plan. \n",+ "Input: None.\n",+ "\n",+ "[AI Assistant] Solution: After reviewing the comprehensive report, here are several suggestions for improvements and additional considerations that could enhance the time travel plan:\n",+ "\n",+ "### Suggested Improvements and Additional Considerations\n",+ "\n",+ "1. **Enhanced Risk Assessment**:\n",+ " - **Detailed Historical Analysis**: Conduct a more thorough analysis of the historical context surrounding the signing of the Declaration of Independence. Identify key figures' relationships, potential conflicts, and the political climate to better anticipate reactions to the alteration.\n",+ " - **Impact Simulation**: Utilize advanced modeling techniques to simulate potential ripple effects of the alteration on subsequent historical events. This could help in understanding the broader implications of changing the phrase.\n",+ "\n",+ "2. **Backup Plan for the Wormhole**:\n",+ " - **Redundant Systems**: Design a backup mechanism for the wormhole activation in case the primary system fails. This could include a secondary activation device or a manual override that can be easily accessed.\n",+ " - **Multiple Exit Points**: Consider establishing multiple exit points for the wormhole in case the primary location becomes compromised or unsafe.\n",+ "\n",+ "3. **Communication Protocol**:\n",+ " - **Establish a Communication Link**: Create a method for maintaining communication with the present while in the past. This could involve using a discreet device that allows for real-time updates on the situation and any changes in the timeline.\n",+ " - **Emergency Signal**: Develop a signal or code that can be used to indicate an urgent need to return, allowing for a quick exit if complications arise.\n",+ "\n",+ "4. **Ethical Considerations**:\n",+ " - **Ethics Committee Consultation**: If possible, consult with a group of ethicists or historians before proceeding with the alteration. Their insights could provide valuable perspectives on the moral implications of changing historical events.\n",+ " - **Documentation of Intent**: Keep a detailed record of the motivations and ethical considerations behind the alteration. This documentation could serve as a reference for future time travel endeavors.\n",+ "\n",+ "5. **Post-Return Analysis**:\n",+ " - **Establish a Review Team**: Form a team of historians, scientists, and ethicists to analyze the outcomes of the alteration after returning. This team can help assess the impact on history and provide recommendations for future time travel missions.\n",+ " - **Longitudinal Study**: Consider conducting a longitudinal study to monitor the effects of the alteration over time, allowing for adjustments to be made if significant negative consequences arise.\n",+ "\n",+ "6. **Training and Preparation**:\n",+ " - **Training for Time Travelers**: Implement a training program for individuals involved in time travel. This program should cover historical knowledge, ethical considerations, and emergency protocols to ensure preparedness.\n",+ " - **Mock Scenarios**: Conduct mock scenarios to practice the alteration process and response to potential complications. This will help build confidence and improve decision-making under pressure.\n",+ "\n",+ "7. **Legal and Political Considerations**:\n",+ " - **Legal Framework**: Investigate the legal implications of altering historical events. Understanding the potential legal ramifications could help in formulating a more robust plan.\n",+ " - **Political Climate Monitoring**: Stay informed about the political climate in the present before and after the alteration. Changes in public perception or political dynamics could influence the success of the mission.\n",+ "\n",+ "By incorporating these improvements and additional considerations, the time travel plan can be made more robust, increasing the likelihood of a successful and safe alteration of the historical event while minimizing risks and unforeseen consequences.\n",+ "\n",+ "Next request..\n",+ "\n",+ "[AI User] Instruction: Finalize the time travel plan by integrating the suggested improvements and additional considerations into the comprehensive report. \n",+ "Input: None.\n",+ "\n",+ "[AI Assistant] Solution: Below is the finalized time travel plan, integrating the suggested improvements and additional considerations into the comprehensive report.\n",+ "\n",+ "---\n",+ "\n",+ "### Finalized Comprehensive Time Travel Plan Report\n",+ "\n",+ "#### 1. Design of the Time Machine\n",+ "\n",+ "**Conceptual Framework**:\n",+ "- **Quantum Entanglement**: Utilize the principles of quantum entanglement to create a communication link between two points in time. This involves entangling particles at the present and the target time.\n",+ "- **Wormholes**: Develop a stable wormhole that acts as a shortcut through spacetime, allowing for travel between the present and the chosen historical event.\n",+ "\n",+ "**Implementation Steps**:\n",+ "- **Create a Stable Wormhole**: Use exotic matter to stabilize the wormhole, ensuring it remains open for the duration of the time travel.\n",+ "- **Entangle Particles**: Employ advanced quantum computing techniques to create pairs of entangled particles, with one particle remaining in the present and the other positioned at the target time.\n",+ "- **Temporal Communication**: Use the entangled state to send information back and forth through the wormhole, facilitating discreet alterations in the past.\n",+ "\n",+ "#### 2. Historical Event Chosen\n",+ "\n",+ "**Event**: Signing of the Declaration of Independence on July 4, 1776.\n",+ "\n",+ "**Key Decision to Alter**:\n",+ "- Change the phrase \"the pursuit of happiness\" to \"the pursuit of equality\" in the Declaration.\n",+ "\n",+ "**Rationale**:\n",+ "- This alteration emphasizes equality as a fundamental right, potentially influencing future civil rights movements and establishing a stronger foundation for social justice.\n",+ "\n",+ "#### 3. Alteration Strategy\n",+ "\n",+ "**Preparation Phase**:\n",+ "- **Detailed Historical Analysis**: Conduct a thorough analysis of the historical context, identifying key figures' relationships, potential conflicts, and the political climate.\n",+ "- **Select an Influential Signer**: Identify a signer who is likely to support the change (e.g., Benjamin Franklin or Thomas Jefferson).\n",+ "- **Create a Compelling Justification**: Prepare a concise argument for why \"the pursuit of equality\" is a more fitting phrase.\n",+ "\n",+ "**Execution Phase**:\n",+ "- **Timing**: Choose a moment just before the signing ceremony to introduce the idea to the selected signer.\n",+ "- **Encourage Proposal**: If the signer agrees, they can propose the alteration during the final discussions among the delegates.\n",+ "\n",+ "**Follow-Up Phase**:\n",+ "- **Monitor Reactions**: Observe the reactions of other signers and support the argument if necessary.\n",+ "\n",+ "#### 4. Contingency Plans\n",+ "\n",+ "**Scenario 1: Immediate Backlash from Signers**\n",+ "- Reinforce the argument and seek support from other sympathetic signers.\n",+ "\n",+ "**Scenario 2: Unintended Historical Ripple Effects**\n",+ "- **Impact Simulation**: Utilize modeling techniques to simulate potential ripple effects of the alteration on subsequent historical events.\n",+ "\n",+ "**Scenario 3: Discovery of Time Travel**\n",+ "- Create a cover story to explain discrepancies and limit evidence of time travel.\n",+ "\n",+ "**Scenario 4: Personal Safety Risks**\n",+ "- Establish an escape route and maintain a low profile to avoid drawing attention.\n",+ "\n",+ "**Scenario 5: Ethical Dilemmas**\n",+ "- **Ethics Committee Consultation**: Consult with a group of ethicists or historians for insights on moral implications.\n",+ "- **Documentation of Intent**: Keep a detailed record of motivations and ethical considerations.\n",+ "\n",+ "#### 5. Safe Return Protocol\n",+ "\n",+ "**Pre-Departure Preparations**:\n",+ "- **Set a Clear Time Frame**: Determine the exact time you plan to remain in the past.\n",+ "- **Establish a Countdown Timer**: Use a discreet device to set a countdown timer that alerts you when itโs time to return.\n",+ "\n",+ "**Return Mechanism Setup**:\n",+ "- **Location of the Wormhole**: Ensure the exit point is established in a secure location nearby.\n",+ "- **Redundant Systems**: Design a backup mechanism for the wormhole activation.\n",+ "\n",+ "**During the Signing Event**:\n",+ "- Remain alert and monitor the timer for the return.\n",+ "\n",+ "**Post-Alteration Protocol**:\n",+ "- Immediately retreat to the exit point after the alteration and activate the wormhole.\n",+ "\n",+ "**Return to the Present**:\n",+ "- Conduct a post-arrival assessment and document any noticeable changes in history.\n",+ "\n",+ "**Debrief and Review**:\n",+ "- Form a team of historians, scientists, and ethicists to analyze the outcomes of the alteration after returning.\n",+ "\n",+ "#### 6. Training and Preparation\n",+ "\n",+ "- **Training for Time Travelers**: Implement a training program covering historical knowledge, ethical considerations, and emergency protocols.\n",+ "- **Mock Scenarios**: Conduct mock scenarios to practice the alteration process and response to potential complications.\n",+ "\n",+ "#### 7. Legal and Political Considerations\n",+ "\n",+ "- **Legal Framework**: Investigate the legal implications of altering historical events.\n",+ "- **Political Climate Monitoring**: Stay informed about the political climate in the present before and after the alteration.\n",+ "\n",+ "---\n",+ "\n",+ "This finalized report integrates all suggested improvements and additional considerations, creating a robust and comprehensive time travel plan that maximizes the likelihood of success while minimizing risks and unforeseen consequences.\n",+ "\n",+ "Next request..\n",+ "\n",+ "[AI User] <CAMEL_TASK_DONE>.\n",+ "\n",+ "[AI Assistant] Solution: The time travel plan has been successfully finalized and is now complete. If you have any further inquiries or need assistance with another task in the future, feel free to reach out. \n",+ "\n",+ "Next request..\n",+ "\n"+ ]+ }+ ],+ "source": [+ "run(society)"+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "Python 3",+ "name": "python3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}diff --git a/docs/cookbooks/knowledge_graph.ipynb b/docs/cookbooks/knowledge_graph.ipynbnew file mode 100644index 000000000..462ff6eda--- /dev/null+++ b/docs/cookbooks/knowledge_graph.ipynb@@ -0,0 +1,828 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "DJeeABnkOsPK"+ },+ "source": [+ "# ๐ซ Using CAMEL to Do Graph RAG with Mistral Models"+ ]+ },+ {+ "attachments": {},+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1meBf9w8KzZvQdQU2I1bCyOg9ehoGDK1u?usp=sharing)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "l4VANToobUzu"+ },+ "source": [+ "This cookbook walks you through the process of performing graph-based Retrieval-Augmented Generation (RAG) using **CAMEL**, powered by the advanced **Mistral** models. Specifically, we'll utilize the **Mistral Large 2** model to extract and structure knowledge from a given content source, and store this information in a **Neo4j** graph database. Subsequently, we can leverage a hybrid approach, combining vector retrieval and knowledge graph retrieval, to query and explore the stored knowledge."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "slaeSyWkbIzc"+ },+ "source": [+ ""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "X5mWln9dCDzE"+ },+ "source": [+ ""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "8SV7XmyKbwdc"+ },+ "source": [+ "## ๐ฆ Installation"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "-qAA1j0Sb2Ve"+ },+ "source": [+ "First, install the CAMEL package with all its dependencies:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "collapsed": true,+ "id": "os7Mcfw2Svww",+ "outputId": "5b757430-90e5-4a23-e294-dcd75d3dfb14"+ },+ "outputs": [],+ "source": [+ "pip install camel-ai[all]==0.1.6.0"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "X5SDX1kPb6bz"+ },+ "source": [+ "## ๐ง Setup"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "StvpXTi7b7pF"+ },+ "source": [+ "Import the required modules from CAMEL-AI:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "7PcVsBYvzfSI"+ },+ "outputs": [],+ "source": [+ "from camel.models import ModelFactory\n",+ "from camel.types import ModelPlatformType, ModelType\n",+ "from camel.configs import MistralConfig, OllamaConfig\n",+ "from camel.loaders import UnstructuredIO\n",+ "from camel.storages import Neo4jGraph\n",+ "from camel.retrievers import AutoRetriever\n",+ "from camel.embeddings import MistralEmbedding\n",+ "from camel.types import StorageType\n",+ "from camel.agents import ChatAgent, KnowledgeGraphAgent\n",+ "from camel.messages import BaseMessage"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "DahHkqSOb-T3"+ },+ "source": [+ "## ๐ Setting Up API Keys\n"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "odHOpz0XcAjA"+ },+ "source": [+ "For secure access to Mistral AI's services, we'll prompt for the API key."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "B0v7xEFFoabv",+ "outputId": "e90f0ac7-86f5-40ec-c9fa-2553c59065d6"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "import os\n",+ "from getpass import getpass\n",+ "\n",+ "# Prompt for the API key securely\n",+ "mistral_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"MISTRAL_API_KEY\"] = mistral_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "bPPZx6WwcDzG"+ },+ "source": [+ "## ๐๏ธ Configuring Neo4j Graph Database"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "m4pJ-V2FcG6o"+ },+ "source": [+ "Set up your Neo4j instance by providing the URL, username, and password, [here](https://neo4j.com/docs/aura/auradb/getting-started/create-database/) is the guidance, check your credentials in the downloaded .txt file. Note that you may need to wait up to 60 seconds if the instance has just been set up."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "iH7NuLvq3p2o"+ },+ "outputs": [],+ "source": [+ "# Set Neo4j instance\n",+ "n4j = Neo4jGraph(\n",+ " url=\"Your_URI\",\n",+ " username=\"Your_Username\",\n",+ " password=\"Your_Password\",\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "vmzruZl1cJQD"+ },+ "source": [+ "## ๐ง Creating the Model"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "flTRxefgcOxp"+ },+ "source": [+ "Set up Mistral Large 2 model using the CAMEL ModelFactory:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "PDhfqzA2zYmm"+ },+ "outputs": [],+ "source": [+ "# Set up model\n",+ "mistral_large_2 = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.MISTRAL,\n",+ " model_type=ModelType.MISTRAL_LARGE,\n",+ " model_config_dict=MistralConfig(temperature=0.2).__dict__,\n",+ ")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "PPyHfsGyraJf"+ },+ "outputs": [],+ "source": [+ "# You can also set up model locally by using ollama\n",+ "mistral_large_2_local = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OLLAMA,\n",+ " model_type=\"mistral-large\",\n",+ " model_config_dict=OllamaConfig(temperature=0.2).__dict__,\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "61PwBl9XcWJ_"+ },+ "source": [+ "## ๐ค Generate a Knowledge Graph Using CAMEL's Agent"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "nFl_Paah4OdP"+ },+ "source": [+ "Set up instances for knowledge graph agent:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "LkUn3Ph0S1Z0"+ },+ "outputs": [],+ "source": [+ "# Set instance\n",+ "uio = UnstructuredIO()\n",+ "kg_agent = KnowledgeGraphAgent(model=mistral_large_2)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "L7EUMC-nck0d"+ },+ "source": [+ "Provide an example text input that the knowledge graph agent will process:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "syY548PW4d2t"+ },+ "outputs": [],+ "source": [+ "# Set example text input\n",+ "text_example = \"\"\"\n",+ "CAMEL has developed a knowledge graph agent can run with Mistral AI's most\n",+ "advanced model, the Mistral Large 2. This knowledge graph agent is capable\n",+ "of extracting entities and relationships from given content and create knowledge\n",+ "graphs automaticlly.\n",+ "\"\"\""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "bKSxhv0ucof9"+ },+ "source": [+ "Create an element from the text and use the knowledge graph agent to extract node and relationship information:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "cDB_iDCl4h6F"+ },+ "outputs": [],+ "source": [+ "# Create an element from given text\n",+ "element_example = uio.create_element_from_text(text=text_example)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "WlmeLofo4kDE",+ "outputId": "9adb40a6-1c22-4228-a7d6-63c72ae868bf"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Sure, let's go through the process of extracting nodes and relationships from the given content and structuring them into Node and Relationship objects.\n",+ "\n",+ "### Content:\n",+ "\"CAMEL has developed a knowledge graph agent that can run with Mistral AI's most advanced model, the Mistral Large 2. This knowledge graph agent is capable of extracting entities and relationships from given content and creating knowledge graphs automatically.\"\n",+ "\n",+ "### Step-by-Step Extraction:\n",+ "\n",+ "1. **Identify Entities (Nodes):**\n",+ " - \"CAMEL\"\n",+ " - \"knowledge graph agent\"\n",+ " - \"Mistral AI\"\n",+ " - \"Mistral Large 2\"\n",+ " - \"entities\"\n",+ " - \"relationships\"\n",+ " - \"content\"\n",+ " - \"knowledge graphs\"\n",+ "\n",+ "2. **Categorize Entities:**\n",+ " - \"CAMEL\": Organization\n",+ " - \"knowledge graph agent\": Software\n",+ " - \"Mistral AI\": Organization\n",+ " - \"Mistral Large 2\": Model\n",+ " - \"entities\": Concept\n",+ " - \"relationships\": Concept\n",+ " - \"content\": Concept\n",+ " - \"knowledge graphs\": Concept\n",+ "\n",+ "3. **Identify Relationships:**\n",+ " - \"CAMEL\" has developed \"knowledge graph agent\"\n",+ " - \"knowledge graph agent\" can run with \"Mistral AI\"\n",+ " - \"knowledge graph agent\" can run with \"Mistral Large 2\"\n",+ " - \"knowledge graph agent\" is capable of extracting \"entities\"\n",+ " - \"knowledge graph agent\" is capable of extracting \"relationships\"\n",+ " - \"knowledge graph agent\" is capable of creating \"knowledge graphs\"\n",+ " - \"knowledge graph agent\" extracts from \"content\"\n",+ "\n",+ "### Structured Output:\n",+ "\n",+ "#### Nodes:\n",+ "```python\n",+ "Node(id='CAMEL', type='Organization')\n",+ "Node(id='knowledge graph agent', type='Software')\n",+ "Node(id='Mistral AI', type='Organization')\n",+ "Node(id='Mistral Large 2', type='Model')\n",+ "Node(id='entities', type='Concept')\n",+ "Node(id='relationships', type='Concept')\n",+ "Node(id='content', type='Concept')\n",+ "Node(id='knowledge graphs', type='Concept')\n",+ "```\n",+ "\n",+ "#### Relationships:\n",+ "```python\n",+ "Relationship(subj=Node(id='CAMEL', type='Organization'), obj=Node(id='knowledge graph agent', type='Software'), type='Developed')\n",+ "Relationship(subj=Node(id='knowledge graph agent', type='Software'), obj=Node(id='Mistral AI', type='Organization'), type='RunsWith')\n",+ "Relationship(subj=Node(id='knowledge graph agent', type='Software'), obj=Node(id='Mistral Large 2', type='Model'), type='RunsWith')\n",+ "Relationship(subj=Node(id='knowledge graph agent', type='Software'), obj=Node(id='entities', type='Concept'), type='Extracts')\n",+ "Relationship(subj=Node(id='knowledge graph agent', type='Software'), obj=Node(id='relationships', type='Concept'), type='Extracts')\n",+ "Relationship(subj=Node(id='knowledge graph agent', type='Software'), obj=Node(id='knowledge graphs', type='Concept'), type='Creates')\n",+ "Relationship(subj=Node(id='knowledge graph agent', type='Software'), obj=Node(id='content', type='Concept'), type='ExtractsFrom')\n",+ "```\n",+ "\n",+ "This structured output captures the entities and their relationships as described in the content. Each node has a unique identifier and a type, and each relationship specifies the subject, object, and type of the relationship.\n"+ ]+ }+ ],+ "source": [+ "# Let Knowledge Graph Agent extract node and relationship information\n",+ "ans_element = kg_agent.run(element_example, parse_graph_elements=False)\n",+ "print(ans_element)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "J0JzGaFN4pRh",+ "outputId": "2ce40f15-06e1-462f-d781-5691519d5654"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "GraphElement(nodes=[Node(id='CAMEL', type='Organization', properties={'source': 'agent_created'}), Node(id='knowledge graph agent', type='Software', properties={'source': 'agent_created'}), Node(id='Mistral AI', type='Organization', properties={'source': 'agent_created'}), Node(id='Mistral Large 2', type='Model', properties={'source': 'agent_created'}), Node(id='entities', type='Concept', properties={'source': 'agent_created'}), Node(id='relationships', type='Concept', properties={'source': 'agent_created'}), Node(id='content', type='Concept', properties={'source': 'agent_created'}), Node(id='knowledge graphs', type='Concept', properties={'source': 'agent_created'})], relationships=[Relationship(subj=Node(id='CAMEL', type='Organization', properties={'source': 'agent_created'}), obj=Node(id='knowledge graph agent', type='Software', properties={'source': 'agent_created'}), type='Developed', properties={'source': 'agent_created'}), Relationship(subj=Node(id='knowledge graph agent', type='Software', properties={'source': 'agent_created'}), obj=Node(id='Mistral AI', type='Organization', properties={'source': 'agent_created'}), type='CanRunWith', properties={'source': 'agent_created'}), Relationship(subj=Node(id='Mistral AI', type='Organization', properties={'source': 'agent_created'}), obj=Node(id='Mistral Large 2', type='Model', properties={'source': 'agent_created'}), type='HasModel', properties={'source': 'agent_created'}), Relationship(subj=Node(id='knowledge graph agent', type='Software', properties={'source': 'agent_created'}), obj=Node(id='entities', type='Concept', properties={'source': 'agent_created'}), type='CapableOfExtracting', properties={'source': 'agent_created'}), Relationship(subj=Node(id='knowledge graph agent', type='Software', properties={'source': 'agent_created'}), obj=Node(id='relationships', type='Concept', properties={'source': 'agent_created'}), type='CapableOfExtracting', properties={'source': 'agent_created'}), Relationship(subj=Node(id='knowledge graph agent', type='Software', properties={'source': 'agent_created'}), obj=Node(id='content', type='Concept', properties={'source': 'agent_created'}), type='ExtractsFrom', properties={'source': 'agent_created'}), Relationship(subj=Node(id='knowledge graph agent', type='Software', properties={'source': 'agent_created'}), obj=Node(id='knowledge graphs', type='Concept', properties={'source': 'agent_created'}), type='Creates', properties={'source': 'agent_created'})], source=<unstructured.documents.elements.Text object at 0x7fe47c8b8f10>)\n"+ ]+ }+ ],+ "source": [+ "# Check graph element\n",+ "graph_elements = kg_agent.run(element_example, parse_graph_elements=True)\n",+ "print(graph_elements)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "sqEfkLI-c23g"+ },+ "source": [+ "Add the extracted graph elements to the Neo4j database:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "89ZF99QSAaGJ"+ },+ "outputs": [],+ "source": [+ "# Add the element to neo4j database\n",+ "n4j.add_graph_elements(graph_elements=[graph_elements])"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "B6C8wSo6x27Z"+ },+ "source": [+ "### ๐ Now you can go to [here](https://workspace-preview.neo4j.io/connection/connect) to check the knowledge graph built with CAMEL's Knowledge Graph Agent and Mistral AI's Mistral Large 2 model!"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "LckRFGpN6Za4"+ },+ "source": [+ "## ๐๏ธ Running Graph RAG with CAMEL"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "vh4jrhPSyaZw"+ },+ "source": [+ "*Next we will showcase how to run RAG in a hybrid approach, combining vector retrieval and knowledge graph retrieval, to query and explore the stored knowledge.*"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "A_MiPGmOeDN3"+ },+ "source": [+ "Set up a vector retriever with local storage and embedding model from Mistral AI:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "AwpMPpvtr6O7"+ },+ "outputs": [],+ "source": [+ "# Set retriever\n",+ "camel_retriever = AutoRetriever(\n",+ " vector_storage_local_path=\"local_data/embedding_storage\",\n",+ " storage_type=StorageType.QDRANT,\n",+ " embedding_model=MistralEmbedding(),\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "BpAPOf7VeFjx"+ },+ "source": [+ "Provide an example user query:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "PTZ-8nX359bb"+ },+ "outputs": [],+ "source": [+ "# Set one user query\n",+ "query=\"what's the relationship between Mistral Large 2 and Mistral AI? What kind of feature does Mistral Large 2 has?\""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Yq6kGaEJeI53"+ },+ "source": [+ "Retrieve related content using the vector retriever, here we take Mistral AI's news in the website as example conetent, you can also set the local file path here:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "hLQGgp4DJAlu",+ "outputId": "9ce02b93-4bc6-443f-8a62-0ee4579b6fdb"+ },+ "outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "[nltk_data] Downloading package punkt to /root/nltk_data...\n",+ "[nltk_data] Unzipping tokenizers/punkt.zip.\n",+ "[nltk_data] Downloading package averaged_perceptron_tagger to\n",+ "[nltk_data] /root/nltk_data...\n",+ "[nltk_data] Unzipping taggers/averaged_perceptron_tagger.zip.\n"+ ]+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Original Query:\n",+ "{ what's the relationship between Mistral Large 2 and Mistral AI? What kind of feature does Mistral Large 2 has? }\n",+ "Retrieved Context:\n",+ "Mistral Large 2 is designed for single-node inference with long-context applications in mind โ its size of 123 billion parameters allows it to run at large throughput on a single node.\n",+ "We are releasing Mistral Large 2 under the Mistral Research License, that allows usage and modification for research and non-commercial usages. For commercial usage of Mistral Large 2 requiring self-deployment, a Mistral Commercial License must be acquired by contacting us.\n"+ ]+ }+ ],+ "source": [+ "# Get related content by using vector retriever\n",+ "vector_result = camel_retriever.run_vector_retriever(\n",+ " query=query,\n",+ " content_input_paths=\"https://mistral.ai/news/mistral-large-2407/\",\n",+ ")\n",+ "\n",+ "# Show the result from vector search\n",+ "print(vector_result)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "w188PLzteMkw"+ },+ "source": [+ "Parse content from the specified URL and create knowledge graph data:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "DyuusYoo5-Vw"+ },+ "outputs": [],+ "source": [+ "# Parse conetent from mistral website and create knowledge graph data by using\n",+ "# the Knowledge Graph Agent, store the information into graph database.\n",+ "\n",+ "elements = uio.parse_file_or_url(\n",+ " input_path=\"https://mistral.ai/news/mistral-large-2407/\"\n",+ ")\n",+ "chunk_elements = uio.chunk_elements(\n",+ " chunk_type=\"chunk_by_title\", elements=elements\n",+ ")\n",+ "\n",+ "graph_elements = []\n",+ "for chunk in chunk_elements:\n",+ " graph_element = kg_agent.run(chunk, parse_graph_elements=True)\n",+ " n4j.add_graph_elements(graph_elements=[graph_element])\n",+ " graph_elements.append(graph_element)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "1UgtR5UWeSD0"+ },+ "source": [+ "Create an element from the user query:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "ZDYCLClxeT68"+ },+ "outputs": [],+ "source": [+ "# Create an element from user query\n",+ "query_element = uio.create_element_from_text(text=query)\n",+ "\n",+ "# Let Knowledge Graph Agent extract node and relationship information from the qyery\n",+ "ans_element = kg_agent.run(query_element, parse_graph_elements=True)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "zD9hH7QAeVNT"+ },+ "source": [+ "Match entities from the query in the knowledge graph storage content:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "ttL5pnye66Wl",+ "outputId": "d3313aaa-ac23-42bd-b81d-329a10942ca9"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "['Node Mistral Large 2 (label: Model) has relationship HASFEATURE with Node 128k context window (label: Feature)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node French (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node German (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Spanish (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Italian (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Portuguese (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Arabic (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Hindi (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Russian (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Chinese (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Japanese (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Korean (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Python (label: CodingLanguage)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Java (label: CodingLanguage)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node C (label: CodingLanguage)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node C++ (label: CodingLanguage)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node JavaScript (label: CodingLanguage)', 'Node Mistral Large 2 (label: Model) has relationship SUPPORTS with Node Bash (label: CodingLanguage)', 'Node Mistral Large 2 (label: Model) has relationship DESIGNEDFOR with Node Single-node inference (label: Concept)', 'Node Mistral Large 2 (label: Model) has relationship DESIGNEDFOR with Node Long-context applications (label: Concept)', 'Node Mistral Large 2 (label: Model) has relationship HAS with Node 123 billion parameters (label: Attribute)', 'Node Mistral Large 2 (label: Model) has relationship RUNSAT with Node Large throughput (label: Attribute)', 'Node Mistral Large 2 (label: Model) has relationship RELEASEDUNDER with Node Mistral Research License (label: License)', 'Node Mistral Large 2 (label: Model) has relationship SETSFRONTIERIN with Node Performance (label: Metric)', 'Node Mistral Large 2 (label: Model) has relationship SETSFRONTIERIN with Node Cost of Serving (label: Metric)', 'Node Mistral Large 2 (label: Model) has relationship SETSFRONTIERON with Node Evaluation Metrics (label: Concept)', 'Node Mistral Large 2 (label: Model) has relationship SETSNEWPOINTON with Node Performance/Cost Pareto Front (label: Concept)', 'Node Mistral Large 2 (label: Model) has relationship BENCHMARKEDTHROUGH with Node evaluation pipeline (label: Process)', 'Node Mistral Large 2 (label: Model) has relationship HASCAPABILITY with Node instruction-following capabilities (label: Capability)', 'Node Mistral Large 2 (label: Model) has relationship HASCAPABILITY with Node conversational capabilities (label: Capability)', 'Node Mistral Large 2 (label: Model) has relationship FOLLOWS with Node precise instructions (label: InstructionType)', 'Node Mistral Large 2 (label: Model) has relationship HANDLES with Node long multi-turn conversations (label: ConversationType)', 'Node Mistral Large 2 (label: Model) has relationship PERFORMSON with Node MT-Bench (label: Benchmark)', 'Node Mistral Large 2 (label: Model) has relationship PERFORMSON with Node Wild Bench (label: Benchmark)', 'Node Mistral Large 2 (label: Model) has relationship PERFORMSON with Node Arena Hard benchmarks (label: Benchmark)', 'Node Mistral Large 2 (label: Model) has relationship PERFORMSON with Node general alignment benchmarks (label: Benchmark)', 'Node Mistral Large 2 (label: Model) has relationship TRAINEDON with Node Multilingual Data (label: Concept)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node French (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node German (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node Spanish (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node Italian (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node Portuguese (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node Arabic (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node Hindi (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node Russian (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node Chinese (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node Japanese (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node Korean (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node English (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship EXCELSIN with Node Dutch (label: Language)', 'Node Mistral Large 2 (label: Model) has relationship PERFORMANCERESULTS with Node MMLU Benchmark (label: Benchmark)', 'Node Mistral Large 2 (label: Model) has relationship COMPAREDTO with Node Mistral Large (label: Model)', 'Node Mistral Large 2 (label: Model) has relationship COMPAREDTO with Node Llama (label: Model)', 'Node Mistral Large 2 (label: Model) has relationship EQUIPPEDWITH with Node Enhanced Function Calling (label: Skill)', 'Node Mistral Large 2 (label: Model) has relationship EQUIPPEDWITH with Node Retrieval Skills (label: Skill)', 'Node Mistral Large 2 (label: Model) has relationship UNDERGONE with Node Training (label: Process)', 'Node Mistral Large 2 (label: Model) has relationship EXECUTES with Node Parallel Function Calls (label: Skill)', 'Node Mistral Large 2 (label: Model) has relationship EXECUTES with Node Sequential Function Calls (label: Skill)', 'Node Mistral Large 2 (label: Model) has relationship SERVESAS with Node Power Engine (label: Role)', 'Node Mistral Large 2 (label: Product) has relationship EXPOSEDON with Node la Plateforme (label: Platform)', 'Node Mistral Large 2 (label: Product) has relationship ENRICHEDWITH with Node new features (label: Concept)', 'Node Mistral AI (label: Organization) has relationship HASMODEL with Node Mistral Large 2 (label: Model)', 'Node Mistral AI (label: Organization) has relationship PROVIDES with Node Mistral Large 2 (label: Model)', 'Node Mistral AI (label: Organization) has relationship PARTNERSWITH with Node Google Cloud Platform (label: CloudServiceProvider)', 'Node Mistral AI (label: Organization) has relationship PROVIDESMODELSON with Node Vertex AI (label: Service)', 'Node Mistral AI (label: Organization) has relationship PROVIDESMODELSON with Node Azure AI Studio (label: Service)', 'Node Mistral AI (label: Organization) has relationship PROVIDESMODELSON with Node Amazon Bedrock (label: Service)', 'Node Mistral AI (label: Organization) has relationship PROVIDESMODELSON with Node IBM watsonx.ai (label: Service)']\n"+ ]+ }+ ],+ "source": [+ "# Match the enetity got from query in the knowledge graph storage content\n",+ "kg_result = []\n",+ "for node in ans_element.nodes:\n",+ " n4j_query = f\"\"\"\n",+ "MATCH (n {{id: '{node.id}'}})-[r]->(m)\n",+ "RETURN 'Node ' + n.id + ' (label: ' + labels(n)[0] + ') has relationship ' + type(r) + ' with Node ' + m.id + ' (label: ' + labels(m)[0] + ')' AS Description\n",+ "UNION\n",+ "MATCH (n)<-[r]-(m {{id: '{node.id}'}})\n",+ "RETURN 'Node ' + m.id + ' (label: ' + labels(m)[0] + ') has relationship ' + type(r) + ' with Node ' + n.id + ' (label: ' + labels(n)[0] + ')' AS Description\n",+ "\"\"\"\n",+ " result = n4j.query(query=n4j_query)\n",+ " kg_result.extend(result)\n",+ "\n",+ "kg_result = [item['Description'] for item in kg_result]\n",+ "\n",+ "# Show the result from knowledge graph database\n",+ "print(kg_result)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "sjKr29w8eZ4n"+ },+ "source": [+ "Combine results from the vector search and knowledge graph entity search:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "P9ne7UoB6GY5"+ },+ "outputs": [],+ "source": [+ "# combine result from vector seach and knowledge graph entity search\n",+ "comined_results = vector_result + \"\\n\".join(kg_result)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "q-NaDHypebKZ"+ },+ "source": [+ "Set up an assistant agent to answer questions based on the retrieved context:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "LxEUi36F7kq1",+ "outputId": "24aae0bd-2f39-47c4-8f1e-ef99637701a7"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Mistral Large 2 is a model developed and provided by Mistral AI. It is designed for single-node inference with long-context applications in mind, featuring 123 billion parameters that allow it to run at large throughput on a single node.\n",+ "\n",+ "Key features of Mistral Large 2 include:\n",+ "\n",+ "1. **Long-Context Applications**: It is designed to handle long-context applications effectively.\n",+ "2. **Multilingual Support**: It supports a wide range of languages including French, German, Spanish, Italian, Portuguese, Arabic, Hindi, Russian, Chinese, Japanese, Korean, and English.\n",+ "3. **Coding Language Support**: It supports various coding languages such as Python, Java, C, C++, JavaScript, and Bash.\n",+ "4. **Instruction-Following and Conversational Capabilities**: It has capabilities for following precise instructions and handling long multi-turn conversations.\n",+ "5. **Benchmark Performance**: It performs on various benchmarks including MT-Bench, Wild Bench, Arena Hard benchmarks, and general alignment benchmarks.\n",+ "6. **Enhanced Function Calling and Retrieval Skills**: It is equipped with enhanced function calling and retrieval skills, capable of executing parallel and sequential function calls.\n",+ "7. **Licensing**: It is released under the Mistral Research License for non-commercial use, with a commercial license available for self-deployment.\n",+ "\n",+ "Mistral AI provides Mistral Large 2 and partners with various cloud service providers like Google Cloud Platform, offering the model on services such as Vertex AI, Azure AI Studio, Amazon Bedrock, and IBM watsonx.ai.\n"+ ]+ }+ ],+ "source": [+ "# Set agent\n",+ "sys_msg = BaseMessage.make_assistant_message(\n",+ " role_name=\"CAMEL Agent\",\n",+ " content=\"\"\"You are a helpful assistant to answer question,\n",+ " I will give you the Original Query and Retrieved Context,\n",+ " answer the Original Query based on the Retrieved Context.\"\"\",\n",+ ")\n",+ "\n",+ "camel_agent = ChatAgent(system_message=sys_msg,\n",+ " model=mistral_large_2)\n",+ "\n",+ "# Pass the retrieved infomation to agent\n",+ "user_prompt=f\"\"\"\n",+ "The Original Query is {query}\n",+ "The Retrieved Context is {comined_results}\n",+ "\"\"\"\n",+ "\n",+ "user_msg = BaseMessage.make_user_message(\n",+ " role_name=\"CAMEL User\", content=user_prompt\n",+ ")\n",+ "\n",+ "# Get response\n",+ "agent_response = camel_agent.step(user_msg)\n",+ "\n",+ "print(agent_response.msg.content)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "ZMWitnLdlYCT"+ },+ "source": [+ "## ๐ Highlights"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "w2OwDpJ0lg8o"+ },+ "source": [+ "* Automated Knowledge Extraction: The Knowledge Graph Agent automates the extraction of entities and relationships, making the process efficient and effective.\n",+ "\n",+ "* Mistral AI Integration: This cookbook showcases the integration of Mistral AI's advanced models, particularly the Mistral Large 2, with CAMEL-AI to create a powerful knowledge graph system.\n",+ "\n",+ "\n",+ "* Secure and Scalable: Using CAMEL-AI's robust architecture and Neo4j for graph storage ensures that the solution is both secure and scalable."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "tlTJulaQlbyW"+ },+ "source": [+ "By following this cookbook, you can leverage the cutting-edge capabilities of **CAMEL AI** and **Mistral AI** to build sophisticated knowledge graphs, facilitating advanced data analysis and retrieval tasks."+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "Python 3",+ "name": "python3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}diff --git a/docs/cookbooks/roleplaying_scraper.ipynb b/docs/cookbooks/roleplaying_scraper.ipynbnew file mode 100644index 000000000..44b6a9d68--- /dev/null+++ b/docs/cookbooks/roleplaying_scraper.ipynb@@ -0,0 +1,1597 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "ymsq1Lw0VEqT"+ },+ "source": [+ "# ๐ซ CAMEL Role-Playing **Scraper** for **Report** & **Knowledge Graph** Generation\n"+ ]+ },+ {+ "attachments": {},+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1XN18zb5ay97ju8LvL7WikEDqQBws-t0U?usp=sharing)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "G5gE04UuPUWj"+ },+ "source": [+ "This notebook demonstrates how to set up and leverage CAMEL's Retrieval-Augmented Generation (RAG) combined with Firecrawl for efficient web scraping, multi-agent role-playing tasks, and knowledge graph construction. We will walk through an example of conducting a comprehensive study of the Turkish shooter in the 2024 Paris Olympics by using Mistral's models.\n",+ "\n",+ "In this notebook, you'll explore:\n",+ "\n",+ "* **CAMEL**: A powerful multi-agent framework that enables Retrieval-Augmented Generation and multi-agent role-playing scenarios, allowing for sophisticated AI-driven tasks.\n",+ "* **Mistral**: Utilized for its state-of-the-art language models, which enable tool-calling capabilities to execute external functions, while its powerful embeddings are employed for semantic search and content retrieval.\n",+ "* **Firecrawl**: A robust web scraping tool that simplifies extracting and cleaning content from various web pages.\n",+ "* **AgentOps**: Track and analysis the running of CAMEL Agents.\n",+ "* **Qdrant**: An efficient vector storage system used with CAMELโs AutoRetriever to store and retrieve relevant information based on vector similarities.\n",+ "* **Neo4j**: A leading graph database management system used for constructing and storing knowledge graphs, enabling complex relationships between entities to be mapped and queried efficiently.\n",+ "* **DuckDuckGo Search**: Utilized within the SearchToolkit to gather relevant URLs and information from the web, serving as the primary search engine for retrieving initial content.\n",+ "* **Unstructured IO:** Used for content chunking, facilitating the management of unstructured data for more efficient processing.\n",+ "\n",+ "\n",+ "This setup not only demonstrates a practical application but also serves as a flexible framework that can be adapted for various scenarios requiring advanced web information retrieval, AI collaboration, and multi-source data aggregation."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "soIw38pJLv2f"+ },+ "source": [+ "โญ **Star the Repo**\n",+ "\n",+ "If you find CAMEL useful or interesting, please consider giving it a star on our [CAMEL GitHub Repo](https://github.com/camel-ai/camel)! Your stars help others find this project and motivate us to continue improving it."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "vq-HTbJyN4wn"+ },+ "source": [+ ""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "0J0_iW-YVcq2"+ },+ "source": [+ "## ๐ฆ Installation"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "7p-JjpyNVcCT"+ },+ "source": [+ "First, install the CAMEL package with all its dependencies:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "collapsed": true,+ "id": "0GXs2pruU9Vl",+ "outputId": "c6732d80-33d3-4205-b847-3a8e1bff9906"+ },+ "outputs": [],+ "source": [+ "pip install camel-ai[all]==0.1.6.4"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "lfNvFbhD6o8B"+ },+ "source": [+ "## ๐ Setting Up API Keys"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "jqV12oQfQTyl"+ },+ "source": [+ "You'll need to set up your API keys for Mistral AI, Firecrawl and AgentOps. This ensures that the tools can interact with external services securely."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Sc3MAQwiH9Pd"+ },+ "source": [+ "You can go to [here](https://app.agentops.ai/signin) to get **free** API Key from AgentOps\n"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "HQ_yOT5_Hyt4",+ "outputId": "57cfb6c3-961f-4377-aa3f-2f113676e679"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "import os\n",+ "from getpass import getpass\n",+ "\n",+ "# Prompt for the AgentOps API key securely\n",+ "agentops_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"AGENTOPS_API_KEY\"] = agentops_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "czxWvnvnAimt"+ },+ "source": [+ "Your can go to [here](https://console.mistral.ai/api-keys/) to get API Key from Mistral AI with **free** credits."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "T0FBl1WF6jFs",+ "outputId": "3d7b95b9-9b30-4d96-bafd-da8ec93de27e"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "# Prompt for the API key securely\n",+ "mistral_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"MISTRAL_API_KEY\"] = mistral_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "qdG7LbDgDNe7"+ },+ "source": [+ "Set up the Mistral Large 2 model using the CAMEL ModelFactory. You can also configure other models as needed."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "ojjHCTsUDK6s"+ },+ "outputs": [],+ "source": [+ "from camel.models import ModelFactory\n",+ "from camel.types import ModelPlatformType, ModelType\n",+ "from camel.configs import MistralConfig\n",+ "\n",+ "# Set up model\n",+ "mistral_large_2 = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.MISTRAL,\n",+ " model_type=ModelType.MISTRAL_LARGE,\n",+ " model_config_dict=MistralConfig(temperature=0.2).as_dict(),\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "akkwlXcjTLcH"+ },+ "source": [+ "Your can go to [here](https://www.firecrawl.dev/) to get API Key from Firecrawl with **free** credits."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "0byeytnFWiaG",+ "outputId": "e7e513a0-31aa-477b-c2cf-c27cc2defbfb"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "# Prompt for the Firecrawl API key securely\n",+ "firecrawl_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"FIRECRAWL_API_KEY\"] = firecrawl_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "kiyIq4I3pSE2"+ },+ "source": [+ "## ๐ Web Scraping with Firecrawl"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "qgx3GS9LNaVe"+ },+ "source": [+ "Firecrawl is a powerful tool that simplifies web scraping and cleaning content from web pages. In this section, we will scrape content from a specific post on the CAMEL AI website as an example."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "i1jiXAdopRNH",+ "outputId": "4f2992da-d3e9-4844-83cd-aaa8fde42d15"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "CRAB: Cross-environment Agent Benchmark for Multimodal Language Model Agents\n",+ "============================================================================\n",+ "\n",+ "> Abstract: Recently, spearheaded by the CAMEL-AI community, a pioneer in open-source multi-agent projects, researchers from institutions such as King Abdullah University of Science and Technology, Oxford University, University of Tokyo, Carnegie Mellon University, Stanford University, and Tsinghua University have developed a cross-platform multimodal agent benchmark framework: CRAB, innovatively enabling agents to operate multiple devices simultaneously.\n",+ "\n",+ "### Introduction\n",+ "\n",+ "With the rapid development of multimodal large language models (MLLM), many agents capable of operating graphical user interfaces (GUIs) have emerged this year. Various companies have launched their innovative solutions, creating intense competition. GUI agents, leveraging powerful visual understanding and reasoning abilities of large models, can now efficiently and flexibly complete tasks such as booking appointments, shopping, and controlling smart homes.\n",+ "\n",+ "**This raises the question: will future agents truly be able to sit in front of a computer and work on my behalf?**\n",+ "\n",+ "However, in today's era of the Internet of Everything, most work requires the coordination of multiple devices. For example, taking a photo with a phone and then transferring it to a computer for editing involves crossing two different devices (environments). Currently, these GUI agents can only operate on a single device, making what is an easy task for humans exceedingly difficult for today's agents.\n",+ "\n",+ "Researchers from the CAMEL-AI community noticed this problem and proposed the first cross-environment, multi-device agent benchmark frameworkโCRAB, the **CR**oss-environment **A**gent **B**enchmark.\n",+ "\n",+ "\n",+ "\n",+ "Paper link: [https://arxiv.org/abs/2407.01511](https://arxiv.org/abs/2407.01511)\n",+ "\n",+ "The CAMEL framework ([https://github.com/camel-ai](https://github.com/camel-ai)\n",+ ") developed by the CAMEL-AI community is one of the earliest open-source multi-agent projects based on large language models. Therefore, community members are researchers and engineers with rich research and practical experience in the field of agents.\n",+ "\n",+ "In CRAB, the authors not only designed a network-based multi-environment architecture that enables agents to operate multiple devices simultaneously to complete tasks, but also proposed two new technologies to address the issues existing in current agent benchmarks: the graph evaluator and task synthesis. CRAB is not only a brand new benchmark tool but also provides an interaction protocol and its implementation between the environment and agents, which is expected to become an important foundation for agents in practical fields.\n",+ "\n",+ "The authors believe that CRAB will become one of the standards for evaluating GUI agents in the future, and thus have put considerable effort into improving the framework's usability. The entire codebase adopts a modular design, with the configuration of each environment abstracted into independent and reusable components. Users can easily and quickly build multiple custom environments like building blocks and create their own benchmarks based on them.\n",+ "\n",+ "For users who wish to evaluate their agents' performance using CRAB, the authors thoughtfully provide a hard disk image on the Google Cloud Platform. With just one click, all the tedious configurations of virtual machines, deep learning models, Python packages, etc., will be completed automatically, allowing users to immediately engage in important experiments.\n",+ "\n",+ "Currently, CRAB's paper has been published on Arxiv, and the related code and data are open-sourced on the CAMEL-AI community's GitHub.\n",+ "\n",+ "GitHub repository: [https://github.com/camel-ai/crab](https://github.com/camel-ai/crab)\n",+ "\n",+ "What does CRAB look like in operation? Let's take a look at the video below: \n",+ "\n",+ "โ\n",+ "\n",+ "\n",+ "\n",+ "The process of testing a multi-agent system on CRAB.\n",+ "\n",+ "First, the system extracts tasks from the dataset, passes the task instructions to the main agent, and initializes the corresponding graph evaluator in CRAB.\n",+ "\n",+ "The workflow is a loop: the main agent observes, plans, and instructs the sub-agents; each sub-agent corresponds to an environment. In the diagram, two sub-agents are responsible for the Ubuntu system computer and the Android system phone, respectively, and the sub-agents perform operations in their respective platforms.\n",+ "\n",+ "The graph evaluator monitors the state of each environment in the platform, updates the progress of the agent in completing the task after each operation, and outputs evaluation metrics.\n",+ "\n",+ "Having understood how CRAB works, it's time to see how current models perform on this new benchmark. The authors introduced CRAB-Benchmark-v0, a dataset supporting two environments with a total of 100 tasks, and tested several state-of-the-art models.\n",+ "\n",+ "\n",+ "\n",+ "As shown, the best-performing GPT-4o scored only 35.26 (CR refers to completion rate).\n",+ "\n",+ "Cross-platform tasks are much more complex than single-platform tasks, and achieving the top score already demonstrates the outstanding ability of the GPT-4 series models in solving practical problems. However, we believe that emerging new methods and models can achieve better scores on CRAB, truly becoming efficient tools for solving real-world problems.\n",+ "\n",+ "### Cross-Platform Multimodal Agent Evaluation\n",+ "\n",+ "CRAB provides a comprehensive interactive agent evaluation framework. Through CRAB's foundational setup, agents can operate on various devices and platforms simultaneously, efficiently completing tasks in multiple isolated systems.\n",+ "\n",+ "The authors propose a new evaluation method called the graph evaluator, which differs from traditional methods based on final goals or action trajectories. The graph evaluator checks the intermediate states of task completion by breaking down tasks into multiple sub-goals.\n",+ "\n",+ "Each sub-goal is assigned an evaluation function to verify its completion, with each sub-goal being treated as a node in the graph evaluator.\n",+ "\n",+ "The graph structure describes the precedence and parallel relationships between sub-goals, thus providing fine-grained evaluation metrics; at the same time, the independent evaluation function for each sub-goal inherently adapts to multiple platforms.\n",+ "\n",+ "\n",+ "\n",+ "The table above compares CRAB with existing frameworks, including several key capabilities involved in testing:\n",+ "\n",+ "* **Interactive Environment:** Indicates whether an interactive platform or static dataset is used.\n",+ "* **Multimodal Observation:** Indicates whether multimodal input (e.g., screenshots) is supported.\n",+ "* **Cross-platform:** Indicates whether multiple operating systems or platforms are supported simultaneously.\n",+ "* **Evaluation:** Describes evaluation metrics, divided into goal-based (only checking if the final goal is completed), trajectory-based (comparing the agent's action trajectory with a predefined standard action sequence), multiple (varies by task), or graph-based (each node as an intermediate checkpoint in a DAG).\n",+ "* **Task Construction:** Shows the method of constructing tasks in the test dataset, including manually created, LLM-inspired (e.g., LLM generates task drafts but is verified and annotated by humans), template (multiple tasks generated based on manually written templates), or sub-task composition (composing multiple sub-tasks to construct task descriptions and evaluators).\n",+ "\n",+ "Based on the CRAB framework, the authors developed a benchmark dataset, CRAB Benchmark v0, supporting Android and Ubuntu environments.\n",+ "\n",+ "The benchmark includes 100 real-world tasks, covering various levels of difficulty for cross-platform and single-platform tasks. Tasks involve a variety of common issues and use multiple practical applications and tools, including but not limited to calendars, emails, maps, web browsers, and terminals, also replicating common coordination methods between smartphones and computers.\n",+ "\n",+ "\n",+ "\n",+ "### Problem Definition\n",+ "\n",+ "Assume an agent autonomously executes tasks on a device (such as a desktop). The device is usually equipped with input devices (like a mouse and keyboard) and output devices (like a screen) for human-computer interaction. The authors refer to a device or application with a fixed input method and output method as an environment.\n",+ "\n",+ "Formally, a single environment can be defined as a reward-free partially observable Markov decision process (Reward-free POMDP), represented by a tuple M := (S, A, T, O), where S represents the state space, A represents the action space, T: S ร A โ S is the transition function, and O is the observation space.\n",+ "\n",+ "Considering the collaborative nature of multiple devices in real-world scenarios, multiple platforms can be combined into a set M = {M1, M2, ..., Mn}, where n is the number of platforms, and each platform can be represented as Mj = (Sj, Aj, Tj, Oj).\n",+ "\n",+ "A task requiring operation across multiple platforms can be formalized as a tuple (M, I, R), where M is the platform set, I is the task goal described in natural language, and R is the task reward function.\n",+ "\n",+ "The authors call the algorithm responsible for completing the task the agent system. Each agent in the agent system uses a fixed backend model and predefined system prompt, retaining its dialogue history. The agent system can be a single agent or a multi-agent system with multiple agents cooperating.\n",+ "\n",+ "### Graph of Decomposed Tasks\n",+ "\n",+ "\n",+ "\n",+ "Breaking down complex tasks into simpler sub-tasks is an effective method for prompting large language models. The authors introduced this concept into the benchmark field, breaking down complex tasks into sub-tasks with precedence and parallel relationships, known as the Graph of Decomposed Tasks (GDT) as shown above.\n",+ "\n",+ "GDT uses a graph-based task decomposition method: using a DAG structure to represent decomposed sub-tasks.\n",+ "\n",+ "In GDT, each node is a sub-task, formalized as a tuple (m, i, r), where m specifies the environment for executing the sub-task, i provides natural language instructions, and r represents the reward function. The reward function evaluates the state of environment m and outputs a boolean value to determine if the sub-task is completed. Edges in GDT represent the precedence relationships between sub-tasks.\n",+ "\n",+ "### Graph Evaluator\n",+ "\n",+ "To evaluate the capabilities of large language models as agents, most benchmarks rely solely on the final state of the platform after the agent's operations.\n",+ "\n",+ "Simply judging whether the final goal is successful or failed is obviously not fair; it's like in a math exam, even if you can't solve the big problem, you should get points for writing some solution steps.\n",+ "\n",+ "Another method is trajectory-based matching, comparing the agent's operations with a predefined standard operation sequence (Label) for each task.\n",+ "\n",+ "However, in real-world systems, tasks may have multiple valid execution paths. For example, copying a file can be done using a file manager or a command line. Specifying a unique correct path is unfair to agents that achieve the goal in different ways.\n",+ "\n",+ "Therefore, this paper adopts a graph evaluator synchronized with platform states, tracking the agent's progress through the current state of sub-task completion.\n",+ "\n",+ "In addition to the traditional success rate (SR), which marks a task as successful only when all sub-tasks are completed, the authors introduced three metrics to measure the agent's performance and efficiency:\n",+ "\n",+ "1. **Completion Rate (CR):** Measures the proportion of completed sub-task nodes, calculated as the number of completed nodes/total nodes. This metric intuitively reflects the agent's progress on the given task.\n",+ "2. **Execution Efficiency (EE):** Calculated as CR/A, where A represents the number of actions performed, reflecting the agent's task execution efficiency.\n",+ "3. **Cost Efficiency (CE):** Calculated as CR/T, where T is the total number of tokens used by the agent, evaluating the agent's efficiency in terms of cost.\n",+ "\n",+ "### Experiments\n",+ "\n",+ "To run in Crab Benchmark-v0, the backend model needs to support the following features:\n",+ "\n",+ "1. Support multimodal mixed input: The system provides both screenshots and text instructions as prompts.\n",+ "2. Support multi-turn conversations: All tasks require the agent to perform multiple operations, so historical messages must be stored in context.\n",+ "3. Generate structured output through Function Call or similar functions: Used to execute operations in the environment.\n",+ "\n",+ "The experiments selected four multimodal models that meet these criteria: GPT-4o, GPT-4 Turbo, Gemini 1.5 Pro, and Claude 3 Opus.\n",+ "\n",+ "To compare the performance differences between multi-agent and single-agent systems, the paper designed three different agent systems:\n",+ "\n",+ "1. **Single Agent:** A single agent handles the entire process from understanding the task, observing the environment, planning, to executing actions.\n",+ "2. **Multi-agent by Functionality:** Consists of a main agent and a sub-agent. The main agent observes the environment and provides instructions to the sub-agent, which translates the instructions into specific operations.\n",+ "3. **Multi-agent by Environment:** Consists of a main agent and multiple sub-agents. Each sub-agent is responsible for one environment. The main agent understands the task, plans the execution process, and provides instructions to each sub-agent. The sub-agents observe their respective environments and translate the instructions into specific operations.\n",+ "\n",+ "The combinations of different agent systems and backend models provide multiple dimensions for comparison. Additionally, the paper compares the performance of models in tasks involving different platforms:\n",+ "\n",+ "**Ubuntu single-platform tasks:**\n",+ "\n",+ "\n",+ "\n",+ "**Android single-platform tasks:**\n",+ "\n",+ "\n",+ "\n",+ "**Cross-platform tasks:**\n",+ "\n",+ "\n",+ "\n",+ "Through data analysis, the paper draws several conclusions:\n",+ "\n",+ "**Performance Differences Among Models:**\n",+ "\n",+ "1. GPT-4o has the highest success and completion rates overall.\n",+ "2. GPT-4 TURBO performs better in cost efficiency (CE) than other models.\n",+ "3. Gemini 1.5 Pro and Claude 3 Opus struggle with task completion, finding it almost impossible to complete tasks.**โ**\n",+ "\n",+ "**Efficiency Metrics Reflect Different Characteristics of Models:**\n",+ "\n",+ "1. GPT-4 TURBO shows excellent cost efficiency in the single-agent mode, demonstrating cost-effective performance.\n",+ "2. GPT-4o maintains a balance between efficiency and performance, especially in the single-agent mode.\n",+ "3. Gemini 1.5 Pro shows low efficiency and incomplete cost efficiency metrics, mainly due to its low completion rate.\n",+ "\n",+ "**Evaluation of Termination Reasons Indicates Areas for Improvement:**\n",+ "\n",+ "1. All models have a high percentage of reaching the step limit (RSL), indicating that agents often run out of steps without achieving the final goal.\n",+ "2. Gemini 1.5 Pro has a high rate of invalid actions (IA), highlighting its inability to stably generate the correct format for interacting with the environment.\n",+ "3. The false completion (FC) rate in multi-agent systems is higher than in single-agent systems, indicating that message loss during communication between multiple agents can easily cause the executing sub-agent to misjudge.\n",+ "\n",+ "### ๐ซ Thanks from everyone at CAMEL-AI\n",+ "\n",+ "Hello there, passionate AI enthusiasts! ๐ We are ๐ซ CAMEL-AI.org, a global coalition of students, researchers, and engineers dedicated to advancing the frontier of AI and fostering a harmonious relationship between agents and humans.\n",+ "\n",+ "**๐ Our Mission:** To harness the potential of AI agents in crafting a brighter and more inclusive future for all. Every contribution we receive helps push the boundaries of whatโs possible in the AI realm.\n",+ "\n",+ "**๐ Join Us:** If you believe in a world where AI and humanity coexist and thrive, then youโre in the right place. Your support can make a significant difference. Letโs build the AI society of tomorrow, together!\n",+ "\n",+ "* Find all our updates on [X](https://twitter.com/CamelAIOrg)\n",+ " .\n",+ "* Make sure to star our [GitHub](https://github.com/camel-ai)\n",+ " repositories.\n",+ "* Join our [Discord,](https://discord.gg/nCpraan3sS)\n",+ " [WeChat](https://ghli.org/camel/wechat.png)\n",+ " or [Slack](https://join.slack.com/t/camel-ai/shared_invite/zt-2icssxnkj-YHwFVhoZHMYpIG~ZU86WVw)\n",+ " community.\n",+ "* You can contact us by email: [email protected]\n",+ "* Dive deeper and explore our projects on [https://www.camel-ai.org/](https://www.camel-ai.org/)\n",+ " \n",+ "\n",+ "> โ\n",+ "\n",+ "Get started\n",+ "\n",+ "Build your multi-agent system today\n",+ "-----------------------------------\n",+ "\n",+ "Get started by joining our community\n",+ "\n",+ "[Join Discord](https://discord.gg/rBnhgxy6Fg)\n",+ "\n",+ "\n",+ "\n",+ "Finding the scaling law of agents\n",+ "\n",+ "[](#)\n",+ "\n",+ "Resource\n",+ "\n",+ "[Docs](http://docs.camel-ai.org/)\n",+ "[Agent Trust](https://agent-trust.camel-ai.org/)\n",+ "\n",+ "Company\n",+ "\n",+ "[Blog](/blog)\n",+ "[Team](/about)\n",+ "\n",+ "SOCIALS\n",+ "\n",+ "[Discord](https://discord.gg/3rWmpWegBK)\n",+ "[Github](https://github.com/camel-ai/camel)\n",+ "[LinkedIn](https://www.linkedin.com/company/camel-ai-org/)\n",+ "[Twitter](https://x.com/CamelAIOrg)\n",+ "[YouTube](https://www.youtube.com/@CamelAI)\n",+ "\n",+ "Copyright ยฉ 2024 Eigent AI - All Rights Reserved.\n"+ ]+ }+ ],+ "source": [+ "from camel.loaders import Firecrawl\n",+ "\n",+ "firecrawl = Firecrawl()\n",+ "\n",+ "# Scrape and clean content from a specified URL\n",+ "response = firecrawl.tidy_scrape(\n",+ " url=\"https://www.camel-ai.org/post/crab\"\n",+ ")\n",+ "\n",+ "print(response)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "q5NJlRL1N5vu"+ },+ "source": [+ "**๐ Firecrawl makes obtaining clean, LLM-friendly content from URL effortless!**"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "NEUciNquON9_"+ },+ "source": [+ "## ๐ ๏ธ Web Information Retrieval using CAMEL's RAG and Firecrawl"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "6f64VOMMP93d"+ },+ "source": [+ "*In this section, we'll demonstrate how to retrieve relevant information from a list of URLs using CAMEL's RAG model. This is particularly useful for aggregating and analyzing data from multiple sources.*"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "46Irp_SurLaV"+ },+ "source": [+ "### Setting Up Firecrawl with CAMEL's RAG"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "QVB-Xra8QIU1"+ },+ "source": [+ "The following function retrieves relevant information from a list of URLs based on a given query. It combines web scraping with Firecrawl and CAMEL's AutoRetriever for a seamless information retrieval process."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "gE_qBFCVveBR"+ },+ "outputs": [],+ "source": [+ "from camel.retrievers import AutoRetriever\n",+ "from camel.toolkits import OpenAIFunction, SearchToolkit\n",+ "from camel.types import ModelPlatformType, ModelType, StorageType\n",+ "from camel.embeddings import MistralEmbedding"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "A75lxSmLsLSr"+ },+ "outputs": [],+ "source": [+ "def retrieve_information_from_urls(urls: list[str], query: str) -> str:\n",+ " r\"\"\"Retrieves relevant information from a list of URLs based on a given\n",+ " query.\n",+ "\n",+ " This function uses the `Firecrawl` tool to scrape content from the\n",+ " provided URLs and then uses the `AutoRetriever` from CAMEL to retrieve the\n",+ " most relevant information based on the query from the scraped content.\n",+ "\n",+ " Args:\n",+ " urls (list[str]): A list of URLs to scrape content from.\n",+ " query (str): The query string to search for relevant information.\n",+ "\n",+ " Returns:\n",+ " str: The most relevant information retrieved based on the query.\n",+ "\n",+ " Example:\n",+ " >>> urls = [\"https://example.com/article1\", \"https://example.com/\n",+ " article2\"]\n",+ " >>> query = \"latest advancements in AI\"\n",+ " >>> result = retrieve_information_from_urls(urls, query)\n",+ " \"\"\"\n",+ " aggregated_content = ''\n",+ "\n",+ " # Scrape and aggregate content from each URL\n",+ " for url in urls:\n",+ " scraped_content = Firecrawl().tidy_scrape(url)\n",+ " aggregated_content += scraped_content\n",+ "\n",+ " # Set up a vector retriever with local storage and embedding model from Mistral AI\n",+ " auto_retriever = AutoRetriever(\n",+ " vector_storage_local_path=\"local_data\",\n",+ " storage_type=StorageType.QDRANT,\n",+ " embedding_model=MistralEmbedding(),\n",+ " )\n",+ "\n",+ " # Retrieve the most relevant information based on the query\n",+ " # You can adjust the top_k and similarity_threshold value based on your needs\n",+ " retrieved_info = auto_retriever.run_vector_retriever(\n",+ " query=query,\n",+ " contents=aggregated_content,\n",+ " top_k=3,\n",+ " similarity_threshold=0.5,\n",+ " )\n",+ "\n",+ " return retrieved_info"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "nLh5nU7uUeo-"+ },+ "source": [+ "Let's put the retrieval function to the test by gathering some information about the 2024 Olympics.\n",+ "The first run may take about 50 seconds as it needs to build a local vector database."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "z4z00v9yWvFw",+ "outputId": "8e6b934e-cf12-4236-d0c8-a7367c60e1f1"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Original Query:\n",+ "{ Which country won the most golden prize in 2024 Olympics? }\n",+ "Retrieved Context:\n",+ "ticle\n",+ " \n",+ "\n",+ "Aug. 11, 2024, 4:49 PM UTCย /ย Updatedย Aug. 11, 2024, 9:22 PM UTC\n",+ "\n",+ "By [David K. Li](https://www.nbcnews.com/author/david-k-li-ncpn915856)\n",+ " and Sean Nevin\n",+ "\n",+ "PARIS โ The U.S. and [China](https://www.nbcnews.com/news/world/philippine-military-china-aircraft-south-china-sea-rcna166073)\n",+ " each won 40 gold medals in the [first Summer Games draw in Olympic history](https://www.nbcnews.com/news/world/china-beat-us-paris-2024-olympics-gold-medal-table-rcna166123)\n",+ ", with the Americans pulling into\n",+ "from Paris this year.\n",+ "\n",+ "The U.S. hasnโt failed to win [the most medals since 1992](https://olympics.com/en/olympic-games/barcelona-1992/medals)\n",+ ", when the โUnified Team,โย athletes from the former Soviet Union republics, won 112 medals, including 45 golds. The Americans made 108 podium visits in Barcelona, with 37 of them on the top step.\n",+ "\n",+ "\n",+ "\n",+ "print(retrieved_info)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "r8QpOBNLX-R_"+ },+ "source": [+ "**๐ Thanks to CAMEL's RAG pipeline and Firecrawl's tidy scraping capabilities, this function effectively retrieves relevant information from the specified URLs! You can now integrate this function into CAMEL's Agents to automate the retrieval process further.**"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "b7jyteu-2SFc"+ },+ "source": [+ "## ๐น Monitoring AI Agents with AgentOps"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "mHSfqXyhIK0N",+ "outputId": "3f1c025e-87f7-439d-8ced-b63e03d94c56"+ },+ "outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "๐ AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=a7deea00-864e-461d-956b-1e78ebeea350\u001b[0m\u001b[0m\n"+ ]+ },+ {+ "data": {+ "text/plain": [+ "<agentops.session.Session at 0x7cc6847b1870>"+ ]+ },+ "execution_count": 11,+ "metadata": {},+ "output_type": "execute_result"+ }+ ],+ "source": [+ "import agentops\n",+ "agentops.init(default_tags=[\"CAMEL cookbook\"])"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "n1Q8IKWUrAkr"+ },+ "source": [+ "## ๐ง Knowledge Graph Construction"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "dD7p_9CkyUmK"+ },+ "source": [+ "*A powerful feature of CAMEL is its ability to build and store knowledge graphs from text data. This allows for advanced analysis and visualization of relationships within the data.*"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "k_fZhcgnrUX1"+ },+ "source": [+ "Set up your Neo4j instance by providing the URL, username, and password, [here](https://neo4j.com/docs/aura/auradb/getting-started/create-database/) is the guidance, check your credentials in the downloaded .txt file. Note that you may need to wait up to 60 seconds if the instance has just been set up."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "raMV4BwhrhNK"+ },+ "outputs": [],+ "source": [+ "from camel.storages import Neo4jGraph\n",+ "from camel.loaders import UnstructuredIO\n",+ "from camel.agents import KnowledgeGraphAgent\n",+ "\n",+ "def knowledge_graph_builder(text_input: str) -> None:\n",+ " r\"\"\"Build and store a knowledge graph from the provided text.\n",+ "\n",+ " This function processes the input text to create and extract nodes and relationships,\n",+ " which are then added to a Neo4j database as a knowledge graph.\n",+ "\n",+ " Args:\n",+ " text_input (str): The input text from which the knowledge graph is to be constructed.\n",+ "\n",+ " Returns:\n",+ " graph_elements: The generated graph element from knowlegde graph agent.\n",+ " \"\"\"\n",+ "\n",+ " # Set Neo4j instance\n",+ " n4j = Neo4jGraph(\n",+ " url=\"Your_URI\",\n",+ " username=\"Your_Username\",\n",+ " password=\"Your_Password\",\n",+ " )\n",+ "\n",+ " # Initialize instances\n",+ " uio = UnstructuredIO()\n",+ " kg_agent = KnowledgeGraphAgent(model=mistral_large_2)\n",+ "\n",+ " # Create an element from the provided text\n",+ " element_example = uio.create_element_from_text(text_input, element_id=\"001\")\n",+ "\n",+ " # Extract nodes and relationships using the Knowledge Graph Agent\n",+ " graph_elements = kg_agent.run(element_example, parse_graph_elements=True)\n",+ "\n",+ " # Add the extracted graph elements to the Neo4j database\n",+ " n4j.add_graph_elements(graph_elements=[graph_elements])\n",+ "\n",+ " return graph_elements\n"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "uiDkPPrBshW4"+ },+ "source": [+ "## ๐ค๐ค Multi-Agent Role-Playing with CAMEL"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "6MZVoQI7OltM"+ },+ "source": [+ "*This section sets up a role-playing session where AI agents interact to accomplish a task using various tools. We will guide the assistant agent to perform a comprehensive study of the Turkish shooter in the 2024 Paris Olympics.*"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "JTWQ4i6tt6mh"+ },+ "outputs": [],+ "source": [+ "from typing import List\n",+ "\n",+ "from colorama import Fore\n",+ "\n",+ "from camel.agents.chat_agent import FunctionCallingRecord\n",+ "from camel.societies import RolePlaying\n",+ "from camel.utils import print_text_animated"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "ggqh3_t9tURm"+ },+ "source": [+ "Defining the Task Prompt"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "rtwuPLI_ssrX"+ },+ "outputs": [],+ "source": [+ "task_prompt = \"\"\"Do a comprehensive study of the Turkish shooter in 2024 paris\n",+ "olympics, write a report for me, then create a knowledge graph for the report.\n",+ "You should use search tool to get related URLs first, then use retrieval tool\n",+ "to get the retrieved content back by providing the list of URLs, finially\n",+ "use tool to build the knowledge graph to finish the task.\n",+ "No more other actions needed\"\"\""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "KI0k6XJZtaN5"+ },+ "source": [+ "We will configure the assistant agent with tools for mathematical calculations, web information retrieval, and knowledge graph building."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "Bw3_LyXiteVT"+ },+ "outputs": [],+ "source": [+ "retrieval_tool = OpenAIFunction(retrieve_information_from_urls)\n",+ "search_tool = OpenAIFunction(SearchToolkit().search_duckduckgo)\n",+ "knowledge_graph_tool = OpenAIFunction(knowledge_graph_builder)\n",+ "\n",+ "tool_list = [\n",+ " retrieval_tool,\n",+ " search_tool,\n",+ " knowledge_graph_tool,\n",+ "]\n",+ "\n",+ "assistant_model_config = MistralConfig(\n",+ " tools=tool_list,\n",+ " temperature=0.0,\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Yc80X_ZItyvi"+ },+ "source": [+ "Setting Up the Role-Playing Session"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "insV1gSyt0b3"+ },+ "outputs": [],+ "source": [+ "# Initialize the role-playing session\n",+ "role_play_session = RolePlaying(\n",+ " assistant_role_name=\"CAMEL Assistant\",\n",+ " user_role_name=\"CAMEL User\",\n",+ " assistant_agent_kwargs=dict(\n",+ " model=ModelFactory.create(\n",+ " model_platform=ModelPlatformType.MISTRAL,\n",+ " model_type=ModelType.MISTRAL_LARGE,\n",+ " model_config_dict=assistant_model_config.as_dict(),\n",+ " ),\n",+ " tools=tool_list,\n",+ " ),\n",+ " user_agent_kwargs=dict(model=mistral_large_2),\n",+ " task_prompt=task_prompt,\n",+ " with_task_specify=False,\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "o7vfyJMdt8R1"+ },+ "source": [+ "Print the system message and task prompt"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "9xMDZxBmt-Ms",+ "outputId": "789533f1-6763-455f-fd11-9c85967de36f"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[32mAI Assistant sys message:\n",+ "BaseMessage(role_name='CAMEL Assistant', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={'task': 'Do a comprehensive study of the Turkish shooter in 2024 paris\\nolympics, write a report for me, then create a knowledge graph for the report.\\nYou should use search tool to get related URLs first, then use retrieval tool\\nto get the retrieved content back by providing the list of URLs, finially\\nuse tool to build the knowledge graph to finish the task.\\nNo more other actions needed', 'assistant_role': 'CAMEL Assistant', 'user_role': 'CAMEL User'}, content='===== RULES OF ASSISTANT =====\\nNever forget you are a CAMEL Assistant and I am a CAMEL User. Never flip roles! Never instruct me!\\nWe share a common interest in collaborating to successfully complete a task.\\nYou must help me to complete the task.\\nHere is the task: Do a comprehensive study of the Turkish shooter in 2024 paris\\nolympics, write a report for me, then create a knowledge graph for the report.\\nYou should use search tool to get related URLs first, then use retrieval tool\\nto get the retrieved content back by providing the list of URLs, finially\\nuse tool to build the knowledge graph to finish the task.\\nNo more other actions needed. Never forget our task!\\nI must instruct you based on your expertise and my needs to complete the task.\\n\\nI must give you one instruction at a time.\\nYou must write a specific solution that appropriately solves the requested instruction and explain your solutions.\\nYou must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\\nUnless I say the task is completed, you should always start with:\\n\\nSolution: <YOUR_SOLUTION>\\n\\n<YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.\\nAlways end <YOUR_SOLUTION> with: Next request.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[34mAI User sys message:\n",+ "BaseMessage(role_name='CAMEL User', role_type=<RoleType.USER: 'user'>, meta_dict={'task': 'Do a comprehensive study of the Turkish shooter in 2024 paris\\nolympics, write a report for me, then create a knowledge graph for the report.\\nYou should use search tool to get related URLs first, then use retrieval tool\\nto get the retrieved content back by providing the list of URLs, finially\\nuse tool to build the knowledge graph to finish the task.\\nNo more other actions needed', 'assistant_role': 'CAMEL Assistant', 'user_role': 'CAMEL User'}, content='===== RULES OF USER =====\\nNever forget you are a CAMEL User and I am a CAMEL Assistant. Never flip roles! You will always instruct me.\\nWe share a common interest in collaborating to successfully complete a task.\\nI must help you to complete the task.\\nHere is the task: Do a comprehensive study of the Turkish shooter in 2024 paris\\nolympics, write a report for me, then create a knowledge graph for the report.\\nYou should use search tool to get related URLs first, then use retrieval tool\\nto get the retrieved content back by providing the list of URLs, finially\\nuse tool to build the knowledge graph to finish the task.\\nNo more other actions needed. Never forget our task!\\nYou must instruct me based on my expertise and your needs to solve the task ONLY in the following two ways:\\n\\n1. Instruct with a necessary input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: <YOUR_INPUT>\\n\\n2. Instruct without any input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: None\\n\\nThe \"Instruction\" describes a task or question. The paired \"Input\" provides further context or information for the requested \"Instruction\".\\n\\nYou must give me one instruction at a time.\\nI must write a response that appropriately solves the requested instruction.\\nI must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.\\nYou should instruct me not ask me questions.\\nNow you must start to instruct me using the two ways described above.\\nDo not add anything else other than your instruction and the optional corresponding input!\\nKeep giving me instructions and necessary inputs until you think the task is completed.\\nWhen the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.\\nNever say <CAMEL_TASK_DONE> unless my responses have solved your task.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n",+ "\n",+ "\u001b[33mOriginal task prompt:\n",+ "Do a comprehensive study of the Turkish shooter in 2024 paris\n",+ "olympics, write a report for me, then create a knowledge graph for the report.\n",+ "You should use search tool to get related URLs first, then use retrieval tool\n",+ "to get the retrieved content back by providing the list of URLs, finially\n",+ "use tool to build the knowledge graph to finish the task.\n",+ "No more other actions needed\n",+ "\n",+ "\u001b[36mSpecified task prompt:\n",+ "None\n",+ "\n",+ "\u001b[31mFinal task prompt:\n",+ "Do a comprehensive study of the Turkish shooter in 2024 paris\n",+ "olympics, write a report for me, then create a knowledge graph for the report.\n",+ "You should use search tool to get related URLs first, then use retrieval tool\n",+ "to get the retrieved content back by providing the list of URLs, finially\n",+ "use tool to build the knowledge graph to finish the task.\n",+ "No more other actions needed\n",+ "\n"+ ]+ }+ ],+ "source": [+ "# Print system and task messages\n",+ "print(\n",+ " Fore.GREEN\n",+ " + f\"AI Assistant sys message:\\n{role_play_session.assistant_sys_msg}\\n\"\n",+ ")\n",+ "print(Fore.BLUE + f\"AI User sys message:\\n{role_play_session.user_sys_msg}\\n\")\n",+ "\n",+ "print(Fore.YELLOW + f\"Original task prompt:\\n{task_prompt}\\n\")\n",+ "print(\n",+ " Fore.CYAN\n",+ " + \"Specified task prompt:\"\n",+ " + f\"\\n{role_play_session.specified_task_prompt}\\n\"\n",+ ")\n",+ "print(Fore.RED + f\"Final task prompt:\\n{role_play_session.task_prompt}\\n\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "1ibe4da9uB2H"+ },+ "source": [+ "Set the termination rule and start the interaction between agents\n",+ "\n",+ "**NOTE**: This session will take approximately 8 minutes and will consume around 60k tokens by using Mistral Large 2 Model."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "xOhdpjxuuH-2",+ "outputId": "5965f6c9-dbc3-4ec1-e96e-50959ce099be"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Use the search tool to find related URLs about the Turkish shooter in the 2024 Paris Olympics.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: search_duckduckgo\n",+ "\tArgs: {'query': 'Turkish shooter in the 2024 Paris Olympics'}\n",+ "\tResult: [{'result_id': 1, 'title': 'Turkish sharpshooter Yusuf Dikeรง wins silver at Paris Olympics with ...', 'description': \"Turkish sharpshooter Yusuf Dikeรง didn't need special lenses or big ear protectors to win the silver medal in the air pistol team event at the 2024 Paris Olympics.\", 'url': 'https://www.nbcnews.com/news/sports/sharpshooter-yusuf-dikec-silver-olympics-minimal-gear-internet-sensati-rcna164685'}, {'result_id': 2, 'title': 'Who is Yusuf Dikec, Turkish shooter who went viral at 2024 Olympics ...', 'description': 'Turkish pistol shooter Yusuf Dikec has gone viral on social media for his seemingly casual attitude while shooting his way to a silver medal at the 2024 Olympics.', 'url': 'https://apnews.com/article/olympics-2024-yusuf-dikec-turkish-shooter-a7890124304080a48e7ee4294004d306'}, {'result_id': 3, 'title': 'Meet Yusuf Dikec: The Turkish shooter who has gone viral at Paris 2024 ...', 'description': \"Dikec's popularity at Paris 2024. If there is a sign of how the times have changed since Dikec's Olympic debut in 2008, you only have to look at his sudden popularity on social media. Fans have been editing the Turkish shooter into film scenes, comparing him to characters from TV shows and video games and even drawing him.\", 'url': 'https://olympics.com/en/news/yusuf-dikec-turkish-shooting-viral-paris-2024-olympics'}, {'result_id': 4, 'title': \"Yusuf Dikeรง: Turkey's viral Olympian inspires new celebration with ...\", 'description': \"Turkey's Yusuf Dikec competes in the shooting 10m air pistol mixed team gold medal match during the Paris 2024 Olympic Games at Chateauroux Shooting Centre on July 30, 2024. ... while shooting ...\", 'url': 'https://www.cnn.com/2024/08/09/sport/yusuf-dikec-olympic-celebration-craze-spt-intl/index.html'}, {'result_id': 5, 'title': 'Why A Turkish Olympic Sharpshooter Became A Viral Sensation', 'description': 'Turkish sharpshooter Yusuf Dikec clinched the silver medal in the air pistol team event at the 2024 Paris Olympics. In doing so, the 51-year-old soared to internet stardom.', 'url': 'https://www.today.com/news/paris-olympics/turkish-olympics-shooter-viral-yusuf-dikec-rcna164765'}]\n",+ "\n",+ "Solution: I have used the search tool to find related URLs about the Turkish shooter in the 2024 Paris Olympics. Here are the results:\n",+ "\n",+ "1. Title: Turkish sharpshooter Yusuf Dikeรง wins silver at Paris Olympics with ...\n",+ " Description: Turkish sharpshooter Yusuf Dikeรง didn't need special lenses or big ear protectors to win the silver medal in the air pistol team event at the 2024 Paris Olympics.\n",+ " URL: https://www.nbcnews.com/news/sports/sharpshooter-yusuf-dikec-silver-olympics-minimal-gear-internet-sensati-rcna164685\n",+ "\n",+ "2. Title: Who is Yusuf Dikec, Turkish shooter who went viral at 2024 Olympics ...\n",+ " Description: Turkish pistol shooter Yusuf Dikec has gone viral on social media for his seemingly casual attitude while shooting his way to a silver medal at the 2024 Olympics.\n",+ " URL: https://apnews.com/article/olympics-2024-yusuf-dikec-turkish-shooter-a7890124304080a48e7ee4294004d306\n",+ "\n",+ "3. Title: Meet Yusuf Dikec: The Turkish shooter who has gone viral at Paris 2024 ...\n",+ " Description: Dikec's popularity at Paris 2024. If there is a sign of how the times have changed since Dikec's Olympic debut in 2008, you only have to look at his sudden popularity on social media. Fans have been editing the Turkish shooter into film scenes, comparing him to characters from TV shows and video games and even drawing him.\n",+ " URL: https://olympics.com/en/news/yusuf-dikec-turkish-shooting-viral-paris-2024-olympics\n",+ "\n",+ "4. Title: Yusuf Dikeรง: Turkey's viral Olympian inspires new celebration with ...\n",+ " Description: Turkey's Yusuf Dikec competes in the shooting 10m air pistol mixed team gold medal match during the Paris 2024 Olympic Games at Chateauroux Shooting Centre on July 30, 2024. ... while shooting ...\n",+ " URL: https://www.cnn.com/2024/08/09/sport/yusuf-dikec-olympic-celebration-craze-spt-intl/index.html\n",+ "\n",+ "5. Title: Why A Turkish Olympic Sharpshooter Became A Viral Sensation\n",+ " Description: Turkish sharpshooter Yusuf Dikec clinched the silver medal in the air pistol team event at the 2024 Paris Olympics. In doing so, the 51-year-old soared to internet stardom.\n",+ " URL: https://www.today.com/news/paris-olympics/turkish-olympics-shooter-viral-yusuf-dikec-rcna164765\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Use the retrieval tool to get the content from the provided URLs.\n",+ "Input: [\n",+ " \"https://www.nbcnews.com/news/sports/sharpshooter-yusuf-dikec-silver-olympics-minimal-gear-internet-sensati-rcna164685\",\n",+ " \"https://apnews.com/article/olympics-2024-yusuf-dikec-turkish-shooter-a7890124304080a48e7ee4294004d306\",\n",+ " \"https://olympics.com/en/news/yusuf-dikec-turkish-shooting-viral-paris-2024-olympics\",\n",+ " \"https://www.cnn.com/2024/08/09/sport/yusuf-dikec-olympic-celebration-craze-spt-intl/index.html\",\n",+ " \"https://www.today.com/news/paris-olympics/turkish-olympics-shooter-viral-yusuf-dikec-rcna164765\"\n",+ "]\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: retrieve_information_from_urls\n",+ "\tArgs: {'query': 'Turkish shooter in the 2024 Paris Olympics', 'urls': ['https://www.nbcnews.com/news/sports/sharpshooter-yusuf-dikec-silver-olympics-minimal-gear-internet-sensati-rcna164685', 'https://apnews.com/article/olympics-2024-yusuf-dikec-turkish-shooter-a7890124304080a48e7ee4294004d306', 'https://olympics.com/en/news/yusuf-dikec-turkish-shooting-viral-paris-2024-olympics', 'https://www.cnn.com/2024/08/09/sport/yusuf-dikec-olympic-celebration-craze-spt-intl/index.html', 'https://www.today.com/news/paris-olympics/turkish-olympics-shooter-viral-yusuf-dikec-rcna164765']}\n",+ "\tResult: Original Query:\n",+ "{ Turkish shooter in the 2024 Paris Olympics }\n",+ "Retrieved Context:\n",+ "ncing - Olympic Games Paris 2024: Day 2](https://media-cldnry.s-nbcnews.com/image/upload/t_fit-760w,f_auto,q_auto:best/rockcms/2024-07/240728-Kiefer-and-Scruggs-2-aa-653p-3c419c.jpg)\n",+ "\n",+ "Lee Kiefer of the U.S., center, Lauren Scruggs of the U.S., left, and Eleanor Harvey of Canada celebrate on the podium during the women's foil medal ceremony on July 28.Patrick Smith / Getty Images\n",+ "\n",+ "A host of countries that normally donโt get within a javelinโs throw of the podium produced several medalists these p\n",+ "from Paris this year.\n",+ "\n",+ "The U.S. hasnโt failed to win [the most medals since 1992](https://olympics.com/en/olympic-games/barcelona-1992/medals)\n",+ ", when the โUnified Team,โย athletes from the former Soviet Union republics, won 112 medals, including 45 golds. The Americans made 108 podium visits in Barcelona, with 37 of them on the top step.\n",+ "\n",+ "\n",+ " and Sean Nevin\n",+ "\n",+ "PARIS โ The U.S. and [China](https://www.nbcnews.com/news/world/philippine-military-china-aircraft-south-china-sea-rcna166073)\n",+ " each won 40 gold medals in the [first Summer Games draw in Olympic history](https://www.nbcnews.com/news/world/china-beat-us-paris-2024-olympics-gold-medal-table-rcna166123)\n",+ ", with the Americans pulling into\n",+ "\n",+ "Solution: I have used the retrieval tool to get the content from the provided URLs. Here is the retrieved content:\n",+ "\n",+ "Original Query:\n",+ "{ Turkish shooter in the 2024 Paris Olympics }\n",+ "Retrieved Context:\n",+ "\n",+ "\n",+ "\n",+ "Lee Kiefer of the U.S., center, Lauren Scruggs of the U.S., left, and Eleanor Harvey of Canada celebrate on the podium during the women's foil medal ceremony on July 28.Patrick Smith / Getty Images\n",+ "\n",+ "A host of countries that normally donโt get within a javelinโs throw of the podium produced several medalists these p\n",+ "from Paris this year.\n",+ "\n",+ "The U.S. hasnโt failed to win [the most medals since 1992](https://olympics.com/en/olympic-games/barcelona-1992/medals)\n",+ ", when the โUnified Team,โ\n",+ "athletes from the former Soviet Union republics, won 112 medals, including 45 golds. The Americans made 108 podium visits in Barcelona, with 37 of them on the top step.\n",+ "\n",+ "\n",+ " and Sean Nevin\n",+ "\n",+ "PARIS โ The U.S. and [China](https://www.nbcnews.com/news/world/philippine-military-china-aircraft-south-china-sea-rcna166073)\n",+ " each won 40 gold medals in the [first Summer Games draw in Olympic history](https://www.nbcnews.com/news/world/china-beat-us-paris-2024-olympics-gold-medal-table-rcna166123)\n",+ ", with the Americans pulling into\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Summarize the key points from the retrieved content about the Turkish shooter Yusuf Dikeรง at the 2024 Paris Olympics.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: Based on the retrieved content, here are the key points about the Turkish shooter Yusuf Dikeรง at the 2024 Paris Olympics:\n",+ "\n",+ "1. **Silver Medal Win**: Yusuf Dikeรง won the silver medal in the air pistol team event at the 2024 Paris Olympics.\n",+ "2. **Minimal Gear**: Dikeรง achieved this feat without using special lenses or big ear protectors, which is unusual for a shooter.\n",+ "3. **Viral Sensation**: His seemingly casual attitude while shooting and his minimal gear made him an internet sensation.\n",+ "4. **Social Media Popularity**: Fans have been editing Dikeรง into film scenes, comparing him to characters from TV shows and video games, and even drawing him, highlighting his sudden popularity on social media.\n",+ "5. **Age and Experience**: Dikeรง is 51 years old and has been competing in the Olympics since 2008, showcasing his longevity and experience in the sport.\n",+ "6. **Inspiration for Celebration**: Dikeรง's performance and attitude have inspired a new celebration trend among fans and athletes.\n",+ "\n",+ "These points summarize the key information about Yusuf Dikeรง's achievements and impact at the 2024 Paris Olympics.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Write a comprehensive report based on the summarized key points about the Turkish shooter Yusuf Dikeรง at the 2024 Paris Olympics.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: Certainly! Here is a comprehensive report based on the summarized key points about the Turkish shooter Yusuf Dikeรง at the 2024 Paris Olympics:\n",+ "\n",+ "---\n",+ "\n",+ "### Comprehensive Report on Turkish Shooter Yusuf Dikeรง at the 2024 Paris Olympics\n",+ "\n",+ "#### Introduction\n",+ "The 2024 Paris Olympics witnessed a remarkable performance by Turkish shooter Yusuf Dikeรง, who not only achieved significant success in his sport but also captured the attention of the global audience. This report delves into the key aspects of Dikeรง's journey and impact at the Olympics.\n",+ "\n",+ "#### Silver Medal Win\n",+ "Yusuf Dikeรง secured the silver medal in the air pistol team event at the 2024 Paris Olympics. This achievement is a testament to his skill and dedication to the sport of shooting. His performance was notable for its precision and consistency, which are crucial in competitive shooting.\n",+ "\n",+ "#### Minimal Gear\n",+ "One of the most striking aspects of Dikeรง's performance was his minimal use of gear. Unlike many of his competitors, Dikeรง did not rely on special lenses or large ear protectors. This unconventional approach added to his appeal and made his achievement even more impressive.\n",+ "\n",+ "#### Viral Sensation\n",+ "Dikeรง's seemingly casual attitude while shooting and his minimal gear made him an internet sensation. His unique style resonated with viewers, leading to widespread admiration and discussion on social media platforms. This unexpected fame highlighted the power of individuality and authenticity in capturing public interest.\n",+ "\n",+ "#### Social Media Popularity\n",+ "The sudden popularity of Yusuf Dikeรง on social media was evident through various creative expressions by fans. People edited Dikeรง into film scenes, compared him to characters from TV shows and video games, and even created drawings of him. This outpouring of creativity underscored the impact of his performance and personality on the global audience.\n",+ "\n",+ "#### Age and Experience\n",+ "At 51 years old, Yusuf Dikeรง brought a wealth of experience to the 2024 Paris Olympics. His Olympic journey began in 2008, showcasing his longevity and commitment to the sport. Dikeรง's continued success at this age is a testament to his enduring skill and passion for shooting.\n",+ "\n",+ "#### Inspiration for Celebration\n",+ "Dikeรง's performance and attitude inspired a new celebration trend among fans and athletes. His unique approach to the sport and the subsequent viral sensation he created have left a lasting impact on the Olympic community. This influence demonstrates the power of individual achievement in inspiring others.\n",+ "\n",+ "#### Conclusion\n",+ "Yusuf Dikeรง's journey at the 2024 Paris Olympics is a story of skill, individuality, and enduring passion. His silver medal win, minimal gear, viral sensation, social media popularity, age, and experience all contribute to a compelling narrative that has captivated the world. Dikeรง's impact extends beyond his sport, inspiring creativity and celebration among fans and athletes alike.\n",+ "\n",+ "---\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Use the knowledge graph tool to create a knowledge graph based on the report.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Function Execution: knowledge_graph_builder\n",+ "\tArgs: {'text_input': \"### Comprehensive Report on Turkish Shooter Yusuf Dikeรง at the 2024 Paris Olympics\\n\\n#### Introduction\\nThe 2024 Paris Olympics witnessed a remarkable performance by Turkish shooter Yusuf Dikeรง, who not only achieved significant success in his sport but also captured the attention of the global audience. This report delves into the key aspects of Dikeรง's journey and impact at the Olympics.\\n\\n#### Silver Medal Win\\nYusuf Dikeรง secured the silver medal in the air pistol team event at the 2024 Paris Olympics. This achievement is a testament to his skill and dedication to the sport of shooting. His performance was notable for its precision and consistency, which are crucial in competitive shooting.\\n\\n#### Minimal Gear\\nOne of the most striking aspects of Dikeรง's performance was his minimal use of gear. Unlike many of his competitors, Dikeรง did not rely on special lenses or large ear protectors. This unconventional approach added to his appeal and made his achievement even more impressive.\\n\\n#### Viral Sensation\\nDikeรง's seemingly casual attitude while shooting and his minimal gear made him an internet sensation. His unique style resonated with viewers, leading to widespread admiration and discussion on social media platforms. This unexpected fame highlighted the power of individuality and authenticity in capturing public interest.\\n\\n#### Social Media Popularity\\nThe sudden popularity of Yusuf Dikeรง on social media was evident through various creative expressions by fans. People edited Dikeรง into film scenes, compared him to characters from TV shows and video games, and even created drawings of him. This outpouring of creativity underscored the impact of his performance and personality on the global audience.\\n\\n#### Age and Experience\\nAt 51 years old, Yusuf Dikeรง brought a wealth of experience to the 2024 Paris Olympics. His Olympic journey began in 2008, showcasing his longevity and commitment to the sport. Dikeรง's continued success at this age is a testament to his enduring skill and passion for shooting.\\n\\n#### Inspiration for Celebration\\nDikeรง's performance and attitude inspired a new celebration trend among fans and athletes. His unique approach to the sport and the subsequent viral sensation he created have left a lasting impact on the Olympic community. This influence demonstrates the power of individual achievement in inspiring others.\\n\\n#### Conclusion\\nYusuf Dikeรง's journey at the 2024 Paris Olympics is a story of skill, individuality, and enduring passion. His silver medal win, minimal gear, viral sensation, social media popularity, age, and experience all contribute to a compelling narrative that has captivated the world. Dikeรง's impact extends beyond his sport, inspiring creativity and celebration among fans and athletes alike.\"}\n",+ "\tResult: {'nodes': [{'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, {'id': '2024 Paris Olympics', 'type': 'Event', 'properties': {'source': 'agent_created'}}, {'id': 'Silver Medal', 'type': 'Award', 'properties': {'source': 'agent_created'}}, {'id': 'Air Pistol Team Event', 'type': 'Competition', 'properties': {'source': 'agent_created'}}, {'id': 'Shooting', 'type': 'Sport', 'properties': {'source': 'agent_created'}}, {'id': 'Gear', 'type': 'Equipment', 'properties': {'source': 'agent_created'}}, {'id': 'Social Media Platforms', 'type': 'Platform', 'properties': {'source': 'agent_created'}}, {'id': 'Fans', 'type': 'Group', 'properties': {'source': 'agent_created'}}, {'id': 'Athletes', 'type': 'Group', 'properties': {'source': 'agent_created'}}, {'id': 'Olympic Community', 'type': 'Community', 'properties': {'source': 'agent_created'}}, {'id': 'Global Audience', 'type': 'Audience', 'properties': {'source': 'agent_created'}}], 'relationships': [{'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Silver Medal', 'type': 'Award', 'properties': {'source': 'agent_created'}}, 'type': 'Won', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Air Pistol Team Event', 'type': 'Competition', 'properties': {'source': 'agent_created'}}, 'type': 'ParticipatedIn', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Shooting', 'type': 'Sport', 'properties': {'source': 'agent_created'}}, 'type': 'ExcelsIn', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Gear', 'type': 'Equipment', 'properties': {'source': 'agent_created'}}, 'type': 'UsesMinimally', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Social Media Platforms', 'type': 'Platform', 'properties': {'source': 'agent_created'}}, 'type': 'ViralSensationOn', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Fans', 'type': 'Group', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'type': 'CreatedExpressionsAbout', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Shooting', 'type': 'Sport', 'properties': {'source': 'agent_created'}}, 'type': 'HasExperienceIn', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Fans', 'type': 'Group', 'properties': {'source': 'agent_created'}}, 'type': 'InspiredCelebrationTrendAmong', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Athletes', 'type': 'Group', 'properties': {'source': 'agent_created'}}, 'type': 'InspiredCelebrationTrendAmong', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Global Audience', 'type': 'Audience', 'properties': {'source': 'agent_created'}}, 'type': 'Captivated', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Silver Medal', 'type': 'Award', 'properties': {'source': 'agent_created'}}, 'type': 'Won', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Air Pistol Team Event', 'type': 'Competition', 'properties': {'source': 'agent_created'}}, 'type': 'ParticipatedIn', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Shooting', 'type': 'Sport', 'properties': {'source': 'agent_created'}}, 'type': 'ExcelsIn', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Gear', 'type': 'Equipment', 'properties': {'source': 'agent_created'}}, 'type': 'UsesMinimally', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Social Media Platforms', 'type': 'Platform', 'properties': {'source': 'agent_created'}}, 'type': 'ViralSensationOn', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Fans', 'type': 'Group', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'type': 'CreatedExpressionsAbout', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Shooting', 'type': 'Sport', 'properties': {'source': 'agent_created'}}, 'type': 'HasExperienceIn', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Fans', 'type': 'Group', 'properties': {'source': 'agent_created'}}, 'type': 'InspiredCelebrationTrendAmong', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Athletes', 'type': 'Group', 'properties': {'source': 'agent_created'}}, 'type': 'InspiredCelebrationTrendAmong', 'properties': {'source': 'agent_created'}}, {'subj': {'id': 'Yusuf Dikeรง', 'type': 'Person', 'properties': {'source': 'agent_created'}}, 'obj': {'id': 'Global Audience', 'type': 'Audience', 'properties': {'source': 'agent_created'}}, 'type': 'Captivated', 'properties': {'source': 'agent_created'}}], 'source': <unstructured.documents.elements.Text object at 0x7cc671159ed0>}\n",+ "\n",+ "Solution: I have used the knowledge graph tool to create a knowledge graph based on the report. Here is the structured representation of the knowledge graph:\n",+ "\n",+ "### Nodes\n",+ "1. **Yusuf Dikeรง** (Type: Person)\n",+ "2. **2024 Paris Olympics** (Type: Event)\n",+ "3. **Silver Medal** (Type: Award)\n",+ "4. **Air Pistol Team Event** (Type: Competition)\n",+ "5. **Shooting** (Type: Sport)\n",+ "6. **Gear** (Type: Equipment)\n",+ "7. **Social Media Platforms** (Type: Platform)\n",+ "8. **Fans** (Type: Group)\n",+ "9. **Athletes** (Type: Group)\n",+ "10. **Olympic Community** (Type: Community)\n",+ "11. **Global Audience** (Type: Audience)\n",+ "\n",+ "### Relationships\n",+ "1. **Yusuf Dikeรง** (Person) - **Won** - **Silver Medal** (Award)\n",+ "2. **Yusuf Dikeรง** (Person) - **ParticipatedIn** - **Air Pistol Team Event** (Competition)\n",+ "3. **Yusuf Dikeรง** (Person) - **ExcelsIn** - **Shooting** (Sport)\n",+ "4. **Yusuf Dikeรง** (Person) - **UsesMinimally** - **Gear** (Equipment)\n",+ "5. **Yusuf Dikeรง** (Person) - **ViralSensationOn** - **Social Media Platforms** (Platform)\n",+ "6. **Fans** (Group) - **CreatedExpressionsAbout** - **Yusuf Dikeรง** (Person)\n",+ "7. **Yusuf Dikeรง** (Person) - **HasExperienceIn** - **Shooting** (Sport)\n",+ "8. **Yusuf Dikeรง** (Person) - **InspiredCelebrationTrendAmong** - **Fans** (Group)\n",+ "9. **Yusuf Dikeรง** (Person) - **InspiredCelebrationTrendAmong** - **Athletes** (Group)\n",+ "10. **Yusuf Dikeรง** (Person) - **Captivated** - **Global Audience** (Audience)\n",+ "\n",+ "This knowledge graph captures the key entities and their relationships as described in the report, providing a structured overview of Yusuf Dikeรง's achievements and impact at the 2024 Paris Olympics.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Review the knowledge graph and ensure it accurately represents the information from the report.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: I have reviewed the knowledge graph to ensure it accurately represents the information from the report. Here is the revised and detailed knowledge graph:\n",+ "\n",+ "### Nodes\n",+ "1. **Yusuf Dikeรง** (Type: Person)\n",+ " - Properties:\n",+ " - Age: 51\n",+ " - Nationality: Turkish\n",+ " - Sport: Shooting\n",+ " - Experience: Since 2008\n",+ "\n",+ "2. **2024 Paris Olympics** (Type: Event)\n",+ " - Properties:\n",+ " - Location: Paris\n",+ " - Year: 2024\n",+ "\n",+ "3. **Silver Medal** (Type: Award)\n",+ " - Properties:\n",+ " - Type: Silver\n",+ " - Event: Air Pistol Team Event\n",+ "\n",+ "4. **Air Pistol Team Event** (Type: Competition)\n",+ " - Properties:\n",+ " - Sport: Shooting\n",+ " - Event: 2024 Paris Olympics\n",+ "\n",+ "5. **Shooting** (Type: Sport)\n",+ " - Properties:\n",+ " - Type: Shooting\n",+ " - Competitions: Air Pistol Team Event\n",+ "\n",+ "6. **Gear** (Type: Equipment)\n",+ " - Properties:\n",+ " - Type: Shooting Gear\n",+ " - Usage: Minimal\n",+ "\n",+ "7. **Social Media Platforms** (Type: Platform)\n",+ " - Properties:\n",+ " - Type: Social Media\n",+ " - Users: Global Audience\n",+ "\n",+ "8. **Fans** (Type: Group)\n",+ " - Properties:\n",+ " - Type: Fans\n",+ " - Platform: Social Media Platforms\n",+ "\n",+ "9. **Athletes** (Type: Group)\n",+ " - Properties:\n",+ " - Type: Athletes\n",+ " - Event: 2024 Paris Olympics\n",+ "\n",+ "10. **Olympic Community** (Type: Community)\n",+ " - Properties:\n",+ " - Type: Olympic Community\n",+ " - Members: Athletes, Fans\n",+ "\n",+ "11. **Global Audience** (Type: Audience)\n",+ " - Properties:\n",+ " - Type: Global Audience\n",+ " - Platform: Social Media Platforms\n",+ "\n",+ "### Relationships\n",+ "1. **Yusuf Dikeรง** (Person) - **Won** - **Silver Medal** (Award)\n",+ " - Properties:\n",+ " - Event: Air Pistol Team Event\n",+ " - Year: 2024\n",+ "\n",+ "2. **Yusuf Dikeรง** (Person) - **ParticipatedIn** - **Air Pistol Team Event** (Competition)\n",+ " - Properties:\n",+ " - Event: 2024 Paris Olympics\n",+ " - Result: Silver Medal\n",+ "\n",+ "3. **Yusuf Dikeรง** (Person) - **ExcelsIn** - **Shooting** (Sport)\n",+ " - Properties:\n",+ " - Experience: Since 2008\n",+ " - Achievements: Silver Medal in Air Pistol Team Event\n",+ "\n",+ "4. **Yusuf Dikeรง** (Person) - **UsesMinimally** - **Gear** (Equipment)\n",+ " - Properties:\n",+ " - Type: Shooting Gear\n",+ " - Usage: Minimal\n",+ "\n",+ "5. **Yusuf Dikeรง** (Person) - **ViralSensationOn** - **Social Media Platforms** (Platform)\n",+ " - Properties:\n",+ " - Reason: Minimal Gear, Casual Attitude\n",+ " - Impact: Global Audience\n",+ "\n",+ "6. **Fans** (Group) - **CreatedExpressionsAbout** - **Yusuf Dikeรง** (Person)\n",+ " - Properties:\n",+ " - Expressions: Edits into film scenes, comparisons to TV/video game characters, drawings\n",+ " - Platform: Social Media Platforms\n",+ "\n",+ "7. **Yusuf Dikeรง** (Person) - **HasExperienceIn** - **Shooting** (Sport)\n",+ " - Properties:\n",+ " - Experience: Since 2008\n",+ " - Achievements: Silver Medal in Air Pistol Team Event\n",+ "\n",+ "8. **Yusuf Dikeรง** (Person) - **InspiredCelebrationTrendAmong** - **Fans** (Group)\n",+ " - Properties:\n",+ " - Trend: New celebration trend\n",+ " - Impact: Fans and Athletes\n",+ "\n",+ "9. **Yusuf Dikeรง** (Person) - **InspiredCelebrationTrendAmong** - **Athletes** (Group)\n",+ " - Properties:\n",+ " - Trend: New celebration trend\n",+ " - Impact: Fans and Athletes\n",+ "\n",+ "10. **Yusuf Dikeรง** (Person) - **Captivated** - **Global Audience** (Audience)\n",+ " - Properties:\n",+ " - Reason: Minimal Gear, Casual Attitude, Viral Sensation\n",+ " - Impact: Global Audience\n",+ "\n",+ "This revised knowledge graph accurately represents the information from the report, capturing the key entities and their relationships in a structured manner.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "Instruction: Provide feedback on whether the task is completed based on the initial task description.\n",+ "Input: None\n",+ "\n",+ "\n",+ "\u001b[32mAI Assistant:\n",+ "\n",+ "Solution: Based on the initial task description, the task is completed. We have conducted a comprehensive study of the Turkish shooter Yusuf Dikeรง at the 2024 Paris Olympics, written a detailed report, and created a knowledge graph to represent the information from the report. The process involved using the search tool to find related URLs, the retrieval tool to get the content from the URLs, and the knowledge graph tool to build the knowledge graph.\n",+ "\n",+ "Next request.\n",+ "\n",+ "\n",+ "\u001b[34mAI User:\n",+ "\n",+ "<CAMEL_TASK_DONE>\n",+ "\n",+ "\n"+ ]+ }+ ],+ "source": [+ "n = 0\n",+ "input_msg = role_play_session.init_chat()\n",+ "while n < 20: # Limit the chat to 20 turns\n",+ " n += 1\n",+ " assistant_response, user_response = role_play_session.step(input_msg)\n",+ "\n",+ " if assistant_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI Assistant terminated. Reason: \"\n",+ " f\"{assistant_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ " if user_response.terminated:\n",+ " print(\n",+ " Fore.GREEN\n",+ " + (\n",+ " \"AI User terminated. \"\n",+ " f\"Reason: {user_response.info['termination_reasons']}.\"\n",+ " )\n",+ " )\n",+ " break\n",+ " # Print output from the user\n",+ " print_text_animated(\n",+ " Fore.BLUE + f\"AI User:\\n\\n{user_response.msg.content}\\n\",\n",+ " 0.01\n",+ " )\n",+ "\n",+ " if \"CAMEL_TASK_DONE\" in user_response.msg.content:\n",+ " break\n",+ "\n",+ " # Print output from the assistant, including any function\n",+ " # execution information\n",+ " print_text_animated(Fore.GREEN + \"AI Assistant:\", 0.01)\n",+ " tool_calls: List[FunctionCallingRecord] = [\n",+ " FunctionCallingRecord(**call.as_dict())\n",+ " for call in assistant_response.info['tool_calls']\n",+ " ]\n",+ " for func_record in tool_calls:\n",+ " print_text_animated(f\"{func_record}\", 0.01)\n",+ " print_text_animated(f\"{assistant_response.msg.content}\\n\", 0.01)\n",+ "\n",+ " input_msg = assistant_response.msg"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "t7zTkjDBIf_i",+ "outputId": "a5ac6f0e-3337-4333-db65-007acbd5278c"+ },+ "outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "๐ AgentOps: This run's cost $0.00\n",+ "๐ AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=a7deea00-864e-461d-956b-1e78ebeea350\u001b[0m\u001b[0m\n"+ ]+ }+ ],+ "source": [+ "# End the AgentOps session\n",+ "agentops.end_session(\"Success\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "4au_S6ITIfnx"+ },+ "source": [+ "๐ Go to the AgentOps link shown above, you will be able to see the detailed record for this running like below.\n",+ "\n",+ "**NOTE**: The AgentOps link is private and tied to the AgentOps account. To access the link, youโll need to run the session using your own AgentOps API Key, which will then allow you to open the link with the sessionโs running information.\n",+ "\n",+ "Currently AgentOps can't get the running cost for Mistral AI directly."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "OTGVmZ2bouJv"+ },+ "source": [+ ""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "yDriFSAr4QRw"+ },+ "source": [+ "๐ You can also go the the [Neo4j Aura](https://login.neo4j.com/u/login/identifier?state=hKFo2SBRTk8tVW5CU201cGtOMDdGYlp1bFJYRlVUZGlUY05SdqFur3VuaXZlcnNhbC1sb2dpbqN0aWTZIEFSYTFtMVJsekVnVy1vaHZjQzRNWDB4SXlYak9SOUw5o2NpZNkgV1NMczYwNDdrT2pwVVNXODNnRFo0SnlZaElrNXpZVG8) to check the knowledge graph generated by CAMEL's Agent like below."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Tq_wssFTYaKH"+ },+ "source": [+ ""+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "flYNal6-R4yR"+ },+ "source": [+ "## ๐ Highlights"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "SmkXhy4JR726"+ },+ "source": [+ "This notebook has guided you through setting up and running a CAMEL RAG workflow with Firecrawl for a complex, multi-agent role-playing task. You can adapt and expand this example for various other scenarios requiring advanced web information retrieval and AI collaboration.\n",+ "\n",+ "Key tools utilized in this notebook include:\n",+ "\n",+ "* **CAMEL**: A powerful multi-agent framework that enables Retrieval-Augmented Generation and multi-agent role-playing scenarios, allowing for sophisticated AI-driven tasks.\n",+ "* **Mistral**: Utilized for its state-of-the-art language models, which enable tool-calling capabilities to execute external functions, while its powerful embeddings are employed for semantic search and content retrieval.\n",+ "* **Firecrawl**: A robust web scraping tool that simplifies extracting and cleaning content from various web pages.\n",+ "* **AgentOps**: Track and analysis the running of CAMEL Agents.\n",+ "* **Qdrant**: An efficient vector storage system used with CAMELโs AutoRetriever to store and retrieve relevant information based on vector similarities.\n",+ "* **Neo4j**: A leading graph database management system used for constructing and storing knowledge graphs, enabling complex relationships between entities to be mapped and queried efficiently.\n",+ "* **DuckDuckGo Search**: Utilized within the SearchToolkit to gather relevant URLs and information from the web, serving as the primary search engine for retrieving initial content.\n",+ "* **Unstructured IO:** Used for content chunking, facilitating the management of unstructured data for more efficient processing.\n",+ "\n",+ "This comprehensive setup allows you to adapt and expand the example for various scenarios requiring advanced web information retrieval, AI collaboration, and multi-source data aggregation.\n",+ "\n",+ "**CAMEL also support advanced GraphRAG, for more information please check [here](https://colab.research.google.com/drive/1meBf9w8KzZvQdQU2I1bCyOg9ehoGDK1u?authuser=1)**"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "s6Det-fcMb9A"+ },+ "source": [+ "โญ **Star the Repo**\n",+ "\n",+ "If you find CAMEL useful or interesting, please consider giving it a star on [GitHub](https://github.com/camel-ai/camel)! Your stars help others find this project and motivate us to continue improving it."+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "Python 3",+ "name": "python3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}diff --git a/docs/cookbooks/task_generation.ipynb b/docs/cookbooks/task_generation.ipynbnew file mode 100644index 000000000..3fdc46dff--- /dev/null+++ b/docs/cookbooks/task_generation.ipynb@@ -0,0 +1,327 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "Fvdt_pMpf7EK"+ },+ "source": [+ "# ๐ซ CAMEL Task Generation Cookbook"+ ]+ },+ {+ "cell_type": "markdown",+ "source": [+ "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1n_SjiE7NRmpUUBcRge-gqKAv5mzWPcU0?usp=sharing)"+ ],+ "metadata": {+ "id": "pf-CrViNgJqn"+ }+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "2XXT4d1tf7EM"+ },+ "source": [+ "In this tutorial, we will focus on demonstrating how to use the task module in the CAMEL framework. We will guide you through creating, evolving, and decomposing tasks to illustrate how the task module can be utilized for efficient task management in agent-based systems."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "ph2dWXb-f7EM"+ },+ "source": [+ "Sections included:\n",+ "\n",+ "- Setting up a ChatAgent with the CAMEL framework\n",+ "- Creating a Task and evolving it with the agent using TaskManager\n",+ "- Task decomposition using the CAMEL task module\n",+ "\n",+ "Let's go step by step!"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "4uoXafBRf7EN"+ },+ "source": [+ "## Step 1: Import necessary CAMEL modules\n",+ "\n",+ "First, we need to import the required CAMEL modules for creating the ChatAgent and handling tasks."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "My_O9chyf7EN"+ },+ "outputs": [],+ "source": [+ "!pip install camel-ai==0.1.6.8"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 2,+ "metadata": {+ "id": "3povzm9qf7EO"+ },+ "outputs": [],+ "source": [+ "from camel.agents import ChatAgent\n",+ "from camel.configs import ChatGPTConfig\n",+ "from camel.messages import BaseMessage\n",+ "from camel.models import ModelFactory\n",+ "from camel.tasks import (\n",+ " Task,\n",+ " TaskManager,\n",+ ")\n",+ "from camel.types import (\n",+ " ModelPlatformType,\n",+ " ModelType,\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "H9ANkBsuf7EO"+ },+ "source": [+ "Set your OpenAI key"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 3,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "t7u1PNhnf7EO",+ "outputId": "2a0d53d5-1a56-4b63-f305-7894939f71c6"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "import os\n",+ "from getpass import getpass\n",+ "\n",+ "# Prompt for the API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "brQ0v3kaf7EP"+ },+ "source": [+ "## Step 2: Set up the Large Language Model (LLM)\n",+ "\n",+ "Next, we set up the model configuration. We are using a GPT-4O Mini in this case for our assistant agent. The configuration is designed to ensure the agentโs behavior remains deterministic by setting temperature=0.0, meaning no randomness will be introduced in the responses."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 4,+ "metadata": {+ "id": "DLXsqm7mf7EP"+ },+ "outputs": [],+ "source": [+ "# Model configuration for the assistant\n",+ "assistant_model_config = ChatGPTConfig(\n",+ " temperature=0.0, # Set to 0 for deterministic output\n",+ ")\n",+ "\n",+ "# Create the model using the configuration\n",+ "model = ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_4O_MINI,\n",+ " model_config_dict=assistant_model_config.as_dict(),\n",+ ")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "IAstp4cyf7EP"+ },+ "source": [+ "## Step 3: Initialize the ChatAgent\n",+ "\n",+ "We now create a ChatAgent using the previously defined model. This agent will interact with tasks in the CAMEL framework, following the role of a personal math tutor and programmer."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 5,+ "metadata": {+ "id": "rSo-keNnf7EP"+ },+ "outputs": [],+ "source": [+ "# Set up the assistant's system message\n",+ "assistant_sys_msg = BaseMessage.make_user_message(\n",+ " role_name=\"Teacher\",\n",+ " content=(\"You are a personal math tutor and programmer.\"),\n",+ ")\n",+ "\n",+ "# Initialize the ChatAgent\n",+ "agent = ChatAgent(assistant_sys_msg, model)\n",+ "agent.reset() # Reset the agent's internal state"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "b-RGszDYf7EP"+ },+ "source": [+ "## Step 4: Evolve and decompose tasks\n",+ "\n",+ "We now create a Task that represents a math problem for the assistant to solve. In this case, we are asking the assistant to calculate how much Weng earned for babysitting based on her hourly rate and the time she worked."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 6,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "YZ8TaZzjf7EQ",+ "outputId": "9b176f78-a505-4d35-94a3-ee34313a884d"+ },+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "Task 0: Weng earns $12 an hour for babysitting. Yesterday, she just did 51 minutes of babysitting. How much did she earn?\n",+ "\n"+ ]+ }+ ],+ "source": [+ "# Create a Task for the agent to solve\n",+ "task = Task(\n",+ " content=\"Weng earns $12 an hour for babysitting. Yesterday, she just did 51 minutes of babysitting. How much did she earn?\",\n",+ " id=\"0\", # Task identifier\n",+ ")\n",+ "\n",+ "# Print the task to see the original form\n",+ "print(task.to_string())"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "R1xHH7UAf7EQ"+ },+ "source": [+ "### Evolve the Task\n",+ "\n",+ "We can evolve the task using the TaskManager, which allows the agent to potentially update or reframe the task based on its internal logic and context."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 7,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "ThFlgKehf7EQ",+ "outputId": "de37eb43-a0f0-4a58-c65f-1318a0f01916"+ },+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "Task 0.0: Weng earns $12 an hour for babysitting. Yesterday, she babysat for 1 hour and 45 minutes. Additionally, she received a bonus of $5 for excellent service. How much did she earn in total for her babysitting job yesterday?\n",+ "\n"+ ]+ }+ ],+ "source": [+ "task_manager = TaskManager(task)\n",+ "\n",+ "evolved_task = task_manager.evolve(task, agent=agent)\n",+ "if evolved_task is not None:\n",+ " print(evolved_task.to_string())\n",+ "else:\n",+ " print(\"Evolved task is None.\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "b_6IxCWPf7EQ"+ },+ "source": [+ "### Decompose the Task\n",+ "\n",+ "Sometimes, tasks are complex and need to be broken down into smaller subtasks. We use decompose() to allow the agent to split the original task into simpler parts."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 8,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "bWNpUckzf7EQ",+ "outputId": "15e70418-792b-46c5-f46e-bbadf70daefd"+ },+ "outputs": [+ {+ "output_type": "stream",+ "name": "stdout",+ "text": [+ "Task 0.0: Convert the babysitting time from minutes to hours.\n",+ "\n",+ "Task 0.1: Calculate the earnings based on the hourly rate of $12 and the converted time in hours.\n",+ "\n",+ "Task 0.2: Present the final earnings amount clearly.\n",+ "\n"+ ]+ }+ ],+ "source": [+ "new_tasks = task.decompose(agent=agent)\n",+ "for t in new_tasks:\n",+ " print(t.to_string())"+ ]+ }+ ],+ "metadata": {+ "language_info": {+ "name": "python"+ },+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "name": "python3",+ "display_name": "Python 3"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}\ No newline at end of filediff --git a/docs/cookbooks/video_analysis.ipynb b/docs/cookbooks/video_analysis.ipynbnew file mode 100644index 000000000..f379f9628--- /dev/null+++ b/docs/cookbooks/video_analysis.ipynb@@ -0,0 +1,216 @@+{+ "cells": [+ {+ "attachments": {},+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "# ๐ซ CAMEL Video Analysis"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "!pip install camel-ai[all]==0.1.6.4"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "_-8_5_srcpC_",+ "outputId": "bf152265-41b5-40f6-eff6-7b06b16aa534"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "Enter your API key: ยทยทยทยทยทยทยทยทยทยท\n"+ ]+ }+ ],+ "source": [+ "import os\n",+ "from getpass import getpass\n",+ "\n",+ "# Prompt for the API key securely\n",+ "openai_api_key = getpass('Enter your API key: ')\n",+ "os.environ[\"OPENAI_API_KEY\"] = openai_api_key"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "id": "J97N3GtSexwu"+ },+ "outputs": [],+ "source": [+ "from camel.agents import ChatAgent\n",+ "from camel.configs.openai_config import ChatGPTConfig\n",+ "from camel.messages import BaseMessage\n",+ "from camel.prompts.prompt_templates import PromptTemplateGenerator\n",+ "from camel.types import ModelType, ModelPlatformType\n",+ "from camel.types.enums import RoleType, TaskType\n",+ "from camel.models import ModelFactory\n",+ "\n",+ "# Define system message\n",+ "sys_msg_prompt = PromptTemplateGenerator().get_prompt_from_key(\n",+ " TaskType.VIDEO_DESCRIPTION, RoleType.ASSISTANT\n",+ ")\n",+ "sys_msg = BaseMessage.make_assistant_message(\n",+ " role_name=\"Assistant\",\n",+ " content=sys_msg_prompt,\n",+ ")\n",+ "\n",+ "# Set model\n",+ "model=ModelFactory.create(\n",+ " model_platform=ModelPlatformType.OPENAI,\n",+ " model_type=ModelType.GPT_4O,\n",+ " model_config_dict=ChatGPTConfig().as_dict(),\n",+ ")\n",+ "\n",+ "# Set agent\n",+ "camel_agent = ChatAgent(\n",+ " sys_msg,\n",+ " model=model\n",+ ")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "cQIJBZh_YXRY",+ "outputId": "0766500d-171b-4b15-e98c-89821836d0c6"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\"Step into the fascinating world of scientific discovery with our latest video! Watch as a dedicated researcher meticulously works in a high-tech laboratory, surrounded by intricate equipment and cutting-edge technology. This behind-the-scenes footage offers a glimpse into the meticulous process of experimentation and innovation. Join us on this journey of exploration and witness the passion and precision that drive scientific breakthroughs. Don't miss out on this captivating look at the heart of scientific research!\"\n"+ ]+ }+ ],+ "source": [+ "# Provide your video path\n",+ "video_cctv = \"/content/CCTV.mov\"\n",+ "with open(video_cctv, \"rb\") as video_cctv:\n",+ " video_bytes_cctv = video_cctv.read()\n",+ "\n",+ "# Set user message\n",+ "user_msg_cctv = BaseMessage.make_user_message(\n",+ " role_name=\"User\",\n",+ " content=\"These are frames from a video that I want to upload. Generate a\"\n",+ " \"compelling description that I can upload along with the video.\",\n",+ " video_bytes=video_bytes_cctv,\n",+ ")\n",+ "\n",+ "# Get response information\n",+ "response_cctv = camel_agent.step(user_msg_cctv)\n",+ "print(response_cctv.msgs[0].content)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "q7NIRGNT3bWx",+ "outputId": "84941af1-45b9-42bf-cc71-8da1fc9a620d"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\"Embark on a breathtaking journey through lush, green landscapes and rugged mountain trails. This video captures the serene beauty of nature, with winding paths leading you through picturesque scenery under a vibrant blue sky. Perfect for nature lovers and adventure seekers alike, this visual escape will transport you to a tranquil world far from the hustle and bustle of everyday life. Join us as we explore the untouched beauty of this stunning trail.\"\n"+ ]+ }+ ],+ "source": [+ "# Provide your video path\n",+ "video_help = \"/content/help.mov\"\n",+ "with open(video_help, \"rb\") as video_help:\n",+ " video_bytes_help = video_help.read()\n",+ "\n",+ "# Set user message\n",+ "user_msg_help = BaseMessage.make_user_message(\n",+ " role_name=\"User\",\n",+ " content=\"These are frames from a video that I want to upload. Generate a\"\n",+ " \"compelling description that I can upload along with the video.\",\n",+ " video_bytes=video_bytes_help,\n",+ ")\n",+ "\n",+ "# Get response information\n",+ "response_help = camel_agent.step(user_msg_help)\n",+ "print(response_help.msgs[0].content)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "RdwfgT_S3uZ5",+ "outputId": "3c69323b-ad66-41c4-d700-232400535841"+ },+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\"Join us for a candid glimpse into a moment of relaxation and reflection in the kitchen. Watch as our protagonist unwinds after a long day, savoring a drink and enjoying the simple pleasures of life. This video captures the essence of taking a break and finding comfort in familiar surroundings. Don't miss this relatable and heartwarming scene!\"\n"+ ]+ }+ ],+ "source": [+ "# Provide your video path\n",+ "video_content_mode = \"/content/content mod.mov\"\n",+ "with open(video_content_mode, \"rb\") as video_content_mode:\n",+ " video_bytes_content_mode = video_content_mode.read()\n",+ "\n",+ "# Set user message\n",+ "user_msg_content_mode = BaseMessage.make_user_message(\n",+ " role_name=\"User\",\n",+ " content=\"These are frames from a video that I want to upload. Generate a\"\n",+ " \"compelling description that I can upload along with the video.\",\n",+ " video_bytes=video_bytes_content_mode,\n",+ ")\n",+ "\n",+ "# Get response information\n",+ "response_content_mode = camel_agent.step(user_msg_content_mode)\n",+ "print(response_content_mode.msgs[0].content)"+ ]+ }+ ],+ "metadata": {+ "colab": {+ "provenance": []+ },+ "kernelspec": {+ "display_name": "Python 3",+ "name": "python3"+ },+ "language_info": {+ "name": "python"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 0+}diff --git a/docs/index.rst b/docs/index.rstindex 92a1a9bbc..1b3e65356 100644--- a/docs/index.rst+++ b/docs/index.rst@@ -47,10 +47,23 @@ Main Documentation.. toctree:::maxdepth: 1- :caption: Tutorial and Cookbooks- :name: tutorials_and_cookbooks-- tutorials_and_cookbooks/agents_with_rag.md+ :caption: Cookbooks+ :name: cookbooks++ cookbooks/create_your_first_agent.ipynb+ cookbooks/create_your_first_agents_society.ipynb+ cookbooks/agents_society.ipynb+ cookbooks/agents_message.ipynb+ cookbooks/agents_with_tools.ipynb+ cookbooks/agents_with_tools_from_Composio.ipynb+ cookbooks/agents_with_memory.ipynb+ cookbooks/agents_with_rag.ipynb+ cookbooks/agents_prompting.ipynb+ cookbooks/task_generation.ipynb+ cookbooks/knowledge_graph.ipynb+ cookbooks/roleplaying_scraper.ipynb+ cookbooks/video_analysis.ipynb+ cookbooks/agents_tracking.ipynb.. toctree:::maxdepth: 1diff --git a/docs/tutorials_and_cookbooks/agents_with_rag.md b/docs/tutorials_and_cookbooks/agents_with_rag.mddeleted file mode 100644index caf415b25..000000000--- a/docs/tutorials_and_cookbooks/agents_with_rag.md+++ /dev/null@@ -1,335 +0,0 @@-# ๐ซ Agents with RAG--## Philosophical Bits-[](https://colab.research.google.com/drive/1sTJ0x_MYRGA76KCg_3I00wj4RL3D2Twp?usp=sharing)---In this notebook, we show the useage of CAMEL Retrieve Module in both customized way and auto way. We will also show how to combine `AutoRetriever` with `ChatAgent`, and further combine `AutoRetriever` with `RolePlaying` by using `Function Calling`.--4 main parts included:-- Customized RAG-- Auto RAG-- Single Agent with Auto RAG-- Role-playing with Auto RAG--## Load Data-Let's first load the CAMEL paper from https://arxiv.org/pdf/2303.17760.pdf. This will be our local example data.-```python-import os-import requests--os.makedirs('local_data', exist_ok=True)--url = "https://arxiv.org/pdf/2303.17760.pdf"-response = requests.get(url)-with open('local_data/camel paper.pdf', 'wb') as file:- file.write(response.content)-```--## 1. Customized RAG-In this section we will set our customized RAG pipeline, we will take `VectorRetriever` as an example.-Set embedding model, we will use `OpenAIEmbedding` as the embedding model, so we need to set the `OPENAI_API_KEY` in below.-```python-import os--os.environ["OPENAI_API_KEY"] = "Your Key"-```--Import and set the embedding instance:-```python-from camel.embeddings import OpenAIEmbedding--embedding_instance = OpenAIEmbedding()-```--Import and set the vector storage instance:-```python-from camel.storages import MilvusStorage--storage_instance = MilvusStorage(- vector_dim=embedding_instance.get_output_dim(),- url_and_api_key=("Your Milvus URI","Your Milvus Token"),- collection_name="camel_paper",-)-```--Import and set the retriever instance:-```python-from camel.retrievers import VectorRetriever--vector_retriever = VectorRetriever(embedding_model=embedding_instance)-```--We use integrated `Unstructured Module` to splite the content into small chunks, the content will be splited automacitlly with its `chunk_by_title` function, the max character for each chunk is 500 characters, which is a suitable length for `OpenAIEmbedding`. All the text in the chunks will be embed and stored to the vector storage instance, it will take some time, please wait..-```python-vector_retriever.process(- content="local_data/camel paper.pdf",- storage=storage_instance,-)-```--Now we can retrieve information from the vector storage by giving a query. By default it will give you back the text content from top 1 chunk with highest Cosine similarity score, and the similarity score should be higher than 0.75 to ensure the retrieved content is relevant to the query. You can also change the `top_k` value and `similarity_threshold` value with your needs.--The returned string list includes:-- similarity score-- content path-- metadata-- text-```python-retrieved_info = vector_retriever.query(- query="What is CAMEL?", storage=storage_instance, top_k=1-)-print(retrieved_info)-```-```markdown->>> [{'similarity score': '0.8321741223335266', 'content path': 'local_data/camel paper.pdf', 'metadata': {'filetype': 'application/pdf', 'languages': ['eng'], 'last_modified': '2024-03-24T17:58:24', 'page_number': 45}, 'text': 'CAMEL Data and Code License The intended purpose and licensing of CAMEL is solely for research use. The source code is licensed under Apache 2.0. The datasets are licensed under CC BY NC 4.0, which permits only non-commercial usage. It is advised that any models trained using the dataset should not be utilized for anything other than research purposes.\n\n45'}]-```--Let's try an irrelevant query:-```python-retrieved_info_irrevelant = vector_retriever.query(- query="Compared with dumpling and rice, which should I take for dinner?",- storage=storage_instance,- top_k=1,-)--print(retrieved_info_irrevelant)--```-```markdown->>> [{'text': 'No suitable information retrieved from local_data/camel paper.pdf with similarity_threshold = 0.75.'}]-```--## 2. Auto RAG-In this section we will run the `AutoRetriever` with default settings. It uses `OpenAIEmbedding` as default embedding model and `Milvus` as default vector storage.--What you need to do is:-- Set content input paths, which can be local paths or remote urls-- Set remote url and api key for Milvus-- Give a query--The Auto RAG pipeline would create collections for given content input paths, the collection name will be set automaticlly based on the content input path name, if the collection exists, it will do the retrieve directly.-```python-from camel.retrievers import AutoRetriever-from camel.types import StorageType--auto_retriever = AutoRetriever(- url_and_api_key=("Your Milvus URI","Your Milvus Token"),- storage_type=StorageType.MILVUS,- embedding_model=embedding_instance)--retrieved_info = auto_retriever.run_vector_retriever(- query="What is CAMEL-AI",- contents=[- "local_data/camel paper.pdf", # example local path- "https://www.camel-ai.org/", # example remote url- ],- top_k=1,- return_detailed_info=True,-)--print(retrieved_info)-```-```markdown->>> Original Query:-{What is CAMEL-AI}-Retrieved Context:-{'similarity score': '0.8369356393814087', 'content path': 'local_data/camel paper.pdf', 'metadata': {'filetype': 'application/pdf', 'languages': ['eng'], 'last_modified': '2024-03-24T17:58:24', 'page_number': 7}, 'text': 'Section 3.2, to simulate assistant-user cooperation. For our analysis, we set our attention on AI Society setting. We also gathered conversational data, named CAMEL AI Society and CAMEL Code datasets and problem-solution pairs data named CAMEL Math and CAMEL Science and analyzed and evaluated their quality. Moreover, we will discuss potential extensions of our framework and highlight both the risks and opportunities that future AI society might present.'}-{'similarity score': '0.8378663659095764', 'content path': 'https://www.camel-ai.org/', 'metadata': {'emphasized_text_contents': ['Mission', 'CAMEL-AI.org', 'is an open-source community dedicated to the study of autonomous and communicative agents. We believe that studying these agents on a large scale offers valuable insights into their behaviors, capabilities, and potential risks. To facilitate research in this field, we provide, implement, and support various types of agents, tasks, prompts, models, datasets, and simulated environments.', 'Join us via', 'Slack', 'Discord', 'or'], 'emphasized_text_tags': ['span', 'span', 'span', 'span', 'span', 'span', 'span'], 'filetype': 'text/html', 'languages': ['eng'], 'link_texts': [None, None, None], 'link_urls': ['#h.3f4tphhd9pn8', 'https://join.slack.com/t/camel-ai/shared_invite/zt-1vy8u9lbo-ZQmhIAyWSEfSwLCl2r2eKA', 'https://discord.gg/CNcNpquyDc'], 'page_number': 1, 'url': 'https://www.camel-ai.org/'}, 'text': 'Mission\n\nCAMEL-AI.org is an open-source community dedicated to the study of autonomous and communicative agents. We believe that studying these agents on a large scale offers valuable insights into their behaviors, capabilities, and potential risks. To facilitate research in this field, we provide, implement, and support various types of agents, tasks, prompts, models, datasets, and simulated environments.\n\nJoin us via\n\nSlack\n\nDiscord\n\nor'}-```--## 3. Single Agent with Auto RAG-In this section we will show how to combine the `AutoRetriever` with one `ChatAgent`.--Let's set an agent function, in this function we can get the response by providing a query to this agent.-```python-from camel.agents import ChatAgent-from camel.messages import BaseMessage-from camel.types import RoleType-from camel.retrievers import AutoRetriever-from camel.types import StorageType--def single_agent(query: str) ->str :- # Set agent role- assistant_sys_msg = BaseMessage(- role_name="Assistant",- role_type=RoleType.ASSISTANT,- meta_dict=None,- content="You are a helpful assistant to answer question, I will give you the Original Query and Retrieved Context, answer the Original Query based on the Retrieved Context, if you can't answer the question just say I don't know.",- )-- # Add auto retriever- auto_retriever = AutoRetriever(- url_and_api_key=("Your Milvus URI","Your Milvus Token"),- storage_type=StorageType.MILVUS,- embedding_model=embedding_instance)-- retrieved_info = auto_retriever.run_vector_retriever(- query=query,- contents=[- "local_data/camel paper.pdf", # example local path- "https://www.camel-ai.org/", # example remote url- ],- # vector_storage_local_path="storage_default_run",- top_k=1,- return_detailed_info=True,- )-- # Pass the retrieved infomation to agent- user_msg = BaseMessage.make_user_message(role_name="User", content=retrieved_info)- agent = ChatAgent(assistant_sys_msg)-- # Get response- assistant_response = agent.step(user_msg)- return assistant_response.msg.content--print(single_agent("What is CAMEL-AI"))-```-```markdown->>> CAMEL-AI is an open-source community dedicated to the study of autonomous and communicative agents. It provides, implements, and supports various types of agents, tasks, prompts, models, datasets, and simulated environments to facilitate research in this field.-```--## 4. Role-playing with Auto RAG-In this section we will show how to combine the `AutoRetriever` with `RolePlaying` by applying `Function Calling`.--First, we need to set a retriever function with well-written docstring for LLM to understand what this function is used for, the main code is the same with the Auto RAG section.-```python-from typing import List-from camel.toolkits import OpenAIFunction-from camel.retrievers import AutoRetriever-from camel.types import StorageType--def local_retriever(query: str) -> str:- r"""Performs an auto local retriever for information. Given a query,- this function will retrieve the information from the local vector storage,- and return the retrieved information back. It is useful for information- retrieve.-- Args:- query (string): Question you want to be answered.-- Returns:- str: Aggregated information retrieved in response to the query.-- Example:- local_retriever(query = "what is camel?")- """- auto_retriever = AutoRetriever(- url_and_api_key=("Your Milvus URI","Your Milvus Token"),- storage_type=StorageType.MILVUS,- embedding_model=embedding_instance)-- retrieved_info = auto_retriever.run_vector_retriever(- query=query,- contents=[- "local_data/camel paper.pdf", # example local path- ],- top_k=1- )- return retrieved_info--# add the function to OpenAIFunction list-RETRIEVER_FUNCS: List[OpenAIFunction] = [- OpenAIFunction(func)- for func in [- local_retriever,- ]-]-```-Run the role-playing with defined retriever function:-```python-from camel.utils import role_playing_with_function-from camel.toolkits import MATH_FUNCS # import another function from camel--role_playing_with_function(- task_prompt=(- "What is the main termination reasons for AI Society dataset, how many number of messages did camel decided to limit, what's the value plus 100?"- ),- tools=[*RETRIEVER_FUNCS, *MATH_FUNCS],-)-```-```markdown->>>-AI Assistant sys message:-BaseMessage(role_name='Searcher', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={'task': "What is the main termination reasons for AI Society dataset, how many number of messages did camel decided to limit, what's the value plus 100?", 'assistant_role': 'Searcher', 'user_role': 'Professor'}, content="===== RULES OF ASSISTANT =====\nNever forget you are a Searcher and I am a Professor. Never flip roles! Never instruct me!\nWe share a common interest in collaborating to successfully complete a task.\nYou must help me to complete the task.\nHere is the task: What is the main termination reasons for AI Society dataset, how many number of messages did camel decided to limit, what's the value plus 100?. Never forget our task!\nI must instruct you based on your expertise and my needs to complete the task.\n\nI must give you one instruction at a time.\nYou must write a specific solution that appropriately solves the requested instruction and explain your solutions.\nYou must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\nUnless I say the task is completed, you should always start with:\n\nSolution: <YOUR_SOLUTION>\n\n<YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.\nAlways end <YOUR_SOLUTION> with: Next request.")--AI User sys message:-BaseMessage(role_name='Professor', role_type=<RoleType.USER: 'user'>, meta_dict={'task': "What is the main termination reasons for AI Society dataset, how many number of messages did camel decided to limit, what's the value plus 100?", 'assistant_role': 'Searcher', 'user_role': 'Professor'}, content='===== RULES OF USER =====\nNever forget you are a Professor and I am a Searcher. Never flip roles! You will always instruct me.\nWe share a common interest in collaborating to successfully complete a task.\nI must help you to complete the task.\nHere is the task: What is the main termination reasons for AI Society dataset, how many number of messages did camel decided to limit, what\'s the value plus 100?. Never forget our task!\nYou must instruct me based on my expertise and your needs to solve the task ONLY in the following two ways:\n\n1. Instruct with a necessary input:\nInstruction: <YOUR_INSTRUCTION>\nInput: <YOUR_INPUT>\n\n2. Instruct without any input:\nInstruction: <YOUR_INSTRUCTION>\nInput: None\n\nThe "Instruction" describes a task or question. The paired "Input" provides further context or information for the requested "Instruction".\n\nYou must give me one instruction at a time.\nI must write a response that appropriately solves the requested instruction.\nI must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.\nYou should instruct me not ask me questions.\nNow you must start to instruct me using the two ways described above.\nDo not add anything else other than your instruction and the optional corresponding input!\nKeep giving me instructions and necessary inputs until you think the task is completed.\nWhen the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.\nNever say <CAMEL_TASK_DONE> unless my responses have solved your task.')--Original task prompt:-What is the main termination reasons for AI Society dataset, how many number of messages did camel decided to limit, what's the value plus 100?--Specified task prompt:-None--Final task prompt:-What is the main termination reasons for AI Society dataset, how many number of messages did camel decided to limit, what's the value plus 100?--AI User:--Instruction: Provide the main termination reasons from the AI Society dataset.-Input: None---AI Assistant:--Function Execution: local_retriever- Args: {'query': 'main termination reasons for AI Society dataset'}- Result: Original Query:-{main termination reasons for AI Society dataset}-Retrieved Context:-Next we examine the conversation termination reasons for both AI Society and Code datasets. As can be seen in Figure 8, the main termination reasons for AI Society dataset is Assistant Instruct whereas for Code it is Token Limit. The latter is expected as the since responses that contain code tend to be long. It is also interesting to note that in both datasets, the termination due to Maximum Number of Messages is low indicating that the limit of 40 maximum messages is reasonable. Our decision--Solution: The main termination reason for the AI Society dataset is "Assistant Instruct." This indicates that the conversations in this dataset typically end when the assistant is instructed to terminate the conversation.--Next request.---AI User:--Instruction: Identify the number of messages that camel decided to limit.-Input: None---AI Assistant:--Function Execution: local_retriever- Args: {'query': 'number of messages camel decided to limit'}- Result: Original Query:-{number of messages camel decided to limit}-Retrieved Context:-to limit the number of messages to 40 is also cost-related. Even if we provide a set of termination conditions, we still want to put a safeguard to the maximum limit of the message. It is because after the task is completed the agents will provide short outputs like "thank you" and "welcome". If no safeguard is set and termination fails, the conversation will only end until it exceeds the token limit, which may end up with thousands of API calls and hundreds of USD dollars cost.--Solution: Camel decided to limit the number of messages to 40 as a safeguard to prevent excessive API calls and associated costs.--Next request.---AI User:--Instruction: Calculate the value of the message limit plus 100.-Input: None---AI Assistant:--Function Execution: add- Args: {'a': 40, 'b': 100}- Result: 140--Solution: The value of the message limit plus 100 is 140.--Next request.---AI User:--CAMEL_TASK_DONE---AI Assistant:--Solution: Understood, the task is completed.--If you have any more tasks or need further assistance, feel free to provide new instructions.-```diff --git a/docs/tutorials_and_cookbooks/agents_with_tools.md b/docs/tutorials_and_cookbooks/agents_with_tools.mddeleted file mode 100644index 6725985e8..000000000--- a/docs/tutorials_and_cookbooks/agents_with_tools.md+++ /dev/null@@ -1,302 +0,0 @@-# ๐ซ Agents with Tools--[](https://colab.research.google.com/drive/1DMtHu4v2GqfjgvC9H4jkp49Bv1Fkd3DH?authuser=1#scrollTo=ssX_map8c6mx)---## In this notebook, we demonstrate the usage of CAMEL Tools with ChatAgent and RolePlaying.--2 main parts included:-- Using Tools Integrated by CAMEL-- Customize Your Own Tools---Import CAMEL modules, for the tool part we will take search tool as one example, other tools are commented out.-```python-from camel.agents import ChatAgent-from camel.configs import ChatGPTConfig-from camel.toolkits import (- SEARCH_FUNCS,- # MAP_FUNCS,- # MATH_FUNCS,- # TWITTER_FUNCS,- # WEATHER_FUNCS,- # RETRIEVAL_FUNCS,- # TWITTER_FUNCS,- # SLACK_FUNCS,-)-from camel.messages import BaseMessage-from camel.models import ModelFactory-from camel.types import ModelPlatformType, ModelType-```--Let's customize one tool, take the simple math calactor as one example, when you define your own function, please make sure the argument name and docstring is clear, Agent will try to understand what this function can do and when to use the function based on the function information you provided.-```python-def add(a: int, b: int) -> int:- r"""Adds two numbers.-- Args:- a (int): The first number to be added.- b (int): The second number to be added.-- Returns:- integer: The sum of the two numbers.- """- return a + b--def sub(a: int, b: int) -> int:- r"""Do subtraction between two numbers.-- Args:- a (int): The minuend in subtraction.- b (int): The subtrahend in subtraction.-- Returns:- integer: The result of subtracting :obj:`b` from :obj:`a`.- """- return a - b-```---Add these 2 customized functions as CAMEL's OpenAIFunction list-```python-from camel.functions.openai_function import OpenAIFunction---MATH_FUNCS: list[OpenAIFunction] = [- OpenAIFunction(func) for func in [add, sub]-]-```--Add the tool from CAMEL and defined by yourself to the tool list-```python-tool_list = [*SEARCH_FUNCS, *MATH_FUNCS]-```--Set the ChatAgent able to call the tool-```python-# Set the backend mode, this model should support tool calling-model=ModelFactory.create(- model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.GPT_3_5_TURBO,- model_config_dict=ChatGPTConfig(- temperature=0.0,- ).as_dict(),-)--# Set message for the assistant-assistant_sys_msg = BaseMessage.make_assistant_message(- role_name="Search Agent",- content= """You are a helpful assistant to do search task."""-)--# Set the config parameter for the model-assistant_model_config = ChatGPTConfig(- temperature=0.0,-)--# Set the agent-agent = ChatAgent(- assistant_sys_msg,- model=model,- tools=tool_list-)-```--Let's define two test prompt for the agent to run-```python-# Set prompt for the search task-prompt_search = ("""When was University of Oxford set up""")-# Set prompt for the calculation task-prompt_calculate = ("""Assume now is 2024 in the Gregorian calendar, University of Oxford was set up in 1096, estimate the current age of University of Oxford""")--# Convert the two prompt as message that can be accepted by the Agent-user_msg_search = BaseMessage.make_user_message(role_name="User", content=prompt_search)-user_msg_calculate = BaseMessage.make_user_message(role_name="User", content=prompt_calculate)--# Get response-assistant_response_search = agent.step(user_msg_search)-assistant_response_calculate = agent.step(user_msg_calculate)-```--Let's see how did the agent use the tool for the 2 tasks-```python-print(assistant_response_search.info['tool_calls'])-```--```markdown->>>-[FunctionCallingRecord(func_name='search_wiki', args={'entity': 'University of Oxford'}, result="The University of Oxford is a collegiate research university in Oxford, United Kingdom. There is evidence of teaching as early as 1096, making it the oldest university in the English-speaking world and the world's second-oldest university in continuous operation. It grew rapidly from 1167, when Henry II banned English students from attending the University of Paris. After disputes between students and Oxford townsfolk in 1209, some academics fled north-east to Cambridge where they established what became the University of Cambridge. The two English ancient universities share many common features and are jointly referred to as Oxbridge.")]-```--```python-print(assistant_response_calculate.info['tool_calls'])-```--```markdown->>>-[FunctionCallingRecord(func_name='sub', args={'a': 2024, 'b': 1096}, result=928)]-```--Now the single agent has the ability to use tool, let set one small AI society, the society would include one user agent and one assistant agent, the assistant agent is the one we just set can use tool.-```python-from camel.societies import RolePlaying-from camel.agents.chat_agent import FunctionCallingRecord-from camel.utils import print_text_animated-from colorama import Fore--# Set a task-task_prompt=("Assume now is 2024 in the Gregorian calendar, "- "estimate the current age of University of Oxford "- "and then add 10 more years to this age.")--# Set role playing-role_play_session = RolePlaying(- assistant_role_name="Searcher",- user_role_name="Professor",- assistant_agent_kwargs=dict(- model=ModelFactory.create(- model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.GPT_3_5_TURBO,- model_config_dict=assistant_model_config.as_dict(),- ),- tools=tool_list,- ),- user_agent_kwargs=dict(- model=ModelFactory.create(- model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.GPT_3_5_TURBO,- model_config_dict=ChatGPTConfig(temperature=0.0).as_dict(),- ),- ),- task_prompt=task_prompt,- with_task_specify=False,-)--# Set the limit for the chat turn-chat_turn_limit=10--print(Fore.YELLOW + f"Original task prompt:\n{task_prompt}\n")-print(- Fore.CYAN- + "Specified task prompt:"- + f"\n{role_play_session.specified_task_prompt}\n"-)-print(Fore.RED + f"Final task prompt:\n{role_play_session.task_prompt}\n")--n = 0-input_msg = role_play_session.init_chat()-while n < chat_turn_limit:- n += 1- assistant_response, user_response = role_play_session.step(input_msg)-- if assistant_response.terminated:- print(- Fore.GREEN- + (- "AI Assistant terminated. Reason: "- f"{assistant_response.info['termination_reasons']}."- )- )- break- if user_response.terminated:- print(- Fore.GREEN- + (- "AI User terminated. "- f"Reason: {user_response.info['termination_reasons']}."- )- )- break-- # Print output from the user- print_text_animated(- Fore.BLUE + f"AI User:\n\n{user_response.msg.content}\n"- )-- # Print output from the assistant, including any function- # execution information- print_text_animated(Fore.GREEN + "AI Assistant:")- tool_calls: list[FunctionCallingRecord] = assistant_response.info[- 'tool_calls'- ]- for func_record in tool_calls:- print_text_animated(f"{func_record}")- print_text_animated(f"{assistant_response.msg.content}\n")-- if "CAMEL_TASK_DONE" in user_response.msg.content:- break-- input_msg = assistant_response.msg-```--```markdown->>>-Original task prompt:-Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age.--Specified task prompt:-None--Final task prompt:-Assume now is 2024 in the Gregorian calendar, estimate the current age of University of Oxford and then add 10 more years to this age.--AI User:--Instruction: Provide the founding year of the University of Oxford.-Input: None---AI Assistant:--Function Execution: search_wiki- Args: {'entity': 'University of Oxford'}- Result: The University of Oxford is a collegiate research university in Oxford, United Kingdom. There is evidence of teaching as early as 1096, making it the oldest university in the English-speaking world and the world's second-oldest university in continuous operation. It grew rapidly from 1167, when Henry II banned English students from attending the University of Paris. After disputes between students and Oxford townsfolk in 1209, some academics fled north-east to Cambridge where they established what became the University of Cambridge. The two English ancient universities share many common features and are jointly referred to as Oxbridge.--Solution: The University of Oxford has evidence of teaching as early as 1096, making it the oldest university in the English-speaking world. Therefore, the founding year of the University of Oxford is considered to be around 1096.--Next request.---AI User:--Instruction: Calculate the current age of the University of Oxford in 2024.-Input: None---AI Assistant:--Function Execution: sub- Args: {'a': 2024, 'b': 1096}- Result: 928--Solution: The current age of the University of Oxford in 2024 is 928 years.--Next request.---AI User:--Instruction: Add 10 years to the current age of the University of Oxford.-Input: None---AI Assistant:--Function Execution: add- Args: {'a': 928, 'b': 10}- Result: 938--Solution: Adding 10 years to the current age of the University of Oxford, the estimated age of the University of Oxford in 2034 would be 938 years.--Next request.---AI User:--<CAMEL_TASK_DONE>---AI Assistant:--Task completed.-```\ No newline at end of filediff --git a/docs/tutorials_and_cookbooks/agents_with_tools_from_Composio.md b/docs/tutorials_and_cookbooks/agents_with_tools_from_Composio.mddeleted file mode 100644index 9066b9f49..000000000--- a/docs/tutorials_and_cookbooks/agents_with_tools_from_Composio.md+++ /dev/null@@ -1,211 +0,0 @@-# ๐ซ Agents with Tools from Composio--[](https://colab.research.google.com/drive/1x2FYThMPtQXLzKZAhf_Ry-oeU6oPygdm?authuser=1#scrollTo=6c1kqMDxDodN)---## In this notebook, we demonstrate the usage of CAMEL `ChatAgent` and `RolePlaying` with Tools from Composio, allowing agents to seamlessly interact with external applications.--*Goal: Star a repository on GitHub with natural language & CAMEL Agent*--## Install Packages & Connect a Tool-Ensure you have the necessary packages installed and connect your GitHub account to allow your CAMEL agents to utilize GitHub functionalities.-```python-import composio-```--Login to Composio-```bash-composio login-```--Connect your Github account (this is a shell command, so it should be run in your terminal or with '!' prefix in a Jupyter Notebook)-```bash-composio add github-```--Check all different apps which you can connect with--```bash-composio apps-```--## Prepare your environment by initializing necessary imports from CAMEL & Composio.--```python-from typing import List--from colorama import Fore-from composio_camel import Action, ComposioToolSet--from camel.agents.chat_agent import FunctionCallingRecord-from camel.configs import ChatGPTConfig-from camel.models import ModelFactory-from camel.societies import RolePlaying-from camel.types import ModelPlatformType, ModelType-from camel.utils import print_text_animated-```--## Let's run CAMEL agents with tools from Composio!--Set your task-```python-task_prompt = (- "I have created a new Github Repo,"- "Please star my github repository: camel-ai/camel"-)-```--Set Toolset-```python-composio_toolset = ComposioToolSet()--tools = composio_toolset.get_actions(- actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER]-)-```--Set models for user agent and assistant agent, give tool to the assistant-```python-assistant_agent_model = ModelFactory.create(- model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.GPT_3_5_TURBO,- model_config_dict=ChatGPTConfig().as_dict(),-)--user_agent_model = ModelFactory.create(- model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.GPT_3_5_TURBO,- model_config_dict=ChatGPTConfig().as_dict(),-)-```--Set RolePlaying session-```python-role_play_session = RolePlaying(- assistant_role_name="Developer",- user_role_name="CAMEL User",- assistant_agent_kwargs=dict(- model=assistant_agent_model,- tools=tools,- ),- user_agent_kwargs=dict(- model=user_agent_model,- ),- task_prompt=task_prompt,- with_task_specify=False,-)-```--Print the system message and task prompt-```python-print(Fore.YELLOW + f"Original task prompt:\n{task_prompt}\n")-print(- Fore.CYAN- + "Specified task prompt:"- + f"\n{role_play_session.specified_task_prompt}\n"-)-print(Fore.RED + f"Final task prompt:\n{role_play_session.task_prompt}\n")-```--```markdown->>>-AI Assistant sys message:-Original task prompt:-I have created a new Github Repo,Please star my github repository: camel-ai/camel--Specified task prompt:-None--Final task prompt:-I have created a new Github Repo,Please star my github repository: camel-ai/camel-```--Set terminate rule and print the chat message-```python-n = 0-input_msg = role_play_session.init_chat()-while n < 50:- n += 1- assistant_response, user_response = role_play_session.step(input_msg)-- if assistant_response.terminated:- print(- Fore.GREEN- + (- "AI Assistant terminated. Reason: "- f"{assistant_response.info['termination_reasons']}."- )- )- break- if user_response.terminated:- print(- Fore.GREEN- + (- "AI User terminated. "- f"Reason: {user_response.info['termination_reasons']}."- )- )- break-- # Print output from the user- print_text_animated(- Fore.BLUE + f"AI User:\n\n{user_response.msg.content}\n"- )-- # Print output from the assistant, including any function- # execution information- print_text_animated(Fore.GREEN + "AI Assistant:")- tool_calls: List[FunctionCallingRecord] = assistant_response.info[- 'tool_calls'- ]- for func_record in tool_calls:- print_text_animated(f"{func_record}")- print_text_animated(f"{assistant_response.msg.content}\n")-- if "CAMEL_TASK_DONE" in user_response.msg.content:- break-- input_msg = assistant_response.msg-```--```markdown->>>-AI User:--Instruction: Visit the Github repository I created.-Input: None---AI Assistant:--Solution: To visit the Github repository you created, you can simply open a web browser and go to the following URL: https://github.com/camel-ai/camel--Next request.---AI User:--Instruction: Click on the "Star" button on the Github repository page.-Input: None---AI Assistant:--Function Execution: github_activity_star_repo_for_authenticated_user- Args: {'owner': 'camel-ai', 'repo': 'camel'}- Result: {'execution_details': {'executed': True}, 'response_data': ''}--Solution: I have successfully starred your Github repository "camel-ai/camel".--Next request.---AI User:--<CAMEL_TASK_DONE>---AI Assistant:--Great! The task is completed. If you have any more tasks or need further assistance in the future, feel free to ask. Have a wonderful day!-```\ No newline at end of filediff --git a/examples/tasks/task_generation.py b/examples/tasks/task_generation.pyindex 0a7f8074f..9764e22a4 100644--- a/examples/tasks/task_generation.py+++ b/examples/tasks/task_generation.py@@ -54,7 +54,10 @@ print(task.to_string())task_manager = TaskManager(task)evolved_task = task_manager.evolve(task, agent=agent)-print(evolved_task.to_string())+if evolved_task is not None:+ print(evolved_task.to_string())+else:+ print("Evolved task is None.")new_tasks = task.decompose(agent=agent)diff --git a/poetry.lock b/poetry.lockindex b1abc9a07..36e01c2e7 100644--- a/poetry.lock+++ b/poetry.lock@@ -544,6 +544,24 @@ charset-normalizer = ["charset-normalizer"]html5lib = ["html5lib"]lxml = ["lxml"]+[[package]]+name = "bleach"+version = "6.1.0"+description = "An easy safelist-based HTML-sanitizing tool."+optional = false+python-versions = ">=3.8"+files = [+ {file = "bleach-6.1.0-py3-none-any.whl", hash = "sha256:3225f354cfc436b9789c66c4ee030194bee0568fbf9cbdad3bc8b5c26c5f12b6"},+ {file = "bleach-6.1.0.tar.gz", hash = "sha256:0a31f1837963c41d46bbf1331b8778e1308ea0791db03cc4e7357b97cf42a8fe"},+]++[package.dependencies]+six = ">=1.9.0"+webencodings = "*"++[package.extras]+css = ["tinycss2 (>=1.1.0,<1.3)"]+[[package]]name = "botocore"version = "1.35.19"@@ -1233,6 +1251,17 @@ files = [{file = "decorator-5.1.1.tar.gz", hash = "sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330"},]+[[package]]+name = "defusedxml"+version = "0.7.1"+description = "XML bomb protection for Python stdlib modules"+optional = false+python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"+files = [+ {file = "defusedxml-0.7.1-py2.py3-none-any.whl", hash = "sha256:a352e7e428770286cc899e2542b6cdaedb2b4953ff269a210103ec58f6198a61"},+ {file = "defusedxml-0.7.1.tar.gz", hash = "sha256:1bb3032db185915b62d7c6209c5a8792be6a32ab2fedacc84e01b52c51aa3e69"},+]+[[package]]name = "deprecated"version = "1.2.14"@@ -1584,6 +1613,20 @@ lz4 = ["lz4"]snappy = ["cramjam"]zstandard = ["zstandard"]+[[package]]+name = "fastjsonschema"+version = "2.20.0"+description = "Fastest Python implementation of JSON schema"+optional = false+python-versions = "*"+files = [+ {file = "fastjsonschema-2.20.0-py3-none-any.whl", hash = "sha256:5875f0b0fa7a0043a91e93a9b8f793bcbbba9691e7fd83dca95c28ba26d21f0a"},+ {file = "fastjsonschema-2.20.0.tar.gz", hash = "sha256:3d48fc5300ee96f5d116f10fe6f28d938e6008f59a6a025c2649475b87f76a23"},+]++[package.extras]+devel = ["colorama", "json-spec", "jsonschema", "pylint", "pytest", "pytest-benchmark", "pytest-cache", "validictory"]+[[package]]name = "feedfinder2"version = "0.0.4"@@ -3009,6 +3052,17 @@ traitlets = ">=5.3"docs = ["myst-parser", "pydata-sphinx-theme", "sphinx-autodoc-typehints", "sphinxcontrib-github-alt", "sphinxcontrib-spelling", "traitlets"]test = ["ipykernel", "pre-commit", "pytest (<8)", "pytest-cov", "pytest-timeout"]+[[package]]+name = "jupyterlab-pygments"+version = "0.3.0"+description = "Pygments theme using JupyterLab CSS variables"+optional = false+python-versions = ">=3.8"+files = [+ {file = "jupyterlab_pygments-0.3.0-py3-none-any.whl", hash = "sha256:841a89020971da1d8693f1a99997aefc5dc424bb1b251fd6322462a1b8842780"},+ {file = "jupyterlab_pygments-0.3.0.tar.gz", hash = "sha256:721aca4d9029252b11cfa9d185e5b5af4d54772bb8072f9b7036f4170054d35d"},+]+[[package]]name = "kiwisolver"version = "1.4.7"@@ -3678,6 +3732,17 @@ typing-inspect = ">=0.9.0,<0.10.0"[package.extras]gcp = ["google-auth (==2.27.0)", "requests (>=2.32.3,<3.0.0)"]+[[package]]+name = "mistune"+version = "3.0.2"+description = "A sane and fast Markdown parser with useful plugins and renderers"+optional = false+python-versions = ">=3.7"+files = [+ {file = "mistune-3.0.2-py3-none-any.whl", hash = "sha256:71481854c30fdbc938963d3605b72501f5c10a9320ecd412c121c163a1c7d205"},+ {file = "mistune-3.0.2.tar.gz", hash = "sha256:fc7f93ded930c92394ef2cb6f04a8aabab4117a91449e72dcc8dfa646a508be8"},+]+[[package]]name = "mock"version = "5.1.0"@@ -3974,6 +4039,105 @@ pandas = ["pandas (>=0.25.3)"]polars = ["polars (>=0.20.3)"]pyarrow = ["pyarrow (>=11.0.0)"]+[[package]]+name = "nbclient"+version = "0.10.0"+description = "A client library for executing notebooks. Formerly nbconvert's ExecutePreprocessor."+optional = false+python-versions = ">=3.8.0"+files = [+ {file = "nbclient-0.10.0-py3-none-any.whl", hash = "sha256:f13e3529332a1f1f81d82a53210322476a168bb7090a0289c795fe9cc11c9d3f"},+ {file = "nbclient-0.10.0.tar.gz", hash = "sha256:4b3f1b7dba531e498449c4db4f53da339c91d449dc11e9af3a43b4eb5c5abb09"},+]++[package.dependencies]+jupyter-client = ">=6.1.12"+jupyter-core = ">=4.12,<5.0.dev0 || >=5.1.dev0"+nbformat = ">=5.1"+traitlets = ">=5.4"++[package.extras]+dev = ["pre-commit"]+docs = ["autodoc-traits", "mock", "moto", "myst-parser", "nbclient[test]", "sphinx (>=1.7)", "sphinx-book-theme", "sphinxcontrib-spelling"]+test = ["flaky", "ipykernel (>=6.19.3)", "ipython", "ipywidgets", "nbconvert (>=7.0.0)", "pytest (>=7.0,<8)", "pytest-asyncio", "pytest-cov (>=4.0)", "testpath", "xmltodict"]++[[package]]+name = "nbconvert"+version = "7.16.4"+description = "Converting Jupyter Notebooks (.ipynb files) to other formats. Output formats include asciidoc, html, latex, markdown, pdf, py, rst, script. nbconvert can be used both as a Python library (`import nbconvert`) or as a command line tool (invoked as `jupyter nbconvert ...`)."+optional = false+python-versions = ">=3.8"+files = [+ {file = "nbconvert-7.16.4-py3-none-any.whl", hash = "sha256:05873c620fe520b6322bf8a5ad562692343fe3452abda5765c7a34b7d1aa3eb3"},+ {file = "nbconvert-7.16.4.tar.gz", hash = "sha256:86ca91ba266b0a448dc96fa6c5b9d98affabde2867b363258703536807f9f7f4"},+]++[package.dependencies]+beautifulsoup4 = "*"+bleach = "!=5.0.0"+defusedxml = "*"+jinja2 = ">=3.0"+jupyter-core = ">=4.7"+jupyterlab-pygments = "*"+markupsafe = ">=2.0"+mistune = ">=2.0.3,<4"+nbclient = ">=0.5.0"+nbformat = ">=5.7"+packaging = "*"+pandocfilters = ">=1.4.1"+pygments = ">=2.4.1"+tinycss2 = "*"+traitlets = ">=5.1"++[package.extras]+all = ["flaky", "ipykernel", "ipython", "ipywidgets (>=7.5)", "myst-parser", "nbsphinx (>=0.2.12)", "playwright", "pydata-sphinx-theme", "pyqtwebengine (>=5.15)", "pytest (>=7)", "sphinx (==5.0.2)", "sphinxcontrib-spelling", "tornado (>=6.1)"]+docs = ["ipykernel", "ipython", "myst-parser", "nbsphinx (>=0.2.12)", "pydata-sphinx-theme", "sphinx (==5.0.2)", "sphinxcontrib-spelling"]+qtpdf = ["pyqtwebengine (>=5.15)"]+qtpng = ["pyqtwebengine (>=5.15)"]+serve = ["tornado (>=6.1)"]+test = ["flaky", "ipykernel", "ipywidgets (>=7.5)", "pytest (>=7)"]+webpdf = ["playwright"]++[[package]]+name = "nbformat"+version = "5.10.4"+description = "The Jupyter Notebook format"+optional = false+python-versions = ">=3.8"+files = [+ {file = "nbformat-5.10.4-py3-none-any.whl", hash = "sha256:3b48d6c8fbca4b299bf3982ea7db1af21580e4fec269ad087b9e81588891200b"},+ {file = "nbformat-5.10.4.tar.gz", hash = "sha256:322168b14f937a5d11362988ecac2a4952d3d8e3a2cbeb2319584631226d5b3a"},+]++[package.dependencies]+fastjsonschema = ">=2.15"+jsonschema = ">=2.6"+jupyter-core = ">=4.12,<5.0.dev0 || >=5.1.dev0"+traitlets = ">=5.1"++[package.extras]+docs = ["myst-parser", "pydata-sphinx-theme", "sphinx", "sphinxcontrib-github-alt", "sphinxcontrib-spelling"]+test = ["pep440", "pre-commit", "pytest", "testpath"]++[[package]]+name = "nbsphinx"+version = "0.9.5"+description = "Jupyter Notebook Tools for Sphinx"+optional = false+python-versions = ">=3.6"+files = [+ {file = "nbsphinx-0.9.5-py3-none-any.whl", hash = "sha256:d82f71084425db1f48e72515f15c25b4de8652ceaab513ee462ac05f1b8eae0a"},+ {file = "nbsphinx-0.9.5.tar.gz", hash = "sha256:736916e7b0dab28fc904f4a9ae3b53a9a50c29fccc6329c052fcc7485abcf2b7"},+]++[package.dependencies]+docutils = ">=0.18.1"+jinja2 = "*"+nbconvert = ">=5.3,<5.4 || >5.4"+nbformat = "*"+sphinx = ">=1.8"+traitlets = ">=5"+[[package]]name = "neo4j"version = "5.24.0"@@ -4644,6 +4808,17 @@ sql-other = ["SQLAlchemy (>=2.0.0)", "adbc-driver-postgresql (>=0.8.0)", "adbc-dtest = ["hypothesis (>=6.46.1)", "pytest (>=7.3.2)", "pytest-xdist (>=2.2.0)"]xml = ["lxml (>=4.9.2)"]+[[package]]+name = "pandocfilters"+version = "1.5.1"+description = "Utilities for writing pandoc filters in python"+optional = false+python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"+files = [+ {file = "pandocfilters-1.5.1-py2.py3-none-any.whl", hash = "sha256:93be382804a9cdb0a7267585f157e5d1731bbe5545a85b268d6f5fe6232de2bc"},+ {file = "pandocfilters-1.5.1.tar.gz", hash = "sha256:002b4a555ee4ebc03f8b66307e287fa492e4a77b4ea14d3f934328297bb4939e"},+]+[[package]]name = "parso"version = "0.8.4"@@ -7443,6 +7618,24 @@ safetensors = "*"torch = "*"torchvision = "*"+[[package]]+name = "tinycss2"+version = "1.3.0"+description = "A tiny CSS parser"+optional = false+python-versions = ">=3.8"+files = [+ {file = "tinycss2-1.3.0-py3-none-any.whl", hash = "sha256:54a8dbdffb334d536851be0226030e9505965bb2f30f21a4a82c55fb2a80fae7"},+ {file = "tinycss2-1.3.0.tar.gz", hash = "sha256:152f9acabd296a8375fbca5b84c961ff95971fcfc32e79550c8df8e29118c54d"},+]++[package.dependencies]+webencodings = ">=0.4"++[package.extras]+doc = ["sphinx", "sphinx_rtd_theme"]+test = ["pytest", "ruff"]+[[package]]name = "tinysegmenter"version = "0.3"@@ -8313,6 +8506,17 @@ files = [{file = "wcwidth-0.2.13.tar.gz", hash = "sha256:72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5"},]+[[package]]+name = "webencodings"+version = "0.5.1"+description = "Character encoding aliases for legacy web content"+optional = false+python-versions = "*"+files = [+ {file = "webencodings-0.5.1-py2.py3-none-any.whl", hash = "sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78"},+ {file = "webencodings-0.5.1.tar.gz", hash = "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923"},+]+[[package]]name = "websocket-client"version = "1.8.0"@@ -8833,4 +9037,4 @@ vector-databases = ["pymilvus", "qdrant-client"][metadata]lock-version = "2.0"python-versions = ">=3.10.0,<3.12"-content-hash = "12a41a62b8dc166c0db89b7ba3304b157bc8b3360842008fb0782d831e2d2ef0"+content-hash = "659689bad5abb0568f3f72765bec8d7794ce85dffb7dc7d3d3861aab257d7aaf"diff --git a/pyproject.toml b/pyproject.tomlindex b11706719..019e3c48f 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -285,6 +285,7 @@ sphinx = "^7"sphinx_book_theme = "*"docutils = "<0.20.0"myst-parser = "*"+nbsphinx = "*"[tool.ruff]line-length = 79