mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-25 17:12:26 +02:00
langgraph: decouple name from assistant ID in RemoteGraph
This commit is contained in:
@@ -93,11 +93,12 @@ class RemoteGraph(PregelProtocol):
|
||||
a node in another `Graph`.
|
||||
"""
|
||||
|
||||
name: str
|
||||
assistant_id: str
|
||||
name: Optional[str]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str, # graph_id
|
||||
assistant_id: str, # graph_id
|
||||
/,
|
||||
*,
|
||||
url: Optional[str] = None,
|
||||
@@ -106,6 +107,7 @@ class RemoteGraph(PregelProtocol):
|
||||
client: Optional[LangGraphClient] = None,
|
||||
sync_client: Optional[SyncLangGraphClient] = None,
|
||||
config: Optional[RunnableConfig] = None,
|
||||
name: Optional[str] = None,
|
||||
):
|
||||
"""Specify `url`, `api_key`, and/or `headers` to create default sync and async clients.
|
||||
|
||||
@@ -114,14 +116,18 @@ class RemoteGraph(PregelProtocol):
|
||||
one of `url`, `client`, or `sync_client` must be provided.
|
||||
|
||||
Args:
|
||||
name: The name of the graph.
|
||||
assistant_id: The assistant ID or graph name of the remote graph to use.
|
||||
url: The URL of the remote API.
|
||||
api_key: The API key to use for authentication. If not provided, it will be read from the environment (`LANGGRAPH_API_KEY`, `LANGSMITH_API_KEY`, or `LANGCHAIN_API_KEY`).
|
||||
headers: Additional headers to include in the requests.
|
||||
client: A `LangGraphClient` instance to use instead of creating a default client.
|
||||
sync_client: A `SyncLangGraphClient` instance to use instead of creating a default client.
|
||||
config: An optional `RunnableConfig` instance with additional configuration.
|
||||
name: Human-readable name to attach to the RemoteGraph instance.
|
||||
Will be accessible via `RemoteGraph.name`. This is useful for adding `RemoteGraph`
|
||||
as a subgraph via `graph.add_node(remote_graph)`.
|
||||
"""
|
||||
self.assistant_id = assistant_id
|
||||
self.name = name
|
||||
self.config = config
|
||||
|
||||
@@ -149,7 +155,7 @@ class RemoteGraph(PregelProtocol):
|
||||
|
||||
def copy(self, update: dict[str, Any]) -> Self:
|
||||
attrs = {**self.__dict__, **update}
|
||||
return self.__class__(attrs.pop("name"), **attrs)
|
||||
return self.__class__(attrs.pop("assistant_id"), **attrs)
|
||||
|
||||
def with_config(
|
||||
self, config: Optional[RunnableConfig] = None, **kwargs: Any
|
||||
@@ -203,7 +209,7 @@ class RemoteGraph(PregelProtocol):
|
||||
"""
|
||||
sync_client = self._validate_sync_client()
|
||||
graph = sync_client.assistants.get_graph(
|
||||
assistant_id=self.name,
|
||||
assistant_id=self.assistant_id,
|
||||
xray=xray,
|
||||
)
|
||||
return DrawableGraph(
|
||||
@@ -232,7 +238,7 @@ class RemoteGraph(PregelProtocol):
|
||||
"""
|
||||
client = self._validate_client()
|
||||
graph = await client.assistants.get_graph(
|
||||
assistant_id=self.name,
|
||||
assistant_id=self.assistant_id,
|
||||
xray=xray,
|
||||
)
|
||||
return DrawableGraph(
|
||||
@@ -642,7 +648,7 @@ class RemoteGraph(PregelProtocol):
|
||||
|
||||
for chunk in sync_client.runs.stream(
|
||||
thread_id=sanitized_config["configurable"].get("thread_id"),
|
||||
assistant_id=self.name,
|
||||
assistant_id=self.assistant_id,
|
||||
input=input,
|
||||
command=command,
|
||||
config=sanitized_config,
|
||||
@@ -737,7 +743,7 @@ class RemoteGraph(PregelProtocol):
|
||||
|
||||
async for chunk in client.runs.stream(
|
||||
thread_id=sanitized_config["configurable"].get("thread_id"),
|
||||
assistant_id=self.name,
|
||||
assistant_id=self.assistant_id,
|
||||
input=input,
|
||||
command=command,
|
||||
config=sanitized_config,
|
||||
|
||||
Reference in New Issue
Block a user