Update readme

This commit is contained in:
William Fu-Hinthorn
2024-02-12 14:53:41 -08:00
parent ac131cc954
commit 1307ce9cc7
2 changed files with 43 additions and 21 deletions
+26 -12
View File
@@ -454,18 +454,6 @@ We also have a lot of examples highlighting how to slightly modify the base chat
- [Force calling a tool first](https://github.com/langchain-ai/langgraph/blob/main/examples/agent_executor/force-calling-a-tool-first.ipynb): How to always call a specific tool first
- [Managing agent steps](https://github.com/langchain-ai/langgraph/blob/main/examples/agent_executor/managing-agent-steps.ipynb): How to more explicitly manage intermediate steps that an agent takes
### Multi-agent Examples
- [Multi-agent collaboration](https://github.com/langchain-ai/langgraph/blob/main/examples/multi_agent/multi-agent-collaboration.ipynb): how to create two agents that work together to accomplish a task
- [Multi-agent with supervisor](https://github.com/langchain-ai/langgraph/blob/main/examples/multi_agent/agent_supervisor.ipynb): how to orchestrate individual agents by using an LLM as a "supervisor" to distribute work
- [Hierarchical agent teams](https://github.com/langchain-ai/langgraph/blob/main/examples/multi_agent/hierarchical_agent_teams.ipynb): how to orchestrate "teams" of agents as nested graphs that can collaborate to solve a problem
### Chatbot Evaluation via Simulation
It can often be tough to evaluation chat bots in multi-turn situations. One way to do this is with simulations.
- [Chat bot evaluation as multi-agent simulation](https://github.com/langchain-ai/langgraph/blob/main/examples/chatbot-simulation-evaluation/agent-simulation-evaluation.ipynb): How to simulate a dialogue between a "virtual user" and your chat bot
### Async
If you are running LangGraph in async workflows, you may want to create the nodes to be async by default.
@@ -486,6 +474,32 @@ For a walkthrough on how to do that, see [this documentation](https://github.com
LangGraph comes with built-in support for human-in-the-loop workflows. This is useful when you want to have a human review the current state before proceeding to a particular node.
For a walkthrough on how to do that, see [this documentation](https://github.com/langchain-ai/langgraph/blob/main/examples/human-in-the-loop.ipynb)
### Planning Agent Examples
The following notebooks implement agent architectures prototypical of the "plan-and-execute" style, where an LLM planner decomposes a user request into a program, an executor executes the program, and an LLM synthesizes a response (and/or dynamically replans) based on the program outputs.
- [Plan-and-execute](https://github.com/langchain-ai/langgraph/blob/main/examples/plan-and-execute/plan-and-execute.ipynb): a simple agent with a **planner** that generates a multi-step task list, an **executor** that invokes the tools in the plan, and a **replanner** that responds or generates an updated plan
- [Reasoning without Observation](https://github.com/langchain-ai/langgraph/blob/main/examples/rewoo/rewoo.ipynb): planner generates a task list whose observations are saved as **variables**. Variables can be used in subsequent tasks to reduce the need for further re-planning
- [LLMCompiler](https://github.com/langchain-ai/langgraph/blob/main/examples/llm-compiler/LLMCompiler.ipynb): planner generates a **DAG** of tasks with variable responses. Tasks are **streamed** and executed eagerly to minimize tool execution runtime.
### Multi-agent Examples
- [Multi-agent collaboration](https://github.com/langchain-ai/langgraph/blob/main/examples/multi_agent/multi-agent-collaboration.ipynb): how to create two agents that work together to accomplish a task
- [Multi-agent with supervisor](https://github.com/langchain-ai/langgraph/blob/main/examples/multi_agent/agent_supervisor.ipynb): how to orchestrate individual agents by using an LLM as a "supervisor" to distribute work
- [Hierarchical agent teams](https://github.com/langchain-ai/langgraph/blob/main/examples/multi_agent/hierarchical_agent_teams.ipynb): how to orchestrate "teams" of agents as nested graphs that can collaborate to solve a problem
### Chatbot Evaluation via Simulation
It can often be tough to evaluation chat bots in multi-turn situations. One way to do this is with simulations.
- [Chat bot evaluation as multi-agent simulation](https://github.com/langchain-ai/langgraph/blob/main/examples/chatbot-simulation-evaluation/agent-simulation-evaluation.ipynb): how to simulate a dialogue between a "virtual user" and your chat bot
### Multimodal Examples
- [WebVoyager](https://github.com/langchain-ai/langgraph/blob/main/examples/web-navigation/web_voyager.ipynb): vision-enabled web browsing agent that uses [Set-of-marks](https://som-gpt4v.github.io/) prompting to navigate a web browser and execute tasks
## Documentation
There are only a few new APIs to use.
+17 -9
View File
@@ -5,7 +5,7 @@
"id": "1c161710-fc66-426f-8c96-28440b9c9626",
"metadata": {},
"source": [
"# Reasoning Without Observation\n",
"# Reasoning without Observation\n",
"\n",
"In [ReWOO](https://arxiv.org/abs/2305.18323), Xu, et. al, propose an agent that combines a multi-step planner and variable substitution for effective tool use. It was designed to improve on the ReACT-style agent architecture in the following ways:\n",
"\n",
@@ -59,15 +59,16 @@
"import os\n",
"import getpass\n",
"\n",
"\n",
"def _set_if_undefined(var: str):\n",
" if not os.environ.get(var):\n",
" os.environ[var] = getpass.getpass(f\"{var}=\")\n",
"\n",
"\n",
"os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n",
"os.environ[\"LANGCHAIN_PROJECT\"] = \"ReWOO\"\n",
"_set_if_undefined(\"TAVILY_API_KEY\")\n",
"_set_if_undefined(\"LANGCHAIN_API_KEY\")\n",
"os.environ['LANGCHAIN_API_KEY'] = \"ls__2d5a3fe2b3af4f4db79501c906e1c072\"\n",
"_set_if_undefined(\"OPENAI_API_KEY\")"
]
},
@@ -89,6 +90,8 @@
"outputs": [],
"source": [
"from typing import TypedDict, List\n",
"\n",
"\n",
"class ReWOO(TypedDict):\n",
" task: str\n",
" plan_string: str\n",
@@ -229,10 +232,12 @@
"source": [
"import re\n",
"from langchain_core.prompts import ChatPromptTemplate\n",
"\n",
"# Regex to match expressions of the form E#... = ...[...]\n",
"regex_pattern = r\"Plan:\\s*(.+)\\s*(#E\\d+)\\s*=\\s*(\\w+)\\s*\\[([^\\]]+)\\]\"\n",
"prompt_template = ChatPromptTemplate.from_messages([(\"user\", prompt)]) \n",
"planner = prompt_template| model\n",
"prompt_template = ChatPromptTemplate.from_messages([(\"user\", prompt)])\n",
"planner = prompt_template | model\n",
"\n",
"\n",
"def get_plan(state: ReWOO):\n",
" task = state[\"task\"]\n",
@@ -262,6 +267,7 @@
"outputs": [],
"source": [
"from langchain_community.tools.tavily_search import TavilySearchResults\n",
"\n",
"search = TavilySearchResults()"
]
},
@@ -279,15 +285,16 @@
" return None\n",
" else:\n",
" return len(state[\"results\"]) + 1\n",
" \n",
"\n",
"\n",
"def tool_execution(state: ReWOO):\n",
" \"\"\"Worker node that executes the tools of a given plan.\"\"\"\n",
" _step =_get_current_task(state)\n",
" _step = _get_current_task(state)\n",
" _, step_name, tool, tool_input = state[\"steps\"][_step - 1]\n",
" _results = state[\"results\"] or {}\n",
" for k, v in _results.items():\n",
" tool_input = tool_input.replace(k, v)\n",
" if tool == \"Google\":\n",
" if tool == \"Google\":\n",
" result = search.invoke(tool_input)\n",
" elif tool == \"LLM\":\n",
" result = model.invoke(tool_input)\n",
@@ -326,6 +333,7 @@
"Task: {task}\n",
"Response:\"\"\"\n",
"\n",
"\n",
"def solve(state: ReWOO):\n",
" plan = \"\"\n",
" for _plan, step_name, tool, tool_input in state[\"steps\"]:\n",
@@ -414,9 +422,9 @@
}
],
"source": [
"for s in app.stream({\"task\":task}):\n",
"for s in app.stream({\"task\": task}):\n",
" print(s)\n",
" print('---')"
" print(\"---\")"
]
},
{