This commit is contained in:
William Fu-Hinthorn
2024-01-18 15:58:54 -08:00
parent ef662ae849
commit 48e635b9f3
3 changed files with 34 additions and 20 deletions
@@ -5,9 +5,9 @@
"id": "a3e3ebc4-57af-4fe4-bdd3-36aff67bf276",
"metadata": {},
"source": [
"## Multi-agent Example 3: Agent Team Supervisor\n",
"## Agent Supervisor\n",
"\n",
"The previous example routed messages automatically based on the output of the initial researcher agent.\n",
"The [previous example](multi-agent-collaboration.ipynb) routed messages automatically based on the output of the initial researcher agent.\n",
"\n",
"We can also choose to use an LLM to orchestrate the different agents.\n",
"\n",
@@ -15,7 +15,7 @@
"\n",
"![diagram](./img/supervisor-diagram.png)\n",
"\n",
"To simplify each agent node, we will use the AgentExecutor class from LangChain."
"To simplify the code in each agent node, we will use the AgentExecutor class from LangChain. This and other \"advanced 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."
]
},
{
@@ -5,7 +5,7 @@
"id": "a3e3ebc4-57af-4fe4-bdd3-36aff67bf276",
"metadata": {},
"source": [
"## Agent Teams\n",
"## Hierarchical Agent Teams\n",
"\n",
"In our previous example ([Agent Supervisor](./agent_supervisor.ipynb)), we introduced the concept of a single supervisor node to route work between different worker nodes.\n",
"\n",
@@ -21,7 +21,6 @@
"![diagram](./img/hierarchical-diagram.png)\n",
"\n",
"\n",
"\n",
"In the rest of this notebook, you will:\n",
"1. Define some utilities to help create the graph and their relations\n",
"2. Write the tools and agent implementations for each team\n",
@@ -62,7 +61,7 @@
"_set_if_undefined(\"LANGCHAIN_API_KEY\")\n",
"_set_if_undefined(\"TAVILY_API_KEY\")\n",
"\n",
"# Optional, add tracing in LangSmith. \n",
"# Optional, add tracing in LangSmith.\n",
"# This will help you visualize and debug the control flow\n",
"os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n",
"os.environ[\"LANGCHAIN_PROJECT\"] = \"Multi-agent Collaboration\""
@@ -5,11 +5,13 @@
"id": "39fd1948-b5c3-48c4-b10e-2ae7e8c83334",
"metadata": {},
"source": [
"# Multi-agent Collaboration Intro\n",
"# Basic Multi-agent Collaboration\n",
"\n",
"A single agent can usually operate effectively using a handful of tools and a scoped domain, but even using powerful models like `gpt-4`, it can be less effective at using many tools. One way to improve your system's performance is through multi-agent collaboration. Each agent can specialize in a task or domain, and LangGraph can effectively orchestrate them to accomplish a larger goal. \n",
"\n",
"This notebook is inspired by the paper [AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation](https://arxiv.org/abs/2308.08155), by Wu, et. al."
"This notebook is inspired by the paper [AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation](https://arxiv.org/abs/2308.08155), by Wu, et. al.\n",
"\n",
"This and other \"advanced 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."
]
},
{
@@ -52,7 +54,7 @@
"id": "7d5fc0f3-5d9e-4e72-a281-177f101c2a7d",
"metadata": {},
"source": [
"## Example 1: 2 Agents\n",
"## Create tool\n",
"\n",
"Below is an example of 2 agents collaborating to accomplish a single task."
]
@@ -117,10 +119,20 @@
" return fig, ax"
]
},
{
"cell_type": "markdown",
"id": "5e4344a7-21df-4d54-90d2-9d19b3416ffb",
"metadata": {},
"source": [
"## Create the graph\n",
"\n",
"We will create the individual agents below and place them within the graph."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b0ca7d80-31e4-4394-bfce-ffac314bac7d",
"id": "4dce3901-6ad5-4df5-8528-6e865cf96cb0",
"metadata": {},
"outputs": [],
"source": [
@@ -147,16 +159,9 @@
"\n",
"class AgentState(TypedDict):\n",
" messages: Annotated[Sequence[BaseMessage], operator.add]\n",
" sender: str"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4dce3901-6ad5-4df5-8528-6e865cf96cb0",
"metadata": {},
"outputs": [],
"source": [
" sender: str\n",
"\n",
"\n",
"workflow = StateGraph(AgentState)\n",
"\n",
"# This a helper class we have that is useful for running tools\n",
@@ -260,6 +265,16 @@
"graph = workflow.compile()"
]
},
{
"cell_type": "markdown",
"id": "8c9447e7-9ab6-43eb-8ae6-9b52f8ba8425",
"metadata": {},
"source": [
"## Invoke\n",
"\n",
"With the graph created, you can invoke it!"
]
},
{
"cell_type": "code",
"execution_count": null,