From 23ace67c0971ccb883cf03c2d2e16bebffe717f6 Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 12:51:47 +0900 Subject: [PATCH 01/12] add: agent middleware excution flow figure added --- src/oss/images/agent-middleware-excution-flow.svg | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/oss/images/agent-middleware-excution-flow.svg diff --git a/src/oss/images/agent-middleware-excution-flow.svg b/src/oss/images/agent-middleware-excution-flow.svg new file mode 100644 index 0000000000..2bc940e619 --- /dev/null +++ b/src/oss/images/agent-middleware-excution-flow.svg @@ -0,0 +1,2 @@ +loop_exit_nodem[0].after_modelrouting Nodegraph Nodeexit_nodetoolsm[-1].after_agentm1, m2, m3: Middlewarem1.after_agentm2m3entry_nodeloop_entry_nodem[0].before_modelm[0].before_agentSTARTENDm[-1].before_modelm[-2]m[-3]{structured_resopnse}if there is can_jump_to key,jumping to node is possible{structured_resopnse}if w/o any tools andafter_model mw......NotesModelm[-1].after_modelm[-2]m[-3]...m[-1].before_agentm[-2]m[-3]...ororororwrap_tool_callwrap_model_call \ No newline at end of file From 7b61014622ea2135fc943cfa7e37efc4073417e3 Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 12:53:06 +0900 Subject: [PATCH 02/12] fix: agent middleware execution flow typo --- src/oss/images/agent-middleware-execution-flow.svg | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/oss/images/agent-middleware-execution-flow.svg diff --git a/src/oss/images/agent-middleware-execution-flow.svg b/src/oss/images/agent-middleware-execution-flow.svg new file mode 100644 index 0000000000..2bc940e619 --- /dev/null +++ b/src/oss/images/agent-middleware-execution-flow.svg @@ -0,0 +1,2 @@ +loop_exit_nodem[0].after_modelrouting Nodegraph Nodeexit_nodetoolsm[-1].after_agentm1, m2, m3: Middlewarem1.after_agentm2m3entry_nodeloop_entry_nodem[0].before_modelm[0].before_agentSTARTENDm[-1].before_modelm[-2]m[-3]{structured_resopnse}if there is can_jump_to key,jumping to node is possible{structured_resopnse}if w/o any tools andafter_model mw......NotesModelm[-1].after_modelm[-2]m[-3]...m[-1].before_agentm[-2]m[-3]...ororororwrap_tool_callwrap_model_call \ No newline at end of file From b391fb4ad2f696ca70dc13a96f7b057337b670fc Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 13:06:41 +0900 Subject: [PATCH 03/12] docs: add middleware execution flow diagram --- src/oss/images/agent-middleware-excution-flow.svg | 2 -- src/oss/langchain/middleware/custom.mdx | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) delete mode 100644 src/oss/images/agent-middleware-excution-flow.svg diff --git a/src/oss/images/agent-middleware-excution-flow.svg b/src/oss/images/agent-middleware-excution-flow.svg deleted file mode 100644 index 2bc940e619..0000000000 --- a/src/oss/images/agent-middleware-excution-flow.svg +++ /dev/null @@ -1,2 +0,0 @@ -loop_exit_nodem[0].after_modelrouting Nodegraph Nodeexit_nodetoolsm[-1].after_agentm1, m2, m3: Middlewarem1.after_agentm2m3entry_nodeloop_entry_nodem[0].before_modelm[0].before_agentSTARTENDm[-1].before_modelm[-2]m[-3]{structured_resopnse}if there is can_jump_to key,jumping to node is possible{structured_resopnse}if w/o any tools andafter_model mw......NotesModelm[-1].after_modelm[-2]m[-3]...m[-1].before_agentm[-2]m[-3]...ororororwrap_tool_callwrap_model_call \ No newline at end of file diff --git a/src/oss/langchain/middleware/custom.mdx b/src/oss/langchain/middleware/custom.mdx index 318cc5d784..015618b395 100644 --- a/src/oss/langchain/middleware/custom.mdx +++ b/src/oss/langchain/middleware/custom.mdx @@ -549,6 +549,14 @@ __Agent loop ends__ - `after_*` hooks: Last to first (reverse) - `wrap_*` hooks: Nested (first middleware wraps all others) +### Detailed execution flow + +The following diagram illustrates the complete agent execution lifecycle with all middleware hook points: + +![Middleware execution flow](/oss/images/agent-middleware-execution-flow.svg) + +This flow is based on the LangChain agent execution model. For code implementation details, see the [LangChain agents factory](https://github.com/langchain-ai/langchain/blob/81c4f21b5297b31b2cd82ccefdd134aa0e59efa0/libs/langchain_v1/langchain/agents/factory.py). + ## Agent jumps To exit early from middleware, return a dictionary with `jump_to`: From ea285af04d1219e0ac87ea932226b6e256d9c578 Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 13:09:14 +0900 Subject: [PATCH 04/12] docs: add middleware execution flow diagram --- src/oss/langchain/middleware/custom.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oss/langchain/middleware/custom.mdx b/src/oss/langchain/middleware/custom.mdx index 015618b395..385ab1b98f 100644 --- a/src/oss/langchain/middleware/custom.mdx +++ b/src/oss/langchain/middleware/custom.mdx @@ -555,7 +555,7 @@ The following diagram illustrates the complete agent execution lifecycle with al ![Middleware execution flow](/oss/images/agent-middleware-execution-flow.svg) -This flow is based on the LangChain agent execution model. For code implementation details, see the [LangChain agents factory](https://github.com/langchain-ai/langchain/blob/81c4f21b5297b31b2cd82ccefdd134aa0e59efa0/libs/langchain_v1/langchain/agents/factory.py). +This flow is based on the LangChain agent execution model. For code implementation details, see the [langchain/libs/langchain_v1/langchain/agents/factory.py](https://github.com/langchain-ai/langchain/blob/81c4f21b5297b31b2cd82ccefdd134aa0e59efa0/libs/langchain_v1/langchain/agents/factory.py). ## Agent jumps From 5a52a07ceb782aad751a5c96030e46ffde534ba0 Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 13:11:15 +0900 Subject: [PATCH 05/12] docs: add middleware execution flow diagram --- src/oss/langchain/middleware/custom.mdx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/oss/langchain/middleware/custom.mdx b/src/oss/langchain/middleware/custom.mdx index 385ab1b98f..8777071580 100644 --- a/src/oss/langchain/middleware/custom.mdx +++ b/src/oss/langchain/middleware/custom.mdx @@ -553,9 +553,10 @@ __Agent loop ends__ The following diagram illustrates the complete agent execution lifecycle with all middleware hook points: -![Middleware execution flow](/oss/images/agent-middleware-execution-flow.svg) - -This flow is based on the LangChain agent execution model. For code implementation details, see the [langchain/libs/langchain_v1/langchain/agents/factory.py](https://github.com/langchain-ai/langchain/blob/81c4f21b5297b31b2cd82ccefdd134aa0e59efa0/libs/langchain_v1/langchain/agents/factory.py). +
+ Middleware execution flow diagram showing agent lifecycle with before_agent, before_model, wrap_model_call, after_model, and after_agent hooks +
Based on the LangChain agents factory implementation.
+
## Agent jumps From 3b2e8e83b0ed41e21418f5d6517e54d9f6afa205 Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 13:11:42 +0900 Subject: [PATCH 06/12] docs: add middleware execution flow diagram --- src/oss/langchain/middleware/custom.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oss/langchain/middleware/custom.mdx b/src/oss/langchain/middleware/custom.mdx index 8777071580..d0672cec45 100644 --- a/src/oss/langchain/middleware/custom.mdx +++ b/src/oss/langchain/middleware/custom.mdx @@ -554,7 +554,7 @@ __Agent loop ends__ The following diagram illustrates the complete agent execution lifecycle with all middleware hook points:
- Middleware execution flow diagram showing agent lifecycle with before_agent, before_model, wrap_model_call, after_model, and after_agent hooks + Middleware execution flow diagram
Based on the LangChain agents factory implementation.
From 7338e6598d0cef11b0e2898145ddf7dd7652bb3c Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 13:12:44 +0900 Subject: [PATCH 07/12] docs: add middleware execution flow diagram --- src/oss/langchain/middleware/custom.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oss/langchain/middleware/custom.mdx b/src/oss/langchain/middleware/custom.mdx index d0672cec45..1399c1c51d 100644 --- a/src/oss/langchain/middleware/custom.mdx +++ b/src/oss/langchain/middleware/custom.mdx @@ -555,7 +555,7 @@ The following diagram illustrates the complete agent execution lifecycle with al
Middleware execution flow diagram -
Based on the LangChain agents factory implementation.
+
Based on the langchain/libs/langchain_v1/langchain/agents/factory.py.
## Agent jumps From b9ca8051bcff2cf5682313571d31e342f65d6548 Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 13:15:41 +0900 Subject: [PATCH 08/12] docs: add middleware execution flow diagram --- src/oss/langchain/middleware/custom.mdx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/oss/langchain/middleware/custom.mdx b/src/oss/langchain/middleware/custom.mdx index 1399c1c51d..10fe68a655 100644 --- a/src/oss/langchain/middleware/custom.mdx +++ b/src/oss/langchain/middleware/custom.mdx @@ -554,8 +554,13 @@ __Agent loop ends__ The following diagram illustrates the complete agent execution lifecycle with all middleware hook points:
- Middleware execution flow diagram -
Based on the langchain/libs/langchain_v1/langchain/agents/factory.py.
+ Middleware execution flow diagram showing agent lifecycle with before_agent, before_model, wrap_model_call, after_model, and after_agent hooks +
+ Based on the LangChain agents factory implementation. +
## Agent jumps From f42e4daee26737f4f9ac07b209c7adebea655e76 Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 13:16:16 +0900 Subject: [PATCH 09/12] docs: add middleware execution flow diagram --- src/oss/langchain/middleware/custom.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/oss/langchain/middleware/custom.mdx b/src/oss/langchain/middleware/custom.mdx index 10fe68a655..31a489a673 100644 --- a/src/oss/langchain/middleware/custom.mdx +++ b/src/oss/langchain/middleware/custom.mdx @@ -556,10 +556,10 @@ The following diagram illustrates the complete agent execution lifecycle with al
Middleware execution flow diagram showing agent lifecycle with before_agent, before_model, wrap_model_call, after_model, and after_agent hooks
- Based on the LangChain agents factory implementation. + Based on the langchain/libs/langchain_v1/langchain/agents/factory.py.
From aba6908ece0ac227c1d5c5c2b2c545c9077d89e7 Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 13:32:55 +0900 Subject: [PATCH 10/12] docs: add middleware execution flow diagram --- src/oss/langchain/middleware/custom.mdx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/oss/langchain/middleware/custom.mdx b/src/oss/langchain/middleware/custom.mdx index 31a489a673..727edccdb3 100644 --- a/src/oss/langchain/middleware/custom.mdx +++ b/src/oss/langchain/middleware/custom.mdx @@ -553,15 +553,11 @@ __Agent loop ends__ The following diagram illustrates the complete agent execution lifecycle with all middleware hook points: -
- Middleware execution flow diagram -
- Based on the langchain/libs/langchain_v1/langchain/agents/factory.py. -
-
+Middleware execution flow diagram + + ## Agent jumps From 21e480963026b12e8ac4f441956739a6758496e1 Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 13:33:07 +0900 Subject: [PATCH 11/12] docs: add middleware execution flow diagram --- src/oss/langchain/middleware/custom.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/oss/langchain/middleware/custom.mdx b/src/oss/langchain/middleware/custom.mdx index 727edccdb3..047738d242 100644 --- a/src/oss/langchain/middleware/custom.mdx +++ b/src/oss/langchain/middleware/custom.mdx @@ -558,7 +558,6 @@ The following diagram illustrates the complete agent execution lifecycle with al Based on the langchain/libs/langchain_v1/langchain/agents/factory.py. - ## Agent jumps To exit early from middleware, return a dictionary with `jump_to`: From c83eacc690a7c471e5647fd8342c2935dc7af925 Mon Sep 17 00:00:00 2001 From: Duhyeon Date: Wed, 19 Nov 2025 13:45:12 +0900 Subject: [PATCH 12/12] docs: add middleware execution flow diagram --- src/oss/langchain/middleware/custom.mdx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/oss/langchain/middleware/custom.mdx b/src/oss/langchain/middleware/custom.mdx index 047738d242..f014867c8b 100644 --- a/src/oss/langchain/middleware/custom.mdx +++ b/src/oss/langchain/middleware/custom.mdx @@ -553,10 +553,15 @@ __Agent loop ends__ The following diagram illustrates the complete agent execution lifecycle with all middleware hook points: -Middleware execution flow diagram - +Agent middleware execution flow diagram showing the lifecycle from START through before_agent, before_model, model execution, after_model, tools execution, and after_agent hooks with their invocation order and relationships + + +Diagram is based on the [langchain_v1/langchain/agents/factory.py](https://github.com/langchain-ai/langchain/blob/81c4f21b5297b31b2cd82ccefdd134aa0e59efa0/libs/langchain_v1/langchain/agents/factory.py). + ## Agent jumps