mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-12 12:47:53 +02:00
docs: update home page (#753)
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
|
||||
⚡ Building language agents as graphs ⚡
|
||||
|
||||
> [!NOTE]
|
||||
> Looking for the JS version? Click [here](https://github.com/langchain-ai/langgraphjs) ([JS docs](https://langchain-ai.github.io/langgraphjs/)).
|
||||
|
||||
## Overview
|
||||
|
||||
[LangGraph](https://langchain-ai.github.io/langgraph/) is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. Compared to other LLM frameworks, it offers these core benefits: cycles, controllability, and persistence. LangGraph allows you to define flows that involve cycles, essential for most agentic architectures, differentiating it from DAG-based solutions. As a very low-level framework, it provides fine-grained control over both the flow and state of your application, crucial for creating reliable agents. Additionally, LangGraph includes built-in persistence, enabling advanced human-in-the-loop and memory features.
|
||||
@@ -146,27 +149,31 @@ final_state["messages"][-1].content
|
||||
'The current weather in New York is as follows:\n- Temperature: 20.3°C (68.5°F)\n- Condition: Overcast\n- Wind: 2.2 mph from the north\n- Humidity: 65%\n- Cloud Cover: 100%\n- UV Index: 5.0\n\nFor more details, you can visit [Weather API](https://www.weatherapi.com/).'
|
||||
```
|
||||
|
||||
### Step-by-step Breakdown:
|
||||
### Step-by-step Breakdown
|
||||
|
||||
1. <details>
|
||||
<summary>Initialize the model and tools.</summary>
|
||||
|
||||
- we use `ChatOpenAI` as our LLM. **NOTE:** we need make sure the model knows that it has these tools available to call. We can do this by converting the LangChain tools into the format for OpenAI tool calling using the `.bind_tools()` method.
|
||||
- we define the tools we want to use -- a web search tool in our case. It is really easy to create your own tools - see documentation here on how to do that [here](https://python.langchain.com/docs/modules/agents/tools/custom_tools).
|
||||
- we define the tools we want to use - a web search tool in our case. It is really easy to create your own tools - see documentation here on how to do that [here](https://python.langchain.com/docs/modules/agents/tools/custom_tools).
|
||||
</details>
|
||||
|
||||
2. <details>
|
||||
<summary>Initialize graph with state.</summary>
|
||||
|
||||
- we initialize graph (`StateGraph`) by passing state schema (in our case `MessagesState`)
|
||||
- `MessagesState` is a prebuilt state schema that has one attribute -- a list of LangChain `Message` objects, as well as logic for merging the updates from each node into the state
|
||||
</details>
|
||||
|
||||
3. <details>
|
||||
<summary>Define graph nodes.</summary>
|
||||
|
||||
There are two main nodes we need:
|
||||
|
||||
- The `agent` node: responsible for deciding what (if any) actions to take.
|
||||
- The `tools` node that invokes tools: if the agent decides to take an action, this node will then execute that action.
|
||||
</details>
|
||||
|
||||
4. <details>
|
||||
<summary>Define entry point and graph edges.</summary>
|
||||
|
||||
@@ -179,12 +186,14 @@ final_state["messages"][-1].content
|
||||
- b. Finish (respond to the user) if the agent did not ask to run tools
|
||||
- Normal edge: after the tools are invoked, the graph should always return to the agent to decide what to do next
|
||||
</details>
|
||||
|
||||
5. <details>
|
||||
<summary>Compile the graph.</summary>
|
||||
|
||||
- When we compile the graph, we turn it into a LangChain [Runnable](https://python.langchain.com/v0.2/docs/concepts/#runnable-interface), which automatically enables calling `.invoke()`, `.stream()` and `.batch()` with your inputs
|
||||
- We can also optionally pass checkpointer object for persisting state between graph runs, and enabling memory, human-in-the-loop workflows, time travel and more. In our case we use `MemorySaver` - a simple in-memory checkpointer
|
||||
</details>
|
||||
|
||||
6. <details>
|
||||
<summary>Execute the graph.</summary>
|
||||
|
||||
@@ -192,8 +201,10 @@ final_state["messages"][-1].content
|
||||
2. The `"agent"` node executes, invoking the chat model.
|
||||
3. The chat model returns an `AIMessage`. LangGraph adds this to the state.
|
||||
4. Graph cycles the following steps until there are no more `tool_calls` on `AIMessage`:
|
||||
- If `AIMessage` has `tool_calls`, `"tools"` node executes
|
||||
- The `"agent"` node executes again and returns `AIMessage`
|
||||
|
||||
- If `AIMessage` has `tool_calls`, `"tools"` node executes
|
||||
- The `"agent"` node executes again and returns `AIMessage`
|
||||
|
||||
5. Execution progresses to the special `END` value and outputs the final state.
|
||||
And as a result, we get a list of all our chat messages as output.
|
||||
</details>
|
||||
|
||||
@@ -7,7 +7,7 @@ hide:
|
||||
|
||||
Welcome to the LangGraph how-to guides! These guides provide practical, step-by-step instructions for accomplishing key tasks in LangGraph.
|
||||
|
||||
## Core
|
||||
## Basics
|
||||
|
||||
The core guides show how to address common needs when building out AI workflows, with special focus placed on [ReAct](https://arxiv.org/abs/2210.03629)-style agents with [tool calling](https://python.langchain.com/docs/modules/model_io/chat/function_calling/) (agents that <strong>Re</strong>ason and **Act** to accomplish tasks).
|
||||
|
||||
|
||||
+2
-128
@@ -1,133 +1,7 @@
|
||||
---
|
||||
hide_comments: true
|
||||
hide:
|
||||
- toc
|
||||
- navigation
|
||||
---
|
||||
# 🦜🕸️LangGraph
|
||||
|
||||

|
||||
[](https://pepy.tech/project/langgraph)
|
||||
[](https://github.com/langchain-ai/langgraph/issues)
|
||||
[](https://discord.com/channels/1038097195422978059/1170024642245832774)
|
||||
|
||||
|
||||
⚡ Build language agents as graphs ⚡
|
||||
|
||||
!!! note "Python version :material-language-python:"
|
||||
|
||||
Looking for the JS version? Click [:fontawesome-brands-square-js: here](https://github.com/langchain-ai/langgraphjs) ([:simple-readme: JS docs](https://langchain-ai.github.io/langgraphjs/)).
|
||||
|
||||
## Overview
|
||||
|
||||
Suppose you're building a customer support assistant. You want your assistant to be able to:
|
||||
|
||||
1. Use tools to respond to questions
|
||||
2. Connect with a human if needed
|
||||
3. Be able to pause the process indefinitely and resume whenever the human responds
|
||||
|
||||
LangGraph makes this all easy. First install:
|
||||
|
||||
```bash
|
||||
pip install -U langgraph
|
||||
```
|
||||
|
||||
Then define your assistant:
|
||||
|
||||
```python
|
||||
import json
|
||||
|
||||
from langchain_anthropic import ChatAnthropic
|
||||
from langchain_community.tools.tavily_search import TavilySearchResults
|
||||
|
||||
from langgraph.checkpoint.sqlite import SqliteSaver
|
||||
from langgraph.graph import END, MessageGraph
|
||||
from langgraph.prebuilt.tool_node import ToolNode
|
||||
|
||||
|
||||
# Define the function that determines whether to continue or not
|
||||
def should_continue(messages):
|
||||
last_message = messages[-1]
|
||||
# If there is no function call, then we finish
|
||||
if not last_message.tool_calls:
|
||||
return END
|
||||
else:
|
||||
return "action"
|
||||
|
||||
|
||||
# Define a new graph
|
||||
workflow = MessageGraph()
|
||||
|
||||
tools = [TavilySearchResults(max_results=1)]
|
||||
model = ChatAnthropic(model="claude-3-haiku-20240307").bind_tools(tools)
|
||||
workflow.add_node("agent", model)
|
||||
workflow.add_node("action", ToolNode(tools))
|
||||
|
||||
workflow.set_entry_point("agent")
|
||||
|
||||
# Conditional agent -> action OR agent -> END
|
||||
workflow.add_conditional_edges(
|
||||
"agent",
|
||||
should_continue,
|
||||
)
|
||||
|
||||
# Always transition `action` -> `agent`
|
||||
workflow.add_edge("action", "agent")
|
||||
|
||||
memory = SqliteSaver.from_conn_string(":memory:") # Here we only save in-memory
|
||||
|
||||
# Setting the interrupt means that any time an action is called, the machine will stop
|
||||
app = workflow.compile(checkpointer=memory, interrupt_before=["action"])
|
||||
```
|
||||
|
||||
Now, run the graph:
|
||||
|
||||
```python
|
||||
# Run the graph
|
||||
thread = {"configurable": {"thread_id": "4"}}
|
||||
for event in app.stream("what is the weather in sf currently", thread, stream_mode="values"):
|
||||
event[-1].pretty_print()
|
||||
|
||||
```
|
||||
We configured the graph to **wait** before executing the `action`. The `SqliteSaver` persists the state. Resume at any time.
|
||||
|
||||
```python
|
||||
for event in app.stream(None, thread, stream_mode="values"):
|
||||
event[-1].pretty_print()
|
||||
```
|
||||
|
||||
The graph orchestrates everything:
|
||||
|
||||
- The `MessageGraph` contains the agent's "Memory"
|
||||
- Conditional edges enable dynamic routing between the chatbot, tools, and the user
|
||||
- Persistence makes it easy to stop, resume, and even rewind for full control over your application
|
||||
|
||||
With LangGraph, you can build complex, stateful agents without getting bogged down in manual state and interrupt management. Just define your nodes, edges, and state schema - and let the graph take care of the rest.
|
||||
|
||||
|
||||
## Tutorials
|
||||
|
||||
Consult the [Tutorials](tutorials/index.md) to learn more about building with LangGraph, including advanced use cases.
|
||||
|
||||
|
||||
## How-To Guides
|
||||
|
||||
Check out the [How-To Guides](how-tos/index.md) for instructions on handling common tasks with LangGraph
|
||||
|
||||
## Reference
|
||||
|
||||
For documentation on the core APIs, check out the [Reference](reference/graphs.md) docs.
|
||||
|
||||
## Conceptual Guides
|
||||
|
||||
Once you've learned the basics, if you want to further understand LangGraph's core abstractions, check out the [Conceptual Guides](./concepts/index.md).
|
||||
|
||||
## Why LangGraph?
|
||||
|
||||
LangGraph is framework agnostic (each node is a regular python function). It extends the core Runnable API (shared interface for streaming, async, and batch calls) to make it easy to:
|
||||
|
||||
- Seamless state management across multiple turns of conversation or tool usage
|
||||
- The ability to flexibly route between nodes based on dynamic criteria
|
||||
- Smooth switching between LLMs and human intervention
|
||||
- Persistence for long-running, multi-session applications
|
||||
|
||||
If you're building a straightforward DAG, Runnables are a great fit. But for more complex, stateful applications with nonlinear flows, LangGraph is the perfect tool for the job.
|
||||
{!README.md!}
|
||||
+4
-3
@@ -91,8 +91,6 @@ plugins:
|
||||
nav:
|
||||
- Home:
|
||||
- 'index.md'
|
||||
- Quick Start: how-tos/docs/quickstart.ipynb
|
||||
- Intro to LangGraph: tutorials/introduction.ipynb
|
||||
- Tutorials:
|
||||
- 'tutorials/index.md'
|
||||
- Introduction: tutorials/introduction.ipynb
|
||||
@@ -135,7 +133,7 @@ nav:
|
||||
|
||||
- "How-to Guides":
|
||||
- 'how-tos/index.md'
|
||||
- Core:
|
||||
- Basics:
|
||||
- Create a ReAct agent: how-tos/create-react-agent.ipynb
|
||||
- Add persistence ("memory"): how-tos/persistence.ipynb
|
||||
- View and update graph state: how-tos/time-travel.ipynb
|
||||
@@ -243,6 +241,9 @@ markdown_extensions:
|
||||
combine_header_slug: true
|
||||
- pymdownx.tasklist:
|
||||
custom_checkbox: true
|
||||
- markdown_include.include:
|
||||
base_path: ./
|
||||
- github-callouts
|
||||
extra_css:
|
||||
- css/mkdocstrings.css
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
⚡ Building language agents as graphs ⚡
|
||||
|
||||
> [!NOTE]
|
||||
> Looking for the JS version? Click [here](https://github.com/langchain-ai/langgraphjs) ([JS docs](https://langchain-ai.github.io/langgraphjs/)).
|
||||
|
||||
## Overview
|
||||
|
||||
[LangGraph](https://langchain-ai.github.io/langgraph/) is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. Compared to other LLM frameworks, it offers these core benefits: cycles, controllability, and persistence. LangGraph allows you to define flows that involve cycles, essential for most agentic architectures, differentiating it from DAG-based solutions. As a very low-level framework, it provides fine-grained control over both the flow and state of your application, crucial for creating reliable agents. Additionally, LangGraph includes built-in persistence, enabling advanced human-in-the-loop and memory features.
|
||||
@@ -146,27 +149,31 @@ final_state["messages"][-1].content
|
||||
'The current weather in New York is as follows:\n- Temperature: 20.3°C (68.5°F)\n- Condition: Overcast\n- Wind: 2.2 mph from the north\n- Humidity: 65%\n- Cloud Cover: 100%\n- UV Index: 5.0\n\nFor more details, you can visit [Weather API](https://www.weatherapi.com/).'
|
||||
```
|
||||
|
||||
### Step-by-step Breakdown:
|
||||
### Step-by-step Breakdown
|
||||
|
||||
1. <details>
|
||||
<summary>Initialize the model and tools.</summary>
|
||||
|
||||
- we use `ChatOpenAI` as our LLM. **NOTE:** we need make sure the model knows that it has these tools available to call. We can do this by converting the LangChain tools into the format for OpenAI tool calling using the `.bind_tools()` method.
|
||||
- we define the tools we want to use -- a web search tool in our case. It is really easy to create your own tools - see documentation here on how to do that [here](https://python.langchain.com/docs/modules/agents/tools/custom_tools).
|
||||
- we define the tools we want to use - a web search tool in our case. It is really easy to create your own tools - see documentation here on how to do that [here](https://python.langchain.com/docs/modules/agents/tools/custom_tools).
|
||||
</details>
|
||||
|
||||
2. <details>
|
||||
<summary>Initialize graph with state.</summary>
|
||||
|
||||
- we initialize graph (`StateGraph`) by passing state schema (in our case `MessagesState`)
|
||||
- `MessagesState` is a prebuilt state schema that has one attribute -- a list of LangChain `Message` objects, as well as logic for merging the updates from each node into the state
|
||||
</details>
|
||||
|
||||
3. <details>
|
||||
<summary>Define graph nodes.</summary>
|
||||
|
||||
There are two main nodes we need:
|
||||
|
||||
- The `agent` node: responsible for deciding what (if any) actions to take.
|
||||
- The `tools` node that invokes tools: if the agent decides to take an action, this node will then execute that action.
|
||||
</details>
|
||||
|
||||
4. <details>
|
||||
<summary>Define entry point and graph edges.</summary>
|
||||
|
||||
@@ -179,12 +186,14 @@ final_state["messages"][-1].content
|
||||
- b. Finish (respond to the user) if the agent did not ask to run tools
|
||||
- Normal edge: after the tools are invoked, the graph should always return to the agent to decide what to do next
|
||||
</details>
|
||||
|
||||
5. <details>
|
||||
<summary>Compile the graph.</summary>
|
||||
|
||||
- When we compile the graph, we turn it into a LangChain [Runnable](https://python.langchain.com/v0.2/docs/concepts/#runnable-interface), which automatically enables calling `.invoke()`, `.stream()` and `.batch()` with your inputs
|
||||
- We can also optionally pass checkpointer object for persisting state between graph runs, and enabling memory, human-in-the-loop workflows, time travel and more. In our case we use `MemorySaver` - a simple in-memory checkpointer
|
||||
</details>
|
||||
|
||||
6. <details>
|
||||
<summary>Execute the graph.</summary>
|
||||
|
||||
@@ -192,8 +201,10 @@ final_state["messages"][-1].content
|
||||
2. The `"agent"` node executes, invoking the chat model.
|
||||
3. The chat model returns an `AIMessage`. LangGraph adds this to the state.
|
||||
4. Graph cycles the following steps until there are no more `tool_calls` on `AIMessage`:
|
||||
- If `AIMessage` has `tool_calls`, `"tools"` node executes
|
||||
- The `"agent"` node executes again and returns `AIMessage`
|
||||
|
||||
- If `AIMessage` has `tool_calls`, `"tools"` node executes
|
||||
- The `"agent"` node executes again and returns `AIMessage`
|
||||
|
||||
5. Execution progresses to the special `END` value and outputs the final state.
|
||||
And as a result, we get a list of all our chat messages as output.
|
||||
</details>
|
||||
|
||||
Generated
+34
-3
@@ -857,8 +857,8 @@ tenacity = ">=8.1.0,<9.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "langgraph"
|
||||
version = "0.0.69"
|
||||
description = "langgraph"
|
||||
version = "0.1.0"
|
||||
description = "Building stateful, multi-actor applications with LLMs"
|
||||
optional = false
|
||||
python-versions = ">=3.9.0,<4.0"
|
||||
files = []
|
||||
@@ -902,6 +902,37 @@ files = [
|
||||
docs = ["mdx-gh-links (>=0.2)", "mkdocs (>=1.5)", "mkdocs-gen-files", "mkdocs-literate-nav", "mkdocs-nature (>=0.6)", "mkdocs-section-index", "mkdocstrings[python]"]
|
||||
testing = ["coverage", "pyyaml"]
|
||||
|
||||
[[package]]
|
||||
name = "markdown-callouts"
|
||||
version = "0.4.0"
|
||||
description = "Markdown extension: a classier syntax for admonitions"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "markdown_callouts-0.4.0-py3-none-any.whl", hash = "sha256:ed0da38f29158d93116a0d0c6ecaf9df90b37e0d989b5337d678ee6e6d6550b7"},
|
||||
{file = "markdown_callouts-0.4.0.tar.gz", hash = "sha256:7ed2c90486967058a73a547781121983839522d67041ae52c4979616f1b2b746"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
markdown = ">=3.3.3"
|
||||
|
||||
[[package]]
|
||||
name = "markdown-include"
|
||||
version = "0.8.1"
|
||||
description = "A Python-Markdown extension which provides an 'include' function"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "markdown-include-0.8.1.tar.gz", hash = "sha256:1d0623e0fc2757c38d35df53752768356162284259d259c486b4ab6285cdbbe3"},
|
||||
{file = "markdown_include-0.8.1-py3-none-any.whl", hash = "sha256:32f0635b9cfef46997b307e2430022852529f7a5b87c0075c504283e7cc7db53"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
markdown = ">=3.0"
|
||||
|
||||
[package.extras]
|
||||
tests = ["pytest"]
|
||||
|
||||
[[package]]
|
||||
name = "markdown-it-py"
|
||||
version = "3.0.0"
|
||||
@@ -2520,4 +2551,4 @@ files = [
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "ce6ddcd0789cddc6c5e87f399754e6d8fc776df9b1b5419fe6a3a20faa5ea4a4"
|
||||
content-hash = "5369acbf95b74ea9627f263672e460e3227383108ff0cb08d99e7af1c18f95a9"
|
||||
|
||||
@@ -20,6 +20,8 @@ mkdocs-minify-plugin = "^0.8.0"
|
||||
mkdocs-rss-plugin = "^1.13.1"
|
||||
mkdocs-git-committers-plugin-2 = "^2.3.0"
|
||||
mkdocs-material = {extras = ["imaging"], version = "^9.5.27"}
|
||||
markdown-include = "^0.8.1"
|
||||
markdown-callouts = "^0.4.0"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
|
||||
Reference in New Issue
Block a user