Skip to content

Commit

Permalink
docs[patch]: update links w/ new langgraph API ref (#26961)
Browse files Browse the repository at this point in the history
Co-authored-by: Erick Friis <[email protected]>
  • Loading branch information
vbarda and efriis authored Oct 3, 2024
1 parent 47142eb commit 2715bed
Showing 1 changed file with 47 additions and 118 deletions.
165 changes: 47 additions & 118 deletions docs/scripts/generate_api_reference_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,111 +20,53 @@
code_block_re = re.compile(r"^(```\s?python\n)(.*?)(```)", re.DOTALL | re.MULTILINE)


# (alias/re-exported modules, source module, class, docs namespace)
MANUAL_API_REFERENCES_LANGGRAPH = [
("langgraph.prebuilt", "create_react_agent"),
(
"langgraph.prebuilt",
"ToolNode",
["langgraph.prebuilt"],
"langgraph.prebuilt.chat_agent_executor",
"create_react_agent",
"prebuilt",
),
(["langgraph.prebuilt"], "langgraph.prebuilt.tool_node", "ToolNode", "prebuilt"),
(
"langgraph.prebuilt",
"ToolExecutor",
["langgraph.prebuilt"],
"langgraph.prebuilt.tool_node",
"tools_condition",
"prebuilt",
),
(
"langgraph.prebuilt",
"ToolInvocation",
),
("langgraph.prebuilt", "tools_condition"),
(
"langgraph.prebuilt",
"ValidationNode",
),
(
"langgraph.prebuilt",
["langgraph.prebuilt"],
"langgraph.prebuilt.tool_node",
"InjectedState",
"prebuilt",
),
# Graph
(
"langgraph.graph",
"StateGraph",
),
(
"langgraph.graph.message",
"MessageGraph",
),
("langgraph.graph.message", "add_messages"),
(
"langgraph.graph.graph",
"CompiledGraph",
),
(
"langgraph.types",
"StreamMode",
),
(
"langgraph.graph",
"START",
),
(
"langgraph.graph",
"END",
),
(
"langgraph.types",
"Send",
),
(
"langgraph.types",
"Interrupt",
),
(
"langgraph.types",
"RetryPolicy",
),
(
"langgraph.checkpoint.base",
"Checkpoint",
),
(
"langgraph.checkpoint.base",
"CheckpointMetadata",
),
(
"langgraph.checkpoint.base",
"BaseCheckpointSaver",
),
(
"langgraph.checkpoint.base",
"SerializerProtocol",
),
(
"langgraph.checkpoint.serde.jsonplus",
"JsonPlusSerializer",
),
(
"langgraph.checkpoint.memory",
"MemorySaver",
),
(
"langgraph.checkpoint.sqlite.aio",
"AsyncSqliteSaver",
),
(
"langgraph.checkpoint.sqlite",
"SqliteSaver",
),
(
"langgraph.checkpoint.postgres.aio",
"AsyncPostgresSaver",
),
(
"langgraph.checkpoint.postgres",
"PostgresSaver",
),
(["langgraph.graph"], "langgraph.graph.message", "add_messages", "graphs"),
(["langgraph.graph"], "langgraph.graph.state", "StateGraph", "graphs"),
(["langgraph.graph"], "langgraph.graph.state", "CompiledStateGraph", "graphs"),
([], "langgraph.types", "StreamMode", "types"),
(["langgraph.graph"], "langgraph.constants", "START", "constants"),
(["langgraph.graph"], "langgraph.constants", "END", "constants"),
(["langgraph.constants"], "langgraph.types", "Send", "types"),
(["langgraph.constants"], "langgraph.types", "Interrupt", "types"),
([], "langgraph.types", "RetryPolicy", "types"),
([], "langgraph.checkpoint.base", "Checkpoint", "checkpoints"),
([], "langgraph.checkpoint.base", "CheckpointMetadata", "checkpoints"),
([], "langgraph.checkpoint.base", "BaseCheckpointSaver", "checkpoints"),
([], "langgraph.checkpoint.base", "SerializerProtocol", "checkpoints"),
([], "langgraph.checkpoint.serde.jsonplus", "JsonPlusSerializer", "checkpoints"),
([], "langgraph.checkpoint.memory", "MemorySaver", "checkpoints"),
([], "langgraph.checkpoint.sqlite.aio", "AsyncSqliteSaver", "checkpoints"),
([], "langgraph.checkpoint.sqlite", "SqliteSaver", "checkpoints"),
([], "langgraph.checkpoint.postgres.aio", "AsyncPostgresSaver", "checkpoints"),
([], "langgraph.checkpoint.postgres", "PostgresSaver", "checkpoints"),
]

WELL_KNOWN_LANGGRAPH_OBJECTS = {
(module_, class_) for module_, class_ in MANUAL_API_REFERENCES_LANGGRAPH
(module_, class_): (source_module, namespace)
for (modules, source_module, class_, namespace) in MANUAL_API_REFERENCES_LANGGRAPH
for module_ in modules + [source_module]
}


Expand Down Expand Up @@ -308,34 +250,21 @@ def _get_imports(
+ ".html"
)
elif package_ecosystem == "langgraph":
if module.startswith("langgraph.checkpoint"):
namespace = "checkpoints"
elif module.startswith("langgraph.graph"):
namespace = "graphs"
elif module.startswith("langgraph.prebuilt"):
namespace = "prebuilt"
elif module.startswith("langgraph.errors"):
namespace = "errors"
else:
if (module, class_name) not in WELL_KNOWN_LANGGRAPH_OBJECTS:
# Likely not documented yet
# Unable to determine the namespace
continue

if module.startswith("langgraph.errors"):
# Has different URL structure than other modules
url = (
_LANGGRAPH_API_REFERENCE
+ namespace
+ "/#langgraph.errors."
+ class_name # Uses the actual class name here.
)
else:
if (module, class_name) not in WELL_KNOWN_LANGGRAPH_OBJECTS:
# Likely not documented yet
continue
url = (
_LANGGRAPH_API_REFERENCE + namespace + "/#" + class_name.lower()
)
source_module, namespace = WELL_KNOWN_LANGGRAPH_OBJECTS[
(module, class_name)
]
url = (
_LANGGRAPH_API_REFERENCE
+ namespace
+ "/#"
+ source_module
+ "."
+ class_name
)
else:
raise ValueError(f"Invalid package ecosystem: {package_ecosystem}")

Expand Down

0 comments on commit 2715bed

Please sign in to comment.