Prerequisites
RemoteGraph
is an interface that allows you to interact with your LangGraph Platform deployment as if it were a regular, locally-defined LangGraph graph (e.g. a CompiledGraph
). This guide shows you how you can initialize a RemoteGraph
and interact with it.
Initializing the graph
When initializing aRemoteGraph
, you must always specify:
name
: the name of the graph you want to interact with or an assistant ID. If you specify a graph name, the default assistant will be used. If you specify an assistant ID, that specific assistant will be used. The graph name is the same name you use inlanggraph.json
configuration file for your deployment.api_key
: a valid LangSmith API key. Can be set as an environment variable (LANGSMITH_API_KEY
) or passed directly via theapi_key
argument. The API key could also be provided via theclient
/sync_client
arguments, ifLangGraphClient
/SyncLangGraphClient
were initialized withapi_key
argument.
url
: URL of the deployment you want to interact with. If you passurl
argument, both sync and async clients will be created using the provided URL, headers (if provided) and default configuration values (e.g. timeout, etc).client
: aLangGraphClient
instance for interacting with the deployment asynchronously (e.g. using.astream()
,.ainvoke()
,.aget_state()
,.aupdate_state()
, etc.)sync_client
: aSyncLangGraphClient
instance for interacting with the deployment synchronously (e.g. using.stream()
,.invoke()
,.get_state()
,.update_state()
, etc.)
If you pass both
client
or sync_client
as well as url
argument, they will take precedence over the url
argument. If none of the client
/ sync_client
/ url
arguments are provided, RemoteGraph
will raise a ValueError
at runtime.Using URL
- Python
- JavaScript
Using clients
- Python
- JavaScript
Invoking the graph
SinceRemoteGraph
is a Runnable
that implements the same methods as CompiledGraph
, you can interact with it the same way you normally would with a compiled graph, i.e. by calling .invoke()
, .stream()
, .get_state()
, .update_state()
, etc (as well as their async counterparts).
Asynchronously
To use the graph asynchronously, you must provide either the
url
or client
when initializing the RemoteGraph
.- Python
- JavaScript
Synchronously
To use the graph synchronously, you must provide either the
url
or sync_client
when initializing the RemoteGraph
.- Python
Thread-level persistence
By default, the graph runs (i.e..invoke()
or .stream()
invocations) are stateless - the checkpoints and the final state of the graph are not persisted. If you would like to persist the outputs of the graph run (for example, to enable human-in-the-loop features), you can create a thread and provide the thread ID via the config
argument, same as you would with a regular compiled graph:
- Python
- JavaScript
Using as a subgraph
If you need to use a
checkpointer
with a graph that has a RemoteGraph
subgraph node, make sure to use UUIDs as thread IDs.RemoteGraph
behaves the same way as a regular CompiledGraph
, it can be also used as a subgraph in another graph. For example:
- Python
- JavaScript