{ "cells": [ { "cell_type": "markdown", "id": "0c8b472b-f3fb-46c2-841f-930a4692697b", "metadata": {}, "source": [ "# LLMCompiler\n", "\n", "This notebook shows how to implement [LLMCompiler, by Kim, et. al](https://arxiv.org/abs/2312.04511) in LangGraph.\n", "\n", "LLMCompiler is an agent architecture designed to **speed up** the execution of agentic tasks by eagerly-executed tasks within a DAG. It also saves costs on redundant token usage by reducing the number of calls to the LLM. Below is an overview of its computational graph:\n", "\n", "\n", "\n", "It has 3 main components:\n", "\n", "1. Planner: stream a DAG of tasks.\n", "2. Task Fetching Unit: schedules and executes the tasks as soon as they are executable\n", "3. Joiner: Responds to the user or triggers a second plan\n", "\n", "\n", "This notebook walks through each component and shows how to wire them together using LangGraph. The end result will leave a trace [like the following](https://smith.langchain.com/public/218c2677-c719-4147-b0e9-7bc3b5bb2623/r).\n", "\n", "\n", "## Setup\n", "\n", "First, let's install the required packages and set our API keys" ] }, { "cell_type": "code", "execution_count": 1, "id": "16bd5497-35ad-44f2-94d9-19ff39a5ffed", "metadata": {}, "outputs": [], "source": [ "%%capture --no-stderr\n", "%pip install -U --quiet langchain_openai langsmith langgraph langchain numexpr" ] }, { "cell_type": "code", "execution_count": 2, "id": "abbd6948-e9a3-47ca-89c7-7ac2fc5eca8b", "metadata": {}, "outputs": [], "source": [ "import getpass\n", "import os\n", "\n", "\n", "def _get_pass(var: str):\n", " if var not in os.environ:\n", " os.environ[var] = getpass.getpass(f\"{var}: \")\n", "\n", "\n", "_get_pass(\"OPENAI_API_KEY\")" ] }, { "cell_type": "markdown", "id": "d499dad8", "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", "