diff --git a/autogen/interoperability/crewai/crewai.py b/autogen/interoperability/crewai/crewai.py index 490dcbd81f..98df36cf05 100644 --- a/autogen/interoperability/crewai/crewai.py +++ b/autogen/interoperability/crewai/crewai.py @@ -26,7 +26,10 @@ def convert_tool(self, tool: Any) -> Tool: crewai_tool: CrewAITool = tool # type: ignore[no-any-unimported] name = _sanitize_name(crewai_tool.name) - description = crewai_tool.description.split("Tool Description: ")[-1] + description = ( + crewai_tool.description.split("Tool Description: ")[-1] + + " (IMPORTANT: When using arguments, put them all in an `args` dictionary)" + ) def func(args: crewai_tool.args_schema) -> Any: # type: ignore[no-any-unimported] return crewai_tool.run(**args.model_dump()) diff --git a/notebook/tools_crewai_tools_integration.ipynb b/notebook/tools_crewai_tools_integration.ipynb index 78b85cbccc..d0313a51f8 100644 --- a/notebook/tools_crewai_tools_integration.ipynb +++ b/notebook/tools_crewai_tools_integration.ipynb @@ -4,9 +4,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Integrating CrewAI Tools with the Autogen Framework\n", + "# Integrating CrewAI Tools with the AG2 Framework\n", "\n", - "In this tutorial, we demonstrate how to integrate [CrewAI Tools](https://github.com/crewAIInc/crewAI-tools/tree/main) into the Autogen framework. This process enables smooth interoperability between the two systems, allowing developers to leverage CrewAI's powerful tools within Autogen's flexible agent-based architecture. By the end of this guide, you will understand how to configure agents, convert CrewAI tools for use in Autogen, and validate the integration with a practical example.\n" + "In this tutorial, we demonstrate how to integrate [CrewAI Tools](https://github.com/crewAIInc/crewAI-tools/tree/main) into the AG2 framework. This process enables smooth interoperability between the two systems, allowing developers to leverage CrewAI's powerful tools within AG2's flexible agent-based architecture. By the end of this guide, you will understand how to configure agents, convert CrewAI tools for use in AG2, and validate the integration with a practical example.\n" ] }, { @@ -14,11 +14,11 @@ "metadata": {}, "source": [ "## Installation\n", - "Install the required packages for integrating CrewAI tools into the Autogen framework.\n", + "Install the required packages for integrating CrewAI tools into the AG2 framework.\n", "This ensures all dependencies for both frameworks are installed.\n", "\n", "```bash\n", - "pip install autogen[interop-crewai]\n", + "pip install ag2[interop-crewai]\n", "```" ] }, @@ -30,11 +30,11 @@ "\n", "Import necessary modules and tools.\n", "- `os` is used to access environment variables.\n", - "- `TemporaryDirectory` is used for creating a temporary workspace.\n", "- `Path` helps in handling file paths.\n", - "- `FileWriterTool` is the CrewAI tool we will integrate.\n", - "- `AssistantAgent` and `UserProxyAgent` are core Autogen classes.\n", - "- `CrewAIInteroperability` facilitates the interoperability between Autogen and CrewAI." + "- `TemporaryDirectory` is used for creating a temporary workspace.\n", + "- `FileWriterTool` and `ScrapeWebsiteTool` are the CrewAI tools we will integrate.\n", + "- `AssistantAgent` and `UserProxyAgent` are core AG2 classes.\n", + "- `CrewAIInteroperability` facilitates the interoperability between AG2 and CrewAI." ] }, { @@ -46,7 +46,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "2024-12-13 12:45:47,330 - 8269089792 - __init__.py-__init__:18 - WARNING: flaml.automl is not available. Please install flaml[automl] to enable AutoML functionalities.\n" + "/usr/local/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n", + "2024-12-16 22:31:29,213 - 139887720012672 - __init__.py-__init__:18 - WARNING: flaml.automl is not available. Please install flaml[automl] to enable AutoML functionalities.\n" ] } ], @@ -55,7 +57,7 @@ "from pathlib import Path\n", "from tempfile import TemporaryDirectory\n", "\n", - "from crewai_tools import FileWriterTool\n", + "from crewai_tools import FileWriterTool, ScrapeWebsiteTool\n", "\n", "from autogen import AssistantAgent, UserProxyAgent\n", "from autogen.interoperability.crewai import CrewAIInteroperability" @@ -79,7 +81,7 @@ "metadata": {}, "outputs": [], "source": [ - "config_list = [{\"model\": \"gpt-4\", \"api_key\": os.environ[\"OPENAI_API_KEY\"]}]\n", + "config_list = [{\"model\": \"gpt-4o-mini\", \"api_key\": os.environ[\"OPENAI_API_KEY\"]}]\n", "user_proxy = UserProxyAgent(\n", " name=\"User\",\n", " human_input_mode=\"NEVER\",\n", @@ -97,9 +99,9 @@ "source": [ "## Tool Integration\n", "\n", - "Initialize and register the CrewAI tool with Autogen.\n", + "Initialize and register the CrewAI tool with AG2.\n", "- `crewai_tool` is an instance of the `FileWriterTool` from CrewAI.\n", - "- `CrewAIInteroperability` converts the CrewAI tool to make it usable in Autogen.\n", + "- `CrewAIInteroperability` converts the CrewAI tool to make it usable in AG2.\n", "- `register_for_execution` and `register_for_llm` allow the tool to work with the UserProxyAgent and AssistantAgent." ] }, @@ -121,7 +123,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Demonstration\n", + "## File creation\n", "\n", "Demonstrate the integration by writing to a file using the converted CrewAI tool.\n", "- A temporary directory is created to simulate a file operation environment.\n", @@ -142,22 +144,15 @@ "\u001b[33mUser\u001b[0m (to chatbot):\n", "\n", "Write 'Easy Migration :)' into tool_result.txt.\n", - "Use /var/folders/79/kmq3y0pj0rbgrrnf4xlq8q0c0000gn/T/tmpwg6ibnmg dir.\n", + "Use /tmp/tmpt6zkd1db dir.\n", "\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[33mchatbot\u001b[0m (to User):\n", "\n", - "\u001b[32m***** Suggested tool call (call_en1Jhr0uYnWnMdQCaZz0WxQq): File_Writer_Tool *****\u001b[0m\n", + "\u001b[32m***** Suggested tool call (call_UR57tA4Dr5YF0aLInnRGa8eD): File_Writer_Tool *****\u001b[0m\n", "Arguments: \n", - "{\n", - " \"args\": {\n", - " \"filename\": \"tool_result.txt\",\n", - " \"directory\": \"/var/folders/79/kmq3y0pj0rbgrrnf4xlq8q0c0000gn/T/tmpwg6ibnmg\",\n", - " \"overwrite\": \"yes\",\n", - " \"content\": \"Easy Migration :)\"\n", - " }\n", - "}\n", + "{\"args\":{\"filename\":\"tool_result.txt\",\"directory\":\"/tmp/tmpt6zkd1db\",\"content\":\"Easy Migration :)\",\"overwrite\":\"True\"}}\n", "\u001b[32m*********************************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", @@ -166,14 +161,14 @@ "Using Tool: File Writer Tool\n", "\u001b[33mUser\u001b[0m (to chatbot):\n", "\n", - "\u001b[32m***** Response from calling tool (call_en1Jhr0uYnWnMdQCaZz0WxQq) *****\u001b[0m\n", - "Content successfully written to /var/folders/79/kmq3y0pj0rbgrrnf4xlq8q0c0000gn/T/tmpwg6ibnmg/tool_result.txt\n", + "\u001b[32m***** Response from calling tool (call_UR57tA4Dr5YF0aLInnRGa8eD) *****\u001b[0m\n", + "Content successfully written to /tmp/tmpt6zkd1db/tool_result.txt\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[33mchatbot\u001b[0m (to User):\n", "\n", - "The text \"Easy Migration :)\" has been successfully written into the file \"tool_result.txt\" in the directory \"/var/folders/79/kmq3y0pj0rbgrrnf4xlq8q0c0000gn/T/tmpwg6ibnmg\".\n", + "The message 'Easy Migration :)' has been successfully written to the file `tool_result.txt` in the directory `/tmp/tmpt6zkd1db`.\n", "\n", "TERMINATE\n", "\n", @@ -187,22 +182,194 @@ " message = f\"\"\"Write 'Easy Migration :)' into {filename}.\n", "Use {tmpdirname} dir.\n", "\"\"\"\n", + "\n", " user_proxy.initiate_chat(recipient=chatbot, message=message, max_turns=2)\n", "\n", - " assert Path(tmpdirname, filename).read_text() == \"Easy Migration :)\"\n" + " assert Path(tmpdirname, filename).read_text() == \"Easy Migration :)\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Scrape the web\n", + "\n", + "Demonstrate scraping a website using the converted CrewAI tool.\n", + "- The `message` instructs the chatbot to scrape the AG2 website.\n", + "- `user_proxy.initiate_chat` starts the interaction, with the chatbot processing the request and using the tool.\n", + "- Finally, we output the summary from the LLM" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mUser\u001b[0m (to chatbot):\n", + "\n", + "Scape the website https://ag2.ai/\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33mchatbot\u001b[0m (to User):\n", + "\n", + "\u001b[32m***** Suggested tool call (call_jwhEriZ8xz0sJfbNXZQYeWRH): Read_website_content *****\u001b[0m\n", + "Arguments: \n", + "{\"args\":{\"website_url\":\"https://ag2.ai/\"}}\n", + "\u001b[32m*************************************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[35m\n", + ">>>>>>>> EXECUTING FUNCTION Read_website_content...\u001b[0m\n", + "Using Tool: Read website content\n", + "\u001b[33mUser\u001b[0m (to chatbot):\n", + "\n", + "\u001b[32m***** Response from calling tool (call_jwhEriZ8xz0sJfbNXZQYeWRH) *****\u001b[0m\n", + "\n", + "AgentOS\n", + "Join our growing community of over 20,000 agent builders Join our growing community of over 20,000 agent builders The Open-Source AgentOS Build production-ready multi-agent systems in minutes, not months. Github Discord The End-to-End Platform for Multi-Agent Automation The End-to-End Platform for Multi-Agent Automation Flexible Agent Construction and Orchestration Create specialized agents that work together seamlessly. AG2 makes it easy to define roles, configure behaviors, and orchestrate collaboration - all through simple, intuitive code. → Assistant agents for problem-solving → Executor agents for taking action → Critic agents for validation → Group chat managers for coordination Built-in Conversation Patterns Built-in Conversation Patterns Stop wrestling with agent coordination. AG2 handles message routing, state management, and conversation flow automatically. → Two-agent conversations → Group chats with dynamic speaker selection → Sequential chats with context carryover → Nested conversations for modularity Seamless Human-AI collaboration Seamless Human-AI collaboration Seamlessly integrate human oversight and input into your agent workflows. → Configurable human input modes → Flexible intervention points → Optional human approval workflows → Interactive conversation interfaces → Context-aware human handoff Roadmap AG2 STUDIO → Visual agent system design → Real-time testing and debugging → One-click deployment to production → Perfect for prototyping and MVPs AG2 STUDIO → Visual agent system design → Real-time testing and debugging → One-click deployment to production → Perfect for prototyping and MVPs AG2 STUDIO → Visual agent system design → Real-time testing and debugging → One-click deployment to production → Perfect for prototyping and MVPs AG2 MARKETPLACE → Share and monetize your agents → Discover pre-built solution templates → Quick-start your agent development → Connect with other builders AG2 MARKETPLACE → Share and monetize your agents → Discover pre-built solution templates → Quick-start your agent development → Connect with other builders AG2 MARKETPLACE → Share and monetize your agents → Discover pre-built solution templates → Quick-start your agent development → Connect with other builders SCALING TOOLS → Zero to production deployment guides → Usage analytics and cost optimization → Team collaboration features → Enterprise-ready security controls SCALING TOOLS → Zero to production deployment guides → Usage analytics and cost optimization → Team collaboration features → Enterprise-ready security controls SCALING TOOLS → Zero to production deployment guides → Usage analytics and cost optimization → Team collaboration features → Enterprise-ready security controls AG2 STUDIO → Visual agent system design → Real-time testing and debugging → One-click deployment to production → Perfect for prototyping and MVPs AG2 STUDIO → Visual agent system design → Real-time testing and debugging → One-click deployment to production → Perfect for prototyping and MVPs AG2 MARKETPLACE → Share and monetize your agents → Discover pre-built solution templates → Quick-start your agent development → Connect with other builders AG2 MARKETPLACE → Share and monetize your agents → Discover pre-built solution templates → Quick-start your agent development → Connect with other builders SCALING TOOLS → Zero to production deployment guides → Usage analytics and cost optimization → Team collaboration features → Enterprise-ready security controls SCALING TOOLS → Zero to production deployment guides → Usage analytics and cost optimization → Team collaboration features → Enterprise-ready security controls Whether you're a solo founder prototyping the next big AI product, or an enterprise team deploying at scale we're building AG2 for you. This is AgentOS - making multi-agent development accessible to everyone. Github Join Our Growing Community Join Our Growing Community → 20,000+ active agent builders → Daily technical discussions → Weekly community calls → Open RFC process → Regular contributor events (Coming soon) Discord Problem Features Roadmap Community Documentation Problem Features Roadmap Community Documentation Problem Features Roadmap Community Documentation\n", + "\n", + "\u001b[32m**********************************************************************\u001b[0m\n", + "\n", + "--------------------------------------------------------------------------------\n", + "\u001b[33mchatbot\u001b[0m (to User):\n", + "\n", + "I have scraped the content from the website https://ag2.ai/. Here are the key points:\n", + "\n", + "---\n", + "\n", + "**AgentOS**\n", + "- Join a community of over 20,000 agent builders.\n", + "- Build production-ready multi-agent systems quickly.\n", + " \n", + "**Features:**\n", + "- **Flexible Agent Construction and Orchestration**: Define roles, configure behaviors, and orchestrate collaboration through intuitive code.\n", + " - Assistant agents for problem-solving.\n", + " - Executor agents for taking action.\n", + " - Critic agents for validation.\n", + " - Group chat managers for coordination.\n", + "\n", + "- **Built-in Conversation Patterns**: Automatically handles message routing, state management, and conversation flow.\n", + " - Two-agent conversations.\n", + " - Group chats with dynamic speaker selection.\n", + " - Sequential chats with context carryover.\n", + " - Nested conversations for modularity.\n", + "\n", + "- **Seamless Human-AI Collaboration**: Integrate human oversight and input into workflows.\n", + " - Configurable human input modes.\n", + " - Flexible intervention points.\n", + " - Optional human approval workflows.\n", + " - Interactive conversation interfaces.\n", + " - Context-aware human handoff.\n", + "\n", + "**Roadmap:**\n", + "- **AG2 STUDIO**: \n", + " - Visual agent system design.\n", + " - Real-time testing and debugging.\n", + " - One-click deployment to production.\n", + "\n", + "- **AG2 MARKETPLACE**: \n", + " - Share and monetize agents.\n", + " - Discover pre-built solution templates.\n", + "\n", + "- **Scaling Tools**: \n", + " - Zero to production deployment guides.\n", + " - Usage analytics and cost optimization.\n", + " - Team collaboration features.\n", + "\n", + "---\n", + "\n", + "Whether you're a solo founder or an enterprise team, AG2 aims to make multi-agent development accessible for everyone. \n", + "\n", + "TERMINATE\n", + "\n", + "--------------------------------------------------------------------------------\n" + ] + } + ], + "source": [ + "crewai_scrape_tool = ScrapeWebsiteTool()\n", + "ag2_tool = crewai_interop.convert_tool(crewai_scrape_tool)\n", + "\n", + "ag2_tool.register_for_execution(user_proxy)\n", + "ag2_tool.register_for_llm(chatbot)\n", + "\n", + "message = \"Scape the website https://ag2.ai/\"\n", + "\n", + "chat_result = user_proxy.initiate_chat(recipient=chatbot, message=message, max_turns=2)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I have scraped the content from the website https://ag2.ai/. Here are the key points:\n", + "\n", + "---\n", + "\n", + "**AgentOS**\n", + "- Join a community of over 20,000 agent builders.\n", + "- Build production-ready multi-agent systems quickly.\n", + " \n", + "**Features:**\n", + "- **Flexible Agent Construction and Orchestration**: Define roles, configure behaviors, and orchestrate collaboration through intuitive code.\n", + " - Assistant agents for problem-solving.\n", + " - Executor agents for taking action.\n", + " - Critic agents for validation.\n", + " - Group chat managers for coordination.\n", + "\n", + "- **Built-in Conversation Patterns**: Automatically handles message routing, state management, and conversation flow.\n", + " - Two-agent conversations.\n", + " - Group chats with dynamic speaker selection.\n", + " - Sequential chats with context carryover.\n", + " - Nested conversations for modularity.\n", + "\n", + "- **Seamless Human-AI Collaboration**: Integrate human oversight and input into workflows.\n", + " - Configurable human input modes.\n", + " - Flexible intervention points.\n", + " - Optional human approval workflows.\n", + " - Interactive conversation interfaces.\n", + " - Context-aware human handoff.\n", + "\n", + "**Roadmap:**\n", + "- **AG2 STUDIO**: \n", + " - Visual agent system design.\n", + " - Real-time testing and debugging.\n", + " - One-click deployment to production.\n", + "\n", + "- **AG2 MARKETPLACE**: \n", + " - Share and monetize agents.\n", + " - Discover pre-built solution templates.\n", + "\n", + "- **Scaling Tools**: \n", + " - Zero to production deployment guides.\n", + " - Usage analytics and cost optimization.\n", + " - Team collaboration features.\n", + "\n", + "---\n", + "\n", + "Whether you're a solo founder or an enterprise team, AG2 aims to make multi-agent development accessible for everyone. \n", + "\n", + "\n" + ] + } + ], + "source": [ + "print(chat_result.summary)" + ] } ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -216,7 +383,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.16" + "version": "3.11.10" } }, "nbformat": 4,