Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/oss/images/agent-middleware-execution-flow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/oss/langchain/middleware/custom.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,20 @@ __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:

<img
src="/oss/images/agent-middleware-execution-flow.svg"
alt="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"
className="rounded-lg block mx-auto"
/>

<Note>
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).
</Note>

## Agent jumps

To exit early from middleware, return a dictionary with `jump_to`:
Expand Down