Visualize LangGraph code and estimate its cost per node
Paste the code that builds your LangGraph agent and Nodagentry draws it as a graph: every node, branch, tool and approval step, with the estimated cost of each model call. Then run it in the free simulator, apply a suggested fix and compare the cost before and after.
From code to graph
This is a typical LangGraph agent: a cheap model triages the request, a stronger model does the work and can call tools until it is done.
from langchain_openai import ChatOpenAI
from langgraph.graph import StateGraph, MessagesState, START
from langgraph.prebuilt import ToolNode, tools_condition
triage_llm = ChatOpenAI(model="gpt-4o-mini")
agent_llm = ChatOpenAI(model="gpt-4o").bind_tools(tools)
def triage(state: MessagesState):
return {"messages": [triage_llm.invoke(state["messages"])]}
def agent(state: MessagesState):
return {"messages": [agent_llm.invoke(state["messages"])]}
builder = StateGraph(MessagesState)
builder.add_node("triage", triage)
builder.add_node("agent", agent)
builder.add_node("tools", ToolNode(tools))
builder.add_edge(START, "triage")
builder.add_edge("triage", "agent")
builder.add_conditional_edges("agent", tools_condition)
builder.add_edge("tools", "agent")
graph = builder.compile()
The gpt-4o agent is the expensive step. In the editor, the top insight moves the most expensive steps to a cheaper tier; apply it, run again and the before and after costs sit side by side.
Import your agent in four steps
- Open the importer. In the editor it is also under the example picker and the More menu, as Import agent code.
- Paste the file that builds your graph. The panel on the right shows what it found: model steps, tools, branches, approvals and the model behind each step.
- Choose Import to canvas (Import as new workflow when you are signed in), then Run baseline. Sim needs no key and shows the route and the cost of every step.
- Open Improve and apply the top insight, or change a step's model tier in the Inspector, and run again to compare. Change in your code then lists the model names to swap in your source to get the same saving.
How LangGraph maps to the graph
| In your code | In Nodagentry |
|---|---|
| add_node with a function that calls a chat model | Agent, on the model's price tier |
| add_node with ToolNode(...) | Tool (a stand-in in Sim) |
| add_conditional_edges(source, fn, path_map) | Branch point, one edge per route |
| tools_condition | Branch to tools or to Result |
| interrupt() inside a node, or compile(interrupt_before=[...]) | Approval gate |
| add_node with plain code and no model call | Code step, costs nothing |
| START, set_entry_point / END, set_finish_point | Input / Result |
| create_react_agent(model, tools) | Agent ⇄ Tools, drawn as one pass |
Chat models are found from constructors such as ChatOpenAI, ChatAnthropic, ChatGoogleGenerativeAI, ChatOllama and init_chat_model, including variables made with .bind_tools() or .with_structured_output(). A node gets the model its function calls.
Price tiers
Each model step lands on one of five tiers. The estimate uses the tier's list price, and you can change any step's tier in the Inspector.
| Tier | Models in your code | Per 1M tokens in / out |
|---|---|---|
| Frontier Pro | claude-opus-4-1, o3, gpt-4.5 | $15 / $60 |
| Frontier | gpt-4o, gpt-4.1, claude-sonnet-4-5, gemini-2.5-pro | $2.5 / $10 |
| Frontier Mini | gpt-4o-mini, claude-3-5-haiku, gemini-2.5-flash, o3-mini | $0.8 / $3.2 |
| Open 70B | llama-3.3-70b, mixtral-8x7b, qwen2.5:72b | $0.4 / $0.8 |
| Local 7B | llama3.1:8b, qwen2.5:7b, mistral | $0.05 / $0.1 |
What it can't see yet
The importer reads your code as text, so it only knows what the code spells out.
- Graphs assembled at runtime, for example nodes added in a loop from a config file.
- Routing done with
Command(goto=...)or fan-out withSend(). Add those edges in the editor after importing. - Compiled subgraphs show as a single step. If one file builds several graphs, paste one at a time.
- When a node's model isn't clear from the code, it starts on Frontier Mini and the importer says so.
Questions
- Is my LangGraph code uploaded or run?
- No. The importer reads the code as text in your browser to find nodes, edges and chat models. Nothing is executed and the code is not sent to a server. If you are signed in, the imported graph is saved to your account as a new workflow.
- Does it work with LangGraph.js as well as Python?
- Yes. It reads StateGraph builders in Python and in JavaScript or TypeScript (add_node or addNode, add_edge or addEdge, add_conditional_edges or addConditionalEdges), plus the prebuilt create_react_agent.
- How is the cost per node estimated?
- Each model step gets a price tier from the model named in your code. The editor estimates input and output tokens from the task and the kind of step, then multiplies by that tier's list price per million tokens. Run Live with your own key to see real token counts.
- What happens to loops like agent → tools → agent?
- A design graph runs each step once, so loops are drawn as a single pass and the importer lists the loop it removed. The estimate is the cost of one pass through the loop.
- Is Nodagentry affiliated with LangChain?
- No. Nodagentry is an independent product by Wasapile Labs. LangGraph and LangChain are trademarks of LangChain, Inc.
Next
Once the costs look right, run the same graph on real models in Models & Live, or browse workflow examples built in the editor.