Skip to main content
You might need to rebuild your graph with a different configuration for a new run. For example, you might need to use a different graph state or graph structure depending on the config. This guide shows how you can do this.
Note In most cases, customizing behavior based on the config should be handled by a single graph where each node can read a config and change its behavior based on it

Prerequisites

Make sure to check out this how-to guide on setting up your app for deployment first.

Define graphs

Let’s say you have an app with a simple graph that calls an LLM and returns the response to the user. The app file directory looks like the following:
where the graph is defined in openai_agent.py.

No rebuild

In the standard LangGraph API configuration, the server uses the compiled graph instance that’s defined at the top level of openai_agent.py, which looks like the following:
To make the server aware of your graph, you need to specify a path to the variable that contains the CompiledStateGraph instance in your LangGraph API configuration (langgraph.json), e.g.:

Rebuild

To make your graph rebuild on each new run with custom configuration, you need to rewrite openai_agent.py to instead provide a function that takes a config and returns a graph (or compiled graph) instance. Let’s say we want to return our existing graph for user ID β€˜1’, and a tool-calling agent for other users. We can modify openai_agent.py as follows:
Finally, you need to specify the path to your graph-making function (make_graph) in langgraph.json:
See more info on LangGraph API configuration file here
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.