Skip to content

another v1 pass#830

Closed
Sydney Runkle (sydney-runkle) wants to merge 1 commit into
mainfrom
sr/valid-branch-name
Closed

another v1 pass#830
Sydney Runkle (sydney-runkle) wants to merge 1 commit into
mainfrom
sr/valid-branch-name

Conversation

@sydney-runkle

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings October 10, 2025 20:33
@github-actions github-actions Bot added langchain For docs changes to LangChain oss labels Oct 10, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI Oct 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.

def trim_messages(state):
@before_model
def trim_messages(state: AgentState, runtime: Runtime) -> dict[str, Any] | None:

Copilot AI Oct 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import for Any type annotation. The function signature uses dict[str, Any] but Any is not imported from the typing module.

Copilot uses AI. Check for mistakes.

def validate_response(state):
@after_model
def validate_response(state: AgentState, runtime: Runtime) -> dict[str, Any] | None:

Copilot AI Oct 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@github-actions

Copy link
Copy Markdown
Contributor

Preview ID generated: preview-srvali-1760128449-0d6326d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

langchain For docs changes to LangChain oss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants