langchain - ✅(Solved) Fix Allow to pass to .invoke method {messages: list[AnyMessage} [1 pull requests, 3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#35429Fetched 2026-04-08 00:26:13
View on GitHub
Comments
3
Participants
2
Timeline
10
Reactions
0
Timeline (top)
commented ×3labeled ×3cross-referenced ×2issue_type_added ×1

Currently we cannot pass list[AnyMessage] as input to invoke method if we create agent with high-level create_agent util.

create_agent sets _InputAgentState as input schema, and _InputAgentState has bad typing on list[AnyMessage | dict[...], so list from user code actually should accept both AnyMessage and dict . https://github.com/langchain-ai/langchain/blob/master/libs/langchain_v1/langchain/agents/middleware/types.py#L358-L361

Error Message

Error Message and Stack Trace (if applicable)

Root Cause

Currently we cannot pass list[AnyMessage] as input to invoke method if we create agent with high-level create_agent util.

create_agent sets _InputAgentState as input schema, and _InputAgentState has bad typing on list[AnyMessage | dict[...], so list from user code actually should accept both AnyMessage and dict . https://github.com/langchain-ai/langchain/blob/master/libs/langchain_v1/langchain/agents/middleware/types.py#L358-L361

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Other Dependencies

httpx: 0.28.1 jsonpatch: 1.33 langgraph: 1.0.9 openai: 1.109.1 opentelemetry-api: 1.39.1 opentelemetry-exporter-otlp-proto-http: 1.39.1 opentelemetry-sdk: 1.39.1 orjson: 3.11.7 packaging: 25.0 pydantic: 2.12.5 pytest: 8.4.1 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 tenacity: 9.1.2 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.12.0 zstandard: 0.25.0

PR fix notes

PR #35433: fix: Allow to pass to .invoke method {messages: list[AnyMessage}

Description (problem / solution / changelog)

Summary

  • Fixes typing for agent input state so create_agent(...).invoke(...) accepts MessagesState(messages=[HumanMessage(...)]).

Changes

  • Updated _InputAgentState.messages in langchain.agents.middleware.types to use list[AnyMessage], matching MessagesState.
  • Added a focused regression test at tests/unit_tests/agents/middleware_typing/test_input_state_typing.py.

Testing

  • uv run --group lint ruff check langchain/agents/middleware/types.py tests/unit_tests/agents/middleware_typing/test_input_state_typing.py
  • uv run --group typing mypy tests/unit_tests/agents/middleware_typing/test_input_state_typing.py
  • uv run --group test pytest tests/unit_tests/agents/middleware_typing/test_input_state_typing.py -q

Fixes https://github.com/langchain-ai/langchain/issues/35429

Changed files

  • libs/langchain_v1/langchain/agents/middleware/types.py (modified, +1/-1)
  • libs/langchain_v1/tests/unit_tests/agents/middleware_typing/test_input_state_typing.py (added, +35/-0)

Code Example

from langchain.agents import create_agent
from langgraph.graph.message import MessagesState

# Create full agent
agent = create_agent(model="openai:gpt-4o-mini", system_prompt="You are a personalized assistant. Just say hi.")

agent.invoke(MessagesState(messages=[HumanMessage(content="What's your name?")]))

---

Argument of type "MessagesState" cannot be assigned to parameter "input" of type "_InputAgentState | Command[Unknown] | None" in function "invoke"
  Type "MessagesState" is not assignable to type "_InputAgentState | Command[Unknown] | None"
    "messages" is an incompatible type
      "list[AnyMessage]" is not assignable to "list[AnyMessage | dict[str, Any]]"
    "MessagesState" is not assignable to "Command[Unknown]"
    "MessagesState" is not assignable to "None"basedpyrightreportArgumentType
Ctrl+click to open in new tab
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

from langchain.agents import create_agent
from langgraph.graph.message import MessagesState

# Create full agent
agent = create_agent(model="openai:gpt-4o-mini", system_prompt="You are a personalized assistant. Just say hi.")

agent.invoke(MessagesState(messages=[HumanMessage(content="What's your name?")]))

Error Message and Stack Trace (if applicable)

Argument of type "MessagesState" cannot be assigned to parameter "input" of type "_InputAgentState | Command[Unknown] | None" in function "invoke"
  Type "MessagesState" is not assignable to type "_InputAgentState | Command[Unknown] | None"
    "messages" is an incompatible type
      "list[AnyMessage]" is not assignable to "list[AnyMessage | dict[str, Any]]"
    "MessagesState" is not assignable to "Command[Unknown]"
    "MessagesState" is not assignable to "None"basedpyrightreportArgumentType
Ctrl+click to open in new tab

Description

Currently we cannot pass list[AnyMessage] as input to invoke method if we create agent with high-level create_agent util.

create_agent sets _InputAgentState as input schema, and _InputAgentState has bad typing on list[AnyMessage | dict[...], so list from user code actually should accept both AnyMessage and dict . https://github.com/langchain-ai/langchain/blob/master/libs/langchain_v1/langchain/agents/middleware/types.py#L358-L361

System Info

System Information

OS: Linux OS Version: #1 SMP PREEMPT_DYNAMIC Mon Nov 24 18:41:15 UTC 2025 Python Version: 3.12.12 (main, Oct 10 2025, 00:00:00) [GCC 15.2.1 20250924 (Red Hat 15.2.1-2)]

Package Information

langchain_core: 1.2.10 langchain: 1.2.10 langsmith: 0.4.53 langchain_openai: 1.1.8 langgraph_sdk: 0.3.8

Optional packages not installed

langserve

Other Dependencies

httpx: 0.28.1 jsonpatch: 1.33 langgraph: 1.0.9 openai: 1.109.1 opentelemetry-api: 1.39.1 opentelemetry-exporter-otlp-proto-http: 1.39.1 opentelemetry-sdk: 1.39.1 orjson: 3.11.7 packaging: 25.0 pydantic: 2.12.5 pytest: 8.4.1 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 tenacity: 9.1.2 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.12.0 zstandard: 0.25.0

extent analysis

Fix Plan

Update create_agent Util to Use Correct Input Schema

The issue arises from the incorrect input schema used by the create_agent util. To fix this, we need to update the util to use the correct schema.

Step-by-Step Solution

  1. Update create_agent Util:

    In langchain/agents/create_agent.py, update the create_agent function to use the correct input schema. Replace the line:

input_schema = _InputAgentState


   with:

   ```python
input_schema = Command[AnyMessage | dict[str, Any]]
  1. Update MessagesState Class:

    In langgraph/graph/message.py, update the MessagesState class to use the correct input schema. Replace the line:

messages: list[AnyMessage]


   with:

   ```python
messages: list[AnyMessage | dict[str, Any]]

Example Code

from langchain.agents import create_agent
from langgraph.graph.message import MessagesState

# Create full agent with correct input schema
agent = create_agent(model="openai:gpt-4o-mini", system_prompt="You are a personalized assistant. Just say hi.")

# Create MessagesState with correct input schema
messages_state = MessagesState(messages=[HumanMessage(content="What's your name?")])

agent.invoke(messages_state)

Verification

To verify that the fix worked, run the example code and ensure that the invoke method is called successfully without any errors.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - ✅(Solved) Fix Allow to pass to .invoke method {messages: list[AnyMessage} [1 pull requests, 3 comments, 2 participants]