From 348de9fb63f9ef1592e403475d32dd78225f0700 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Tue, 14 Oct 2025 13:26:56 -0400 Subject: [PATCH 1/2] Revert "revert interactive diagram (#860)" This reverts commit 946a685169d525de71f7419ff885a069a7b40256. --- pipeline/core/builder.py | 10 +- pyproject.toml | 9 +- src/oss/langchain/middleware.mdx | 20 +- .../middleware_visualization/README.md | 63 +++ .../middleware_visualization/diagrams_js.js | 1 + .../diagrams_python.js | 1 + .../generate_middleware_diagrams.py | 259 +++++++++++ .../middleware_visualization/index.html | 401 ++++++++++++++++++ tests/unit_tests/test_builder.py | 1 + 9 files changed, 748 insertions(+), 17 deletions(-) create mode 100644 src/plugins/middleware_visualization/README.md create mode 100644 src/plugins/middleware_visualization/diagrams_js.js create mode 100644 src/plugins/middleware_visualization/diagrams_python.js create mode 100644 src/plugins/middleware_visualization/generate_middleware_diagrams.py create mode 100644 src/plugins/middleware_visualization/index.html diff --git a/pipeline/core/builder.py b/pipeline/core/builder.py index a0ec66207..8185dd755 100644 --- a/pipeline/core/builder.py +++ b/pipeline/core/builder.py @@ -51,6 +51,7 @@ def __init__(self, src_dir: Path, build_dir: Path) -> None: ".yaml", ".css", ".js", + ".html", } # Mapping of language codes to full names for URLs @@ -152,8 +153,8 @@ def rewrite_link(match: re.Match) -> str: url = match.group(2) # The URL post = match.group(3) # Everything after the URL - # Only rewrite absolute /oss/ paths that don't contain 'images' - if url.startswith("/oss/") and "images" not in url: + # Only rewrite absolute /oss/ paths that don't contain 'images' or 'plugins' + if url.startswith("/oss/") and "images" not in url and "plugins" not in url: parts = url.split("/") # Insert full language name after "oss" parts.insert(2, self.language_url_names[target_language]) @@ -739,8 +740,11 @@ def is_shared_file(self, file_path: Path) -> bool: if "snippets" in relative_path.parts: return True + if "plugins" in relative_path.parts: + return True + # JavaScript and CSS files should be shared (used for custom scripts/styles) - return file_path.suffix.lower() in {".js", ".css"} + return file_path.suffix.lower() in {".js", ".css", ".html", ".json"} def _copy_shared_files(self) -> None: """Copy files that should be shared between versions.""" diff --git a/pyproject.toml b/pyproject.toml index 4231dbe5f..b9abdd8cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,8 @@ asyncio_default_fixture_loop_scope = "function" line-length = 88 extend-exclude = [ "scripts/update_mdx.py", - "pipeline/tools/notebook/convert.py" + "pipeline/tools/notebook/convert.py", + "src/plugins/middleware_visualization/generate_middleware_diagrams.py" ] @@ -133,3 +134,9 @@ ignore = [ [tool.ruff.lint.pydocstyle] convention = "google" + + +[tool.mypy] +exclude = [ + "src/plugins/middleware_visualization/generate_middleware_diagrams.py", +] diff --git a/src/oss/langchain/middleware.mdx b/src/oss/langchain/middleware.mdx index 273557c8d..aa943a217 100644 --- a/src/oss/langchain/middleware.mdx +++ b/src/oss/langchain/middleware.mdx @@ -971,21 +971,15 @@ agent = create_agent( #### Node-style hooks -Run at specific points in the execution flow: +Run at specific points in the execution flow. -:::python -- `before_agent` - Before agent starts (once per invocation) -- `before_model` - Before each model call -- `after_model` - After each model response -- `after_agent` - After agent completes (up to once per invocation) -::: +**Try it:** The interactive widget below shows all available hooks and lets you toggle different combinations to see how they affect the agent execution graph: -:::js -- `beforeAgent` - Before agent starts (once per invocation) -- `beforeModel` - Before each model call -- `afterModel` - After each model response -- `afterAgent` - After agent completes (up to once per invocation) -::: +