feat(langchain): MiddlewareTransformer for agent streams#36898
Open
Nick Hollon (nick-hollon-lc) wants to merge 3 commits intonh/agent-streamerfrom
Open
feat(langchain): MiddlewareTransformer for agent streams#36898Nick Hollon (nick-hollon-lc) wants to merge 3 commits intonh/agent-streamerfrom
MiddlewareTransformer for agent streams#36898Nick Hollon (nick-hollon-lc) wants to merge 3 commits intonh/agent-streamerfrom
Conversation
Adds a native `MiddlewareTransformer` and typed `MiddlewareEvent`
dataclass, pre-registered on `AgentStreamer.builtin_factories` so
every `create_agent` run exposes `run.middleware` alongside
`run.tool_calls` without the caller opting in.
The transformer consumes the graph's existing `updates` stream mode,
filters by the `"{name}.{phase}"` node-naming convention
`create_agent` already uses, and re-emits typed events. Middleware
implementations do not need to change; the node-name convention is
the contract. `run.middleware` is an in-process-only projection.
Lives in langchain (not langgraph prebuilt) because middleware is a
langchain-specific concept — langgraph has no middleware primitive.
# Conflicts: # libs/langchain_v1/langchain/agents/__init__.py # libs/langchain_v1/langchain/agents/_streaming.py
# Conflicts: # libs/langchain_v1/langchain/agents/factory.py
494a472 to
03e2eb7
Compare
Collaborator
ccurme (ccurme)
left a comment
There was a problem hiding this comment.
Let's consider if we need this.
MiddlewareTransformer for agent streams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MiddlewareTransformer+ typedMiddlewareEventdataclass, pre-registered onAgentStreamer.builtin_factoriesso everycreate_agentrun exposesrun.middlewarewithout opting in.updatesstream mode and filters by the"{name}.{phase}"node-naming conventioncreate_agentalready uses (before_agent/before_model/after_model/after_agent).run.middlewareis an in-process-only projection; it's not routed anywhere outside the caller's process.ToolCallTransformerlives next toToolNodein langgraph prebuilt.Targeted at
nh/agent-streamer— builds on top ofAgentStreamer.