[PR #940] [CLOSED] feat: support using add_node as a decorator #1785

Closed
opened 2026-02-20 17:45:33 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraph/pull/940
Author: @Ahmad-Alsaleh
Created: 7/7/2024
Status: Closed

Base: mainHead: add_node


📝 Commits (3)

  • 5933c14 feat: support using add_node as a decorator
  • 9f04f2e docs: change add_node.__doc__ in state.py
  • 6d78d99 Merge branch 'main' into add_node

📊 Changes

2 files changed (+53 additions, -28 deletions)

View changed files

📝 libs/langgraph/langgraph/graph/graph.py (+26 -16)
📝 libs/langgraph/langgraph/graph/state.py (+27 -12)

📄 Description

This pull request adds support for using the add_node method as a decorator in the StateGraph class. Previously, the method could only be used to add nodes by passing the node name and action as arguments. With this change, developers can now use the add_node method as a decorator to define nodes directly within the class definition. This provides a more concise and intuitive way to add nodes to the state graph.

Examples:

graph = Graph(...)

# All of the following are supported

@graph.add_node("search node")
def search():
    pass

# Uses search.__name__ as the name of the node

@graph.add_node()
def search():
    pass

@graph.add_node
def search():
    pass

The default behavior is still supported as well

def search():
    pass

graph.add_node(search)

graph.add_node("search tool", search)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langgraph/pull/940 **Author:** [@Ahmad-Alsaleh](https://github.com/Ahmad-Alsaleh) **Created:** 7/7/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `add_node` --- ### 📝 Commits (3) - [`5933c14`](https://github.com/langchain-ai/langgraph/commit/5933c14a5064e4b21cccb1fe85bc26956934958c) feat: support using `add_node` as a decorator - [`9f04f2e`](https://github.com/langchain-ai/langgraph/commit/9f04f2ed78d7908076c28a69ff8220c9dc0f0a5c) docs: change `add_node.__doc__` in `state.py` - [`6d78d99`](https://github.com/langchain-ai/langgraph/commit/6d78d99bae828ad5625dea8e2ffd29f475157bdd) Merge branch 'main' into add_node ### 📊 Changes **2 files changed** (+53 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `libs/langgraph/langgraph/graph/graph.py` (+26 -16) 📝 `libs/langgraph/langgraph/graph/state.py` (+27 -12) </details> ### 📄 Description This pull request adds support for using the `add_node` method as a decorator in the `StateGraph` class. Previously, the method could only be used to add nodes by passing the node name and action as arguments. With this change, developers can now use the `add_node` method as a decorator to define nodes directly within the class definition. This provides a more concise and intuitive way to add nodes to the state graph. Examples: ```python graph = Graph(...) # All of the following are supported @graph.add_node("search node") def search(): pass # Uses search.__name__ as the name of the node @graph.add_node() def search(): pass @graph.add_node def search(): pass ``` The default behavior is still supported as well ```python def search(): pass graph.add_node(search) graph.add_node("search tool", search) ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-20 17:45:33 -05:00
yindo closed this issue 2026-02-20 17:45:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#1785