[PR #364] [CLOSED] docs: optimize the syntactic expression of graph usage #1410

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

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraph/pull/364
Author: @Undertone0809
Created: 4/30/2024
Status: Closed

Base: mainHead: zeeland/perf-node-state


📝 Commits (1)

  • e62a0eb docs: optimize the syntactic expression of graph usage

📊 Changes

5 files changed (+360 additions, -87 deletions)

View changed files

📝 examples/agent_executor/base.ipynb (+100 -36)
📝 examples/agent_executor/force-calling-a-tool-first.ipynb (+15 -8)
📝 examples/plan-and-execute/plan-and-execute.ipynb (+16 -10)
📝 examples/rag/langgraph_adaptive_rag.ipynb (+209 -18)
📝 examples/reflection/reflection.ipynb (+20 -15)

📄 Description

I have already used langgraph in some production projects. When dealing with particularly complex logic, it is easy to misspell node names by simply using string to declare node names. We can optimize the way of node declaration and use enumeration to declare node names. Ref: https://github.com/langchain-ai/langgraph/pull/255

I have only changed some of the previous examples. If you agree with this way of writing, I think I can help modify the writing of node declarations in all documents.

from langgraph.graph import StateGraph, END
from enum import Enum

class NodeType(str, Enum):
    PLAN = "planner"
    EXECUTE = "agent"
    REPLAN = "replan"

workflow = StateGraph(PlanExecute)

# Add the plan node
workflow.add_node(NodeType.PLAN, plan_step)

# Add the execution step
workflow.add_node(NodeType.EXECUTE, execute_step)

# Add a replan node
workflow.add_node(NodeType.REPLAN, replan_step)

workflow.set_entry_point(NodeType.PLAN)

# From plan we go to agent
workflow.add_edge(NodeType.PLAN, NodeType.EXECUTE)

# From agent, we replan
workflow.add_edge(NodeType.EXECUTE, NodeType.REPLAN)

workflow.add_conditional_edges(
    NodeType.REPLAN,
    # Next, we pass in the function that will determine which node is called next.
    should_end,
    {
        # If `tools`, then we call the tool node.
        True: END,
        False: NodeType.EXECUTE,
    },
)

# Finally, we compile it!
# This compiles it into a LangChain Runnable,
# meaning you can use it as you would any other runnable
app = workflow.compile()


🔄 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/364 **Author:** [@Undertone0809](https://github.com/Undertone0809) **Created:** 4/30/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `zeeland/perf-node-state` --- ### 📝 Commits (1) - [`e62a0eb`](https://github.com/langchain-ai/langgraph/commit/e62a0ebe8694f45340cc799acf785e22c35a544f) docs: optimize the syntactic expression of graph usage ### 📊 Changes **5 files changed** (+360 additions, -87 deletions) <details> <summary>View changed files</summary> 📝 `examples/agent_executor/base.ipynb` (+100 -36) 📝 `examples/agent_executor/force-calling-a-tool-first.ipynb` (+15 -8) 📝 `examples/plan-and-execute/plan-and-execute.ipynb` (+16 -10) 📝 `examples/rag/langgraph_adaptive_rag.ipynb` (+209 -18) 📝 `examples/reflection/reflection.ipynb` (+20 -15) </details> ### 📄 Description I have already used langgraph in some production projects. When dealing with particularly complex logic, it is easy to misspell node names by simply using string to declare node names. We can optimize the way of node declaration and use enumeration to declare node names. Ref: https://github.com/langchain-ai/langgraph/pull/255 I have only changed some of the previous examples. If you agree with this way of writing, I think I can help modify the writing of node declarations in all documents. ```python from langgraph.graph import StateGraph, END from enum import Enum class NodeType(str, Enum): PLAN = "planner" EXECUTE = "agent" REPLAN = "replan" workflow = StateGraph(PlanExecute) # Add the plan node workflow.add_node(NodeType.PLAN, plan_step) # Add the execution step workflow.add_node(NodeType.EXECUTE, execute_step) # Add a replan node workflow.add_node(NodeType.REPLAN, replan_step) workflow.set_entry_point(NodeType.PLAN) # From plan we go to agent workflow.add_edge(NodeType.PLAN, NodeType.EXECUTE) # From agent, we replan workflow.add_edge(NodeType.EXECUTE, NodeType.REPLAN) workflow.add_conditional_edges( NodeType.REPLAN, # Next, we pass in the function that will determine which node is called next. should_end, { # If `tools`, then we call the tool node. True: END, False: NodeType.EXECUTE, }, ) # Finally, we compile it! # This compiles it into a LangChain Runnable, # meaning you can use it as you would any other runnable app = workflow.compile() ``` --- <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:44:39 -05:00
yindo closed this issue 2026-02-20 17:44:39 -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#1410