another v1 pass#830
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates LangChain v1 documentation to replace legacy API patterns with the new middleware-based approach. The changes modernize the documentation to reflect the v1 architectural changes while improving code examples and clarity.
Key changes:
- Replace Mermaid diagrams with static images for better performance and consistency
- Update agent configuration examples to use the new middleware decorators instead of legacy hooks
- Modernize structured output examples to use explicit strategy classes
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/oss/langchain/middleware.mdx | Replace Mermaid diagrams with static PNG images for core agent loop and middleware flow |
| src/oss/langchain/agents.mdx | Update agent examples to use v1 middleware decorators, add migration notes, and modernize API patterns |
| ``` | ||
|
|
||
| <Note> | ||
| Pre-bound models (models with `.bind_tools()` already called) are not supported when using structured output. If you need dynamic model selection with structured output, ensure the models passed to the middleware are not pre-bound. |
There was a problem hiding this comment.
This note mentions a limitation but doesn't explain why pre-bound models aren't supported or provide alternative approaches. Consider adding more context about the technical reason and suggest workarounds.
| Pre-bound models (models with `.bind_tools()` already called) are not supported when using structured output. If you need dynamic model selection with structured output, ensure the models passed to the middleware are not pre-bound. | |
| Pre-bound models (models with `.bind_tools()` already called) are not supported when using structured output. This is because structured output requires the agent to bind tools at runtime to ensure correct serialization and deserialization of tool calls. If a model is pre-bound, the agent cannot properly manage tool bindings, which may lead to errors or unexpected behavior. | |
| **Workaround:** If you need dynamic model selection with structured output, pass unbound models to the middleware and bind tools only after selecting the model. For example, select the model first, then call `.bind_tools()` (Python) or `.bindTools()` (TypeScript) with the appropriate tools before returning the model to the agent. |
|
|
||
| def trim_messages(state): | ||
| @before_model | ||
| def trim_messages(state: AgentState, runtime: Runtime) -> dict[str, Any] | None: |
There was a problem hiding this comment.
Missing import for Any type annotation. The function signature uses dict[str, Any] but Any is not imported from the typing module.
|
|
||
| def validate_response(state): | ||
| @after_model | ||
| def validate_response(state: AgentState, runtime: Runtime) -> dict[str, Any] | None: |
There was a problem hiding this comment.
The import for Any is present at line 834 but it's within the same code block. This creates a duplicate import since Any was already needed in the previous code example but wasn't imported there.
|
Preview ID generated: preview-srvali-1760128449-0d6326d |
No description provided.