Skip to content

Conversation

@dudududukim
Copy link

@dudududukim dudududukim commented Nov 19, 2025

Overview

Adds a detailed middleware execution flow diagram to the custom middleware documentation to help developers understand the complete agent execution lifecycle and all middleware hook points.

image

Type of change

Type: Update existing documentation

Related issues/PRs

  • GitHub issue: N/A
  • Feature PR: N/A
  • Linear issue: N/A
  • Slack thread: N/A

Checklist

  • I have read the contributing guidelines
  • I have tested my changes locally using docs dev
  • All code examples have been tested and work correctly
  • I have used root relative paths for internal links
  • I have updated navigation in src/docs.json if needed

(Internal team members only / optional): Create a preview deployment as necessary using the Create Preview Branch workflow

Additional notes

Changes Made

  • Added: SVG diagram (agent-middleware-execution-flow.svg) to /src/oss/images/
  • Updated: Added "Detailed execution flow" section under "Execution order" in custom.mdx

Motivations

The middleware documentation explains hooks conceptually but lacks a visual representation of how they interact during agent execution. This diagram visualizes:

Complete execution lifecycle from START to completion

Invocation order of all middleware hooks (before_agent, before_model, after_model, after_agent)

Relationship between hooks, model calls, and tool execution

For detailed background, see: What is Middleware in LangChain's createAgent?

Testing Results

✅ make test passed (82 passed in 0.14s)
✅ Locally verified SVG rendering without errors using docs dev
✅ Image displays correctly at http://localhost:3000/oss/langchain/middleware/custom

✅ Follows established patterns from overview.mdx (using tag with absolute path)

✅ Alt text meets accessibility requirements

Feedback Welcome

If there are suggestions for improving the diagram content, styling, or placement, please provide feedback for a modified PR.

@github-actions github-actions bot added langchain For docs changes to LangChain oss labels Nov 19, 2025
@sydney-runkle
Copy link
Contributor

Hiya! Thanks so much for your contribution.

We're super excited about LangChain v1's middleware, and there's definitely a lot to learn in terms of expected flow w/ multiple nodes and wrap + hook style nodes.

I think maybe what could be super helpful here is a few more simple diagrams. Perhaps one that touches on the wrap-style nature of middlewares, ex

M1, M2, M3 means execution order looks like M1, M2, M3 (model) M3, M2, M1

I think another diagram that's helpful could help to explain the jump + exit conditions (loop entry node, loop exit node, etc).

Happy to chat more about what might make the most sense here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

langchain For docs changes to LangChain oss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants