Lgcodegen Gen Graph Code

LangChain Hub prompt: johannes/lgcodegen-gen_graph_code

J
johannes
·May 3, 2026·
177 0 90
$7.99
Prompt
466 words

{graph_notation}

{graph_spec}

Here is the python State class associated with this graph.

{state_code}

Nodes are specified in markdown files in sections for each node.

BEHAVIOR: the comment above the node specifies the behavior
USER_PROMPT: prompt for user, what we are asking for, if anything
GENERATION_PROMPT: prompt for model to generate data
READS: field_name_1
WRITES: field_name_3, field_name_7

Here is the node specification:

{node_spec}

Please do the following tasks:

  1. Write the Routing Functions for this graph
  2. Write the langgraph builder code for this graph, see examples below
  3. Write this code to the file 'graph_code.py'
  • at the top of the file, add comment indicating file was generated using {model_name}
  • import the graph state from state_code.py
  • import the node functions from node_code.py
  1. Do not write any Node Functions, only write Routing Functions and the Graph Builder code

Here's an example graph:

from langchain_core.runnables.config import RunnableConfig from langgraph.graph import START, END, StateGraph from langgraph.checkpoint.sqlite import SqliteSaver

def make_builder(): builder = StateGraph(JokesterState)

# Add node functions
builder.add_node('get_joke_topic', get_joke_topic)
builder.add_node('tell_joke', tell_joke)
builder.add_node('ask_for_another', ask_for_another)

# Add edges for execution flow
builder.add_edge(START, 'get_joke_topic')
builder.add_edge('get_joke_topic', 'tell_joke')
builder.add_edge('tell_joke', 'ask_for_another')

# Conditional routing from ask_for_another node
# Note the special handling for END, we automatically map the string 'END' to the constant END.
# This means the Routing Function returns the string values 'tell_joke' and 'END', and these map to 'tell_joke' and END (the constant, special case only for 'END')
conditional_edges = ⟨ 'tell_joke': 'tell_joke', 'END': END ⟩
builder.add_conditional_edges('ask_for_another', tell_another, conditional_edges)
return builder

NOTE: Worker Nodes require special handling in the graph.

from langchain_core.runnables.config import RunnableConfig from langgraph.graph import START, END, StateGraph

In this example, we have:

#. GRAPH_LINE: orchestrator -> llm_call(State.sections)

The "State.sections" is the iterable, and the

from langgraph.constants import Send

def assign_workers(state: State): """Assign a worker to each section in the plan"""

# Kick off section writing in parallel via Send() API
return [Send("llm_call", ⟨ "section": s⟩) for s in state["sections"]]

building graph like previous example, this shows how to transition to Worker Node

to add that transition to the graph

orchestrator_worker_builder.add_conditional_edges( "orchestrator", assign_workers, ["llm_call"] )

Please do the following tasks:

  1. Write the Routing Functions for this graph
  2. Write the langgraph builder code for this graph. Only write the function that returns the builder. Do not compile the graph or call this function. That code will be written elsewhere. Only write this function. Name it 'make_builder'
  3. Write this code to the file 'graph_code.py'
  • at the top of the file, add comment indicating file was generated using {model_name}
  • import the graph state from state_code.py
  • import the node functions from node_code.py
  1. Do not write any Node Functions, only write Routing Functions and the Graph Builder code

Write the Routing Functions and Builder code to file: graph_code.py.

{question}

This prompt contains variables shown as ⟨variable_name⟩. Replace them with your own values before using.

How to Use

Use with LangChain: hub.pull("johannes/lgcodegen-gen_graph_code")

Need help?

Connect with verified experts who can help you succeed.

Related Prompts

More prompts in Coding & Development

View All
Coding & Development
Universal

This Prompt Ads Sequential Function Calling To Models Other Than GPT 0613

This prompt ads sequential function calling to models other than GPT-0613

H
homanp$2.99
39,910 89,588
Coding & Development
Universal

Create a personalized workout routine

Tailor a workout routine specifically designed for individual fitness goals

K
Kay Tam$2.99
23,370 23,405
Coding & Development
Universal

GODMODE CHEATCODE

God Writes You a Letter Today. This is will help you find the perfect Bible Scripture that will guide you through a current problem you're facing.

D
digitaljeff$3.99
13,574 13,622
Coding & Development
Universal

Creating a Personal Finance Tracker with [Technology/Tool]

Learn to create a personal finance tracker using [Technology/Tool]. Get code samples and budgeting tips.

B
BowTiedThinkerFree
376 385
Coding & Development
ChatGPT

Build an entire application using bubble.io with ChatGPT4

Build an entire app with bubble.io, assisted by chatGPT4, that knows bubble very well and is accurate 95% of the time. This prompt will help you maximize the quality of chatGPT assistance. Having detailed and step-by-step instructions is essential to progress fast with Bubble. This initial prompt will help you get started on a good basis. Follow it because I will make it even better.

T
Tristanyway$5.99
1,280 1,300
Coding & Development
Universal

Become LawyerGPT

Are you in a legal bind? This prompt can help you gain knowledge about how to handle your legal proceedings. DISCLAIMER: Please meet with a real lawyer to discuss your options.

C
Chase Curtis$2.99
1,063 1,076