docs: update middleware contribution examples - #4945
Draft
dajiaohuang wants to merge 2 commits into
Draft
Conversation
Collaborator
|
The issue is addressed by #4968 |
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.
Fixes #4943
Why
The backend contributor guide and English/Chinese site guides use middleware APIs that are absent from DeerFlow's locked LangChain version. The examples either fail to import
BaseMiddlewareor definetransform_state,on_start, andon_endmethods that the currentAgentMiddlewarelifecycle never calls.What changed
AgentMiddleware[AgentState]examples usingbefore_modelandafter_modelhooks.extensions.middlewaresimport-path registration, its zero-argument constructor requirement, shared lead/subagent placement, and trusted-code boundary.DeerFlowClient(middlewares=[...])andcreate_deerflow_agent(extra_middleware=[...]).Surface area
frontend/backend/applanggraph.json, or prompt changedocker/or sandboxed executionskills/backend/pyproject.tomlorfrontend/package.json(say what it buys us)Screenshots / Recording
N/A — no frontend UI behavior changed.
Bug fix verification
backend/tests/test_middleware_documentation.pymainand green on this branch? Yes. The five authoritative examples produced five failures onmain; all five pass after the documentation update.before_modelandafter_modeloverride the lockedAgentMiddlewarehooks.Validation
cd backend && uv sync --locked— completed with 248 packages resolved.cd backend && uv run --locked ruff check .— passed.cd backend && uv run --locked ruff format --check .— 1,159 files already formatted.cd backend && uv run --locked pytest tests/test_middleware_documentation.py tests/test_lead_agent_model_resolution.py -q— 49 passed.cd frontend && corepack pnpm@10.26.2 install --frozen-lockfile— completed without lockfile changes.cd frontend && corepack pnpm@10.26.2 format— passed.cd frontend && corepack pnpm@10.26.2 lint— passed.cd frontend && corepack pnpm@10.26.2 typecheck— passed.cd frontend && corepack pnpm@10.26.2 exec rstest run tests/unit/content/docs-links.test.ts— 1 passed.cd frontend && BETTER_AUTH_SECRET=local-dev-secret-for-build-validation-4943 corepack pnpm@10.26.2 build— production build passed; 101 static pages generated.AI assistance
Tool(s) used: Codex
How you used it: Codex reproduced the stale imports and hooks, cross-checked current middleware implementation and registration paths, drafted the synchronized documentation and regression test, and ran the validation commands listed above. Human line-by-line review is pending.