{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# How to transform inputs and outputs of a subgraph\n", "\n", "It's possible that your subgraph state is completely independent from the parent graph state, i.e. there are no overlapping channels (keys) between the two. For example, you might have a supervisor agent that needs to produce a report with a help of multiple ReAct agents. ReAct agent subgraphs might keep track of a list of messages whereas the supervisor only needs user input and final report in its state, and doesn't need to keep track of messages.\n", "\n", "In such cases you need to transform the inputs to the subgraph before calling it and then transform its outputs before returning. This guide shows how to do that.\n", "\n", "## Setup\n", "\n", "First, let's install the required packages\n", "\n", "```bash\n", "npm install @langchain/langgraph @langchain/core\n", "```\n", "\n", "
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", "Note
\n", "\n",
" We're wrapping the grandchildGraph
invocation in a separate function (callGrandchildGraph
) that transforms the input state before calling the grandchild graph and then transforms the output of grandchild graph back to child graph state. If you just pass grandchildGraph
directly to .addNode
without the transformations, LangGraph will raise an error as there are no shared state channels (keys) between child and grandchild states.\n",
"
Note
\n", "\n",
" We're wrapping the childGraph
invocation in a separate function (callChildGraph
) that transforms the input state before calling the child graph and then transforms the output of the child graph back to parent graph state. If you just pass childGraph
directly to .addNode
without the transformations, LangGraph will raise an error as there are no shared state channels (keys) between parent and child states.\n",
"