Skip to content

Commit

Permalink
Merge branch 'main' into wfh/store_ref_docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Oct 2, 2024
2 parents 9053cf2 + d683630 commit 0373537
Show file tree
Hide file tree
Showing 32 changed files with 1,646 additions and 1,041 deletions.
4 changes: 2 additions & 2 deletions docs/docs/how-tos/async.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
" </a>\n",
" </li>\n",
" <li>\n",
" <a href=\"https://langchain-ai.github.io/langgraph/concepts/high_level/\">\n",
" LangGraph Concepts\n",
" <a href=\"https://langchain-ai.github.io/langgraph/concepts/low_level/\">\n",
" LangGraph Glossary\n",
" </a>\n",
" </li>\n",
" <li>\n",
Expand Down
15 changes: 12 additions & 3 deletions docs/docs/how-tos/branching.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@
" This guide assumes familiarity with the following:\n",
" <ul>\n",
" <li>\n",
" <a href=\"https://langchain-ai.github.io/langgraph/concepts/high_level/\">\n",
" LangGraph Concepts\n",
" <a href=\"https://langchain-ai.github.io/langgraph/concepts/low_level/#nodes\">\n",
" Node\n",
" </a>\n",
" </li>\n",
" <li>\n",
" <a href=\"https://langchain-ai.github.io/langgraph/concepts/low_level/#edges\">\n",
" Edge\n",
" </a>\n",
" </li> \n",
" <li>\n",
" <a href=\"https://langchain-ai.github.io/langgraph/concepts/low_level/#reducers\">\n",
" Reducer\n",
" </a>\n",
" </li>\n",
" </ul>\n",
" </p>\n",
"</div> \n",
"\n",
"\n",
"Parallel execution of nodes is essential to speed up overall graph operation. LangGraph offers native support for parallel execution of nodes, which can significantly enhance the performance of graph-based workflows. This parallelization is achieved through fan-out and fan-in mechanisms, utilizing both standard edges and [conditional_edges](https://langchain-ai.github.io/langgraph/reference/graphs/#langgraph.graph.MessageGraph.add_conditional_edges). Below are some examples showing how to add create branching dataflows that work for you. \n",
"\n",
"![Screenshot 2024-07-09 at 2.55.56 PM.png](attachment:51f122de-b2ce-4c21-a5a7-c3be70c28a91.png)"
Expand Down
101 changes: 36 additions & 65 deletions docs/docs/how-tos/disable-streaming.ipynb

Large diffs are not rendered by default.

63 changes: 43 additions & 20 deletions docs/docs/how-tos/input_output_schema.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,30 @@
"source": [
"# How to define input/output schema for your graph\n",
"\n",
"By default, `StateGraph` takes in a single schema and all nodes are expected to communicate with that schema. However, it is also possible to define explicit input and output schemas for a graph. Often, in these cases, we define an \"internal\" schema that contains all keys relevant to graph operations. But, we use specific input and output schemas to filter what's permitted when invoking and what's returned. We use type hints below to, for example, show that the output of `answer_node` will be filtered to `OutputState`. In addition, we define each node's input schema (e.g., as state: `OverallState` for `answer_node`).\n",
"<div class=\"admonition tip\">\n",
" <p class=\"admonition-title\">Prerequisites</p>\n",
" <p>\n",
" This guide assumes familiarity with the following:\n",
" <ul>\n",
" <li>\n",
" <a href=\"https://langchain-ai.github.io/langgraph/concepts/low_level/#multiple-schemas\">\n",
" Multiple Schemas\n",
" </a>\n",
" </li>\n",
" <li>\n",
" <a href=\"https://langchain-ai.github.io/langgraph/concepts/low_level/#stategraph\">\n",
" State Graph\n",
" </a> \n",
" </li> \n",
" </ul>\n",
" </p>\n",
"</div> \n",
"\n",
"By default, `StateGraph` operates with a single schema, and all nodes are expected to communicate using that schema. However, it's also possible to define distinct input and output schemas for a graph.\n",
"\n",
"In this notebook we'll walk through an example of this. At a high level, in order to do this you simply have to pass in `input=..., output=...` when defining the graph. See the conceptual docs [here](https://langchain-ai.github.io/langgraph/concepts/low_level/#multiple-schemas) for more details.\n",
"When distinct schemas are specified, an internal schema will still be used for communication between nodes. The input schema ensures that the provided input matches the expected structure, while the output schema filters the internal data to return only the relevant information according to the defined output schema.\n",
"\n",
"Let's look at an example!\n",
"In this example, we'll see how to define distinct input and output schema.\n",
"\n",
"## Setup\n",
"\n",
Expand All @@ -20,7 +39,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "678286f2",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -52,49 +71,53 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "6ec0eb77-874e-443e-8c73-93125b515106",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'answer': 'bye'}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"{'answer': 'bye'}\n"
]
}
],
"source": [
"from langgraph.graph import StateGraph, START, END\n",
"from typing_extensions import TypedDict\n",
"\n",
"\n",
"# Define the schema for the input\n",
"class InputState(TypedDict):\n",
" question: str\n",
"\n",
"\n",
"# Define the schema for the output\n",
"class OutputState(TypedDict):\n",
" answer: str\n",
"\n",
"\n",
"# Define the overall schema, combining both input and output\n",
"class OverallState(InputState, OutputState):\n",
" pass\n",
"\n",
"\n",
"# Define the node that processes the input and generates an answer\n",
"def answer_node(state: InputState):\n",
" return {\"answer\": \"bye\"}\n",
" # Example answer and an extra key\n",
" return {\"answer\": \"bye\", \"question\": state[\"question\"]}\n",
"\n",
"\n",
"# Build the graph with input and output schemas specified\n",
"builder = StateGraph(OverallState, input=InputState, output=OutputState)\n",
"builder.add_node(answer_node)\n",
"builder.add_edge(START, \"answer_node\")\n",
"builder.add_edge(\"answer_node\", END)\n",
"graph = builder.compile()\n",
"builder.add_node(answer_node) # Add the answer node\n",
"builder.add_edge(START, \"answer_node\") # Define the starting edge\n",
"builder.add_edge(\"answer_node\", END) # Define the ending edge\n",
"graph = builder.compile() # Compile the graph\n",
"\n",
"graph.invoke({\"question\": \"hi\"})"
"# Invoke the graph with an input and print the result\n",
"print(graph.invoke({\"question\": \"hi\"}))"
]
},
{
Expand Down Expand Up @@ -122,7 +145,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 0373537

Please sign in to comment.