{ "cells": [ { "cell_type": "markdown", "id": "39fd1948-b5c3-48c4-b10e-2ae7e8c83334", "metadata": {}, "source": [ "# Basic Multi-agent Collaboration\n", "\n", "A single agent can usually operate effectively using a handful of tools within a single domain, but even using powerful models like `gpt-4`, it can be less effective at using many tools. \n", "\n", "One way to approach complicated tasks is through a \"divide-and-conquer\" approach: create an specialized agent for each task or domain and route tasks to the correct \"expert\".\n", "\n", "This notebook (inspired by the paper [AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation](https://arxiv.org/abs/2308.08155), by Wu, et. al.) shows one way to do this using LangGraph.\n", "\n", "The resulting graph will look something like the following diagram:\n", "\n", "\n", "\n", "Before we get started, a quick note: this and other multi-agent notebooks are designed to show _how_ you can implement certain design patterns in LangGraph. If the pattern suits your needs, we recommend combining it with some of the other fundamental patterns described elsewhere in the docs for best performance.\n", "\n", "## Setup\n", "\n", "First, let's install our required packages and set our API keys:" ] }, { "cell_type": "code", "execution_count": 1, "id": "0d7b6dcc-c985-46e2-8457-7e6b0298b950", "metadata": {}, "outputs": [], "source": [ "%%capture --no-stderr\n", "%pip install -U langchain langchain_openai langsmith pandas langchain_experimental matplotlib langgraph langchain_core" ] }, { "cell_type": "code", "execution_count": 2, "id": "743c19df-6da9-4d1e-b2d2-ea40080b9fdc", "metadata": {}, "outputs": [], "source": [ "import getpass\n", "import os\n", "\n", "\n", "def _set_if_undefined(var: str):\n", " if not os.environ.get(var):\n", " os.environ[var] = getpass.getpass(f\"Please provide your {var}\")\n", "\n", "\n", "_set_if_undefined(\"OPENAI_API_KEY\")\n", "_set_if_undefined(\"TAVILY_API_KEY\")" ] }, { "cell_type": "markdown", "id": "ab5cea6d", "metadata": {}, "source": [ "
Set up LangSmith for LangGraph development
\n", "\n", " Sign up for LangSmith to quickly spot issues and improve the performance of your LangGraph projects. LangSmith lets you use trace data to debug, test, and monitor your LLM apps built with LangGraph — read more about how to get started here. \n", "
\n", "