The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
core: Add metadata to graph json repr (#24131)
Nuno Campos242898420579
diff --git a/libs/core/langchain_core/runnables/graph.py b/libs/core/langchain_core/runnables/graph.pyindex cfd798580e..0298b3c72f 100644--- a/libs/core/langchain_core/runnables/graph.py+++ b/libs/core/langchain_core/runnables/graph.py@@ -170,7 +170,7 @@ def node_data_json(from langchain_core.runnables.base import Runnable, RunnableSerializableif isinstance(node.data, RunnableSerializable):- return {+ json: Dict[str, Any] = {"type": "runnable","data": {"id": node.data.lc_id(),@@ -178,7 +178,7 @@ def node_data_json(},}elif isinstance(node.data, Runnable):- return {+ json = {"type": "runnable","data": {"id": to_json_not_implemented(node.data)["id"],@@ -186,7 +186,7 @@ def node_data_json(},}elif inspect.isclass(node.data) and issubclass(node.data, BaseModel):- return (+ json = ({"type": "schema","data": node.data.schema(),@@ -198,10 +198,13 @@ def node_data_json(})else:- return {+ json = {"type": "unknown","data": node_data_str(node.id, node.data),}+ if node.metadata is not None:+ json["metadata"] = node.metadata+ return json@dataclassdiff --git a/libs/core/tests/unit_tests/runnables/test_graph.py b/libs/core/tests/unit_tests/runnables/test_graph.pyindex bc80d48a5a..975d6b816d 100644--- a/libs/core/tests/unit_tests/runnables/test_graph.py+++ b/libs/core/tests/unit_tests/runnables/test_graph.py@@ -57,6 +57,7 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:"id": ["langchain_core", "language_models", "fake", "FakeListLLM"],"name": "FakeListLLM",},+ "metadata": {"key": 2},},{"id": 3,@@ -111,6 +112,7 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:"id": ["langchain_core", "language_models", "fake", "FakeListLLM"],"name": "FakeListLLM",},+ "metadata": {"key": 2},},{"id": 3,